/* -------------------------------------------------------
   BWY NEW SOUTH WEST REGION
   includes/scripts/bwy_sw.js
   LyndworthDesign November 2010
------------------------------------------------------- */



/*** script to prevent framing of website ***/
if (parent.frames.length > 0) {
    parent.location.href = self.document.location;
}


function go2(f) { 
    window.location.hash=f; 
}

function formfocus() { 
    if(document.getElementById('nmbr')) { 
        document.getElementById('nmbr').focus(); 
    }
}




/*** anti-spam script ***/
var show, name, dom, m;
function ns(show, name, dom) { 
   m  =  "<a href=\"mailto:" +name+"@"+dom+"\" title=\"send mail to "+show+"\"  ";
   m += "onmouseover=\"window.status='Send mail to "+ show+"'; return true;\" ";
   m += "onmouseout=\"window.status=''; return true;\" ";
   m += "onfocusout=\"window.status='opening e-mail program'; return true;\">";
   m += show+"</a>";
   document.write(m);
}
var show, name, dom, m;
function ns2(show, name, dom) { 
   m = "<a class=\"link\" href=\"mailto:" +name+"@"+dom+"\" title=\"send mail to "+show+"\"  ";
   m += "onmouseover=\"window.status='Send mail to "+ show+"'; return true;\" ";
   m += "onmouseout=\"window.status=''; return true;\" ";
   m += "onfocusout=\"window.status='opening e-mail program'; return true;\">";
   m += show+"</a>";
   document.write(m);
}
var show, name, dom, m;
function ns3(show, name, dom) { 
   m = "<a class=\"email\" href=\"mailto:" +name+"@"+dom+"\" title=\"send mail to "+show+"\"  ";
   m += "onmouseover=\"window.status='Send mail to "+ show+"'; return true;\" ";
   m += "onmouseout=\"window.status=''; return true;\" ";
   m += "onfocusout=\"window.status='opening e-mail program'; return true;\">";
   m += show+"</a>";
   document.write(m);
}



/*** toggle div ***/

   function toggle(d)
   { 
      style = document.getElementById(d).style ; 
      if(style.display == "block") 
      { 
         style.display = "none"; 
      } else { 
         style.display = "block"; 
      } 
   } 

/*** toggle2 div ***/
function toggle2(shID) {
	if (document.getElementById(shID)) {
		if (document.getElementById(shID+'-show').style.display != 'none') {
			document.getElementById(shID+'-show').style.display = 'none';
			document.getElementById(shID).style.display = 'block';
		}
		else {
			document.getElementById(shID+'-show').style.display = 'inline';
			document.getElementById(shID).style.display = 'none';
		}
	}
}



/*** rewrite external links to open in new window ***/
   function externalLinks() 
   { 
      if (!document.getElementsByTagName) 
      {
         return; 
      }
      var anchors = document.getElementsByTagName("a"); 
      for (var i=0; i<anchors.length; i=i+1) 
      { 
         var anchor = anchors[i]; 
         if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") 
         { 
            anchor.target = "_blank"; 
         }
      } 

      var forms = document.getElementsByTagName("form"); 
      for(var i = 0; i < forms.length; i=i+1) 
      { 
         var form = forms[i]; 
         if(form.getAttribute("action").substring(0, 4) == "http") 
         {
            form.target = "_blank"; 
         } 
      } 
   } 

   function post() {
      if (document.getElementById) {
         var alltags = document.all? document.all : document.getElementsByTagName("*");
         for (i=0; i < alltags.length; i++) {
            if (alltags[i].className == "post") {
               var oldText = alltags[i].firstChild;
               var emailAddress = alltags[i].firstChild.nodeValue;
               var user = emailAddress.substring(0, emailAddress.indexOf("("));
               var website = emailAddress.substring(emailAddress.indexOf(")")+1, emailAddress.length);
               var newText = user+"@"+website;
               var a = document.createElement("a");
               a.href = "mailto:"+newText;
               var address = document.createTextNode(newText);
               a.appendChild(address);
               alltags[i].replaceChild(a,oldText);
            }
         }
      }
   }

/*** script to initiate javascripts  ***/
   function setup() 
   {
      externalLinks();
      post();
   }
   window.onload=setup;
/*** END: initiate javascripts  ***/


/*** scroll to top of page: Dave Lindquist
           http://www.octavioheredia.com/blog/archives/2005/10/javascript-back-to-top-links.php  ***/
    function top() {
        var x1 = x2 = x3 = 0;
        var y1 = y2 = y3 = 0;

        if (document.documentElement) {
            x1 = document.documentElement.scrollLeft || 0;
            y1 = document.documentElement.scrollTop || 0;
        }

        if (document.body) {
            x2 = document.body.scrollLeft || 0;
            y2 = document.body.scrollTop || 0;
        }

        x3 = window.scrollX || 0;
        y3 = window.scrollY || 0;

        var x = Math.max(x1, Math.max(x2, x3));
        var y = Math.max(y1, Math.max(y2, y3));

        window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

        if (x > 0 || y > 0) {
            window.setTimeout("top()", 36);
        }
    }


   function scrollUp(id) {
      box = "box_"+ id;
      document.getElementById(id).scrollIntoView(true); 
   }

/*
   visit = newurl + '/admin/_cmttee_contact.php';
   visit = newurl + '/admin/groupmail_cmttee.php';
*/


/*** MAIN SITE PAGES ***/
/* send email from our region page */
function cmttee_contact(data) {
   var newurl = "http://www.bwysouthwest.org.uk";
   visit = newurl + '/admin/cmttee_contact.php';
   theURL = visit + data;
   newwindow = window.open(theURL, 'contact', 'width=560,height=550,resizable=0,status=1,left=25, top=25, location=0,scrollbars=1'); 
   if( window.focus ) { newwindow.focus(); }
}

/* send data to booking form */

function bkform(data) {
   var newurl = "http://www.bwysouthwest.org.uk";
   visit = newurl + '/booking-info.htm';
   theURL = visit + data;
   newwindow = window.open(theURL, 'booking_form', 'width=560,height=600,resizable=0,status=0,left=40, top=30, menubar=0, toolbar=0, sName=_blank, location=0,scrollbars=1'); 
   if ( window.focus ) { newwindow.focus(); }
}





/*** BOOKINGS ADMIN ***/
/* send booking confirmation to applicant */
function confirm_booking(data) {
   var newurl = "http://www.bwysouthwest.org.uk";
   visit = newurl + '/admin/bookings_confirm.php';
   theURL = visit + data;
   newwindow = window.open(theURL, 'contact', 'width=560,height=560,resizable=0,status=1,left=30, top=30, location=0, directories=0, personalbar=0, scrollbars=1'); 
   if( window.focus ) { newwindow.focus(); }
}

/* send email to event applicant */
function contact(data) {
   var newurl = "http://www.bwysouthwest.org.uk";
   visit = newurl + '/admin/bookings_contact.php';
   theURL = visit + data;
   newwindow = window.open(theURL, 'contact', 'width=560,height=560,resizable=0,status=1,left=25, top=25, location=0,scrollbars=1'); 
   if( window.focus ) { newwindow.focus(); }
}
/* send group email to all applicants */
function contact_paid(data) {
   var newurl = "http://www.bwysouthwest.org.uk";
   visit = newurl + '/admin/bookings_contact_paid.php';
   theURL = visit + data;
   newwindow = window.open(theURL, 'contact', 'width=560,height=560,resizable=0,status=1,left=30, top=30, location=0, directories=0, personalbar=0, scrollbars=1'); 
   if ( window.focus ) 
   if( window.focus ) { newwindow.focus(); }
}

/* add notes to applicant booking */
function add_notes(data) {
   var newurl = "http://www.bwysouthwest.org.uk";
   visit = newurl + '/admin/bookings_add_notes.php';
   theURL = visit + data;
   newwindow = window.open(theURL, 'csv', 'width=560,height=380,resizable=0,status=1,left=30, top=30, location=0, directories=0, personalbar=0, scrollbars=1'); 
   if( window.focus ) { newwindow.focus(); }
}



/*** GENERAL BOOKINGS ADMIN FUNCTIONS ***/
function print_register(data) {
   var newurl = "http://www.bwysouthwest.org.uk";
   visit = newurl + '/admin/bookings_print_register.php';
   theURL = visit + data;
   newwindow = window.open(theURL, 'csv', 'width=880,height=600,resizable=1,status=1,left=30, top=30, location=0, directories=0, personalbar=0, menubar=1, scrollbars=1'); 
   if( window.focus ) { newwindow.focus(); }
}
function print_certificates(data) {
   var newurl = "http://www.bwysouthwest.org.uk";
   visit = newurl + '/admin/bookings_print_certificates.php';
   theURL = visit + data;
   newwindow = window.open(theURL, 'csv', 'width=880,height=600,resizable=1,status=1,left=30, top=30, location=0, directories=0, personalbar=0, menubar=1, scrollbars=1'); 
   if( window.focus ) { newwindow.focus(); }
}
function print_summary(data) {
   var newurl = "http://www.bwysouthwest.org.uk";
   visit = newurl + '/admin/bookings_print_summary.php';
   theURL = visit + data;
   newwindow = window.open(theURL, 'csv', 'width=880,height=600,resizable=1,status=1,left=30, top=30, location=0, directories=0, personalbar=0, menubar=1, scrollbars=1'); 
   if( window.focus ) { newwindow.focus(); }
}
function print_csv(data) {
   var newurl = "http://www.bwysouthwest.org.uk";
   visit = newurl + '/admin/bookings_print_csv.php';
   theURL = visit + data;
   newwindow = window.open(theURL, 'csv', 'width=700,height=700,resizable=1,status=1,left=30, top=30, location=0, directories=0, personalbar=0, scrollbars=1'); 
   if( window.focus ) { newwindow.focus(); }
}

/* *** booking_fncts *** */
function win_close() { 
   setTimeout('window.close()', 600); 
} 




/*** GROUP EMAIL FUNCTIONS ***/
function ro_mail() {
   var newurl = "http://www.bwysouthwest.org.uk";
   visit = newurl + '/admin/groupmail_ro.php';
   theURL = visit;
   newwindow = window.open(theURL, 'groupmail', 'width=560,height=600,resizable=0,status=1,left=30, top=30, location=0, directories=0, personalbar=0, scrollbars=1'); 
   if( window.focus ) { newwindow.focus(); }
}

function cmttee_mail() {
   var newurl = "http://www.bwysouthwest.org.uk";
   visit = newurl + '/admin/groupmail_cmttee.php';
   theURL = visit;
   newwindow = window.open(theURL, 'groupmail', 'width=560,height=600,resizable=0,status=1,left=30, top=30, location=0, directories=0, personalbar=0, scrollbars=1'); 
   if( window.focus ) { newwindow.focus(); }
}


function cmttee_recipients(data) {
   var newurl = "http://www.bwysouthwest.org.uk";
   visit = newurl + '/admin/groupmail_recipients.php';
   theURL = visit + data;
   newwindow = window.open(theURL, 'contact', 'width=560,height=550,resizable=0,status=1,left=25, top=25, location=0,scrollbars=1'); 
   if( window.focus ) { newwindow.focus(); }
}




/* *** MEMBERS FORUM *** */
function forum_upload() {
   var newurl = "http://www.bwysouthwest.org.uk";
   visit = newurl + '/admin/forum_upload.php';
   theURL = visit;
   newwindow = window.open(theURL, 'groupmail', 'width=560,height=600,resizable=0,status=1,left=30, top=30, location=0, directories=0, personalbar=0, scrollbars=1'); 
   if( window.focus ) { newwindow.focus(); }
}



/*** AJAX script to load new pages ***/
/*
var xmlhttp; 
if (window.XMLHttpRequest) {
  xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
*/

var xmlhttp; 
if (window.ActiveXObject) { 
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
} else { 
   xmlhttp = new XMLHttpRequest(); 
} 

function fetch(serverPage, objID) {
   var obj = document.getElementById(objID);
   xmlhttp.open("GET", serverPage);
   xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
         obj.innerHTML = xmlhttp.responseText;
      }
   }
xmlhttp.send(null);
}
/*** END: AJAX script ***/

