/*
 * JS.MC_FUNCTIONLIB.JS
 *
 * +======================================================================================================+
 * | A .js (javascript/jscript) for the control of specific data. (Function)
 * | Data specific to client. (Skirmish)
 * |
 * +======================================================================================================+
 * | Requires JAVASCRIPT version 1+
 * +------------------------------------------------------------------------------------------------------+
 * | Usage:
 * | ------
 * | Javascript requiring both dynamic and non-dynamic remote file calls for operational purposes.  
 * | 
 * +------------------------------------------------------------------------------------------------------+
 * | License:
 * | --------
 * | The contents of this file are subject to  
 * | Copyright (C) 2009 MC Web Design. All Rights Reserved. 
 * | You may look at our source code, but please observe source code copyrights.
 * | View our copyright statement for more information at www.mcwebdesign.co.uk 
 * | 
 * +======================================================================================================+
 *
 * @author  S.J.C
 * @link    http://www.mcwebdesign.co.uk
 * @version 1.0
 */ 

// ====================================================================
// ====================================================================
// == [ COMMON AJAX FUNCTIONS FOR DYNAMIC AREAS - *_site.html, laser_games.html, paintball_games.html ] ==

// == FOLLOWING DECLAIRED ON EACH .html ==
//var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
//var loadedobjects=""
//var rootdomain="http://"+window.location.hostname
//var bustcacheparameter=""

function ajaxpage(url, containerid) {
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject) { // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function() {
loadpage(page_request, containerid)
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid) {
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++) {
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1) { //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1) { //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!="") {
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}

// == [ DD LISTS - *_site.html, laser_games.html, paintball_games.html ]
function ajaxcombo(selectobjID, loadarea) {
var selectobj=document.getElementById? document.getElementById(selectobjID) : ""
if (selectobj!="" && selectobj.options[selectobj.selectedIndex].value!="")
ajaxpage(selectobj.options[selectobj.selectedIndex].value, loadarea)
}
// ====================================================================
// ====================================================================
// == [] ==
function MM_swapImgRestore() { //v3.0 
var i,x,a=document.MM_sr; 
for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
x.src=x.oSrc; 
} 

function MM_preloadImages() { //v3.0 
var d=document; 
if(d.images){ 
if(!d.MM_p) d.MM_p=new Array(); 
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
for(i=0; i<a.length; i++) 
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new 
Image; d.MM_p[j++].src=a[i];}} } 

function MM_findObj(n, d) { //v3.0 
var p,i,x; 
if(!d) d=document; 
if((p=n.indexOf("?"))>0&&parent.frames.length) { 
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
} 
if(!(x=d[n])&&d.all) 
x=d.all[n]; 
for (i=0;!x&&i<d.forms.length;i++) 
x=d.forms[i][n]; 
for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
x=MM_findObj(n,d.layers[i].document); 
return x; 
} 

function MM_swapImage() { //v3.0 
var i,j=0,x,a=MM_swapImage.arguments; 
document.MM_sr=new Array; 
for(i=0;i<(a.length-2);i+=3) 
if ((x=MM_findObj(a[i]))!=null){
document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; 
x.src=a[i+2];} 
} 
// ====================================================================
// == [PAGE TOOLS] ==
function emailPage(subject, url) {
   parent.location.href="mailto:?subject="+subject+"&body=Hi, Please try this web page link : <"+url+">"+url+"</a>";
}
function sendMail(login, server){
   parent.location.href="mailto:"+login+"@"+server+"?subject=Enquiry from Skirmish Bristol (.co.uk)&body=";
}
// ====================================================================
// == [PAGE TOOLS] ==
function makeHome(url) {
 if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {    // == MSIE	
   document.body.style.behavior='url(#default#homepage)';
   document.body.setHomePage(url);
   //document.body.setHomePage(window.location.href);
} else if ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) <= '5')) {    // == FIREFOX AND SAFARI
   alert('For Firefox click on the Home button. For Safari click on Edit, Preferences, General, Set to current page.');
} else {
   alert('For Opera ');    // == OPERA OTHERS
 }
}
// ====================================================================
// == [PAGE TOOLS] ==
function favSite(url, title){
 if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
   window.external.AddFavorite(url,title);
 } else if ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) <= '5')) {
   alert('Bookmark our site CTRL-D');
} else {
   alert('Bookmark our site CTRL-T');
 }
}
// ====================================================================
// == [PAGE TOOLS] ==
function printPage(){ 
   print(document); 
}
// ====================================================================
// == [] ==
function getMap(site){
 test = document.mapForm.postcode.value; size = test.length
 test = test.toUpperCase(); //Change to uppercase
 while (test.slice(0,1) == " ") //Strip leading spaces
  {test = test.substr(1,size-1);size = test.length
  }
 while(test.slice(size-1,size)== " ") //Strip trailing spaces
  {test = test.substr(0,size-1);size = test.length
  }
 document.mapForm.postcode.value = test; //write back to form field
 if ((size < 6 || size > 8) && (size != 0)) { //Code length rule
  alert(test + " is not a valid postcode - wrong length.");
  document.mapForm.postcode.focus();
  return false;
  }
 if (size == 0){ //Code length rule
  alert("Please enter a postcode before submitting.");
  document.mapForm.postcode.focus();
  return false;
  }
 if (!(isNaN(test.charAt(0)))){ //leftmost character must be alpha character rule
   alert(test + " is not a valid postcode - cannot start with a number.");
   document.mapForm.postcode.focus();
   return false;
  }
 if (isNaN(test.charAt(size-3))){ //first character of inward code must be numeric rule
   alert(test + " is not a valid postcode - alpha character in wrong position.");
   document.mapForm.postcode.focus();
   return false;
  }
 if (!(isNaN(test.charAt(size-2)))){ //second character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position.");
   document.mapForm.postcode.focus();
   return false;
  }
 if (!(isNaN(test.charAt(size-1)))){ //third character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position.");
   document.mapForm.postcode.focus();
   return false;
  }
 if (!(test.charAt(size-4) == " ")){//space in position length-3 rule
   alert(test + " is not a valid postcode - no space or space in wrong position.");
   document.mapForm.postcode.focus();
   return false;
   }
 count1 = test.indexOf(" ");count2 = test.lastIndexOf(" ");
 if (count1 != count2){//only one space rule
   alert(test + " is not a valid postcode - only one space allowed.");
   document.mapForm.postcode.focus();
   return false;
  }
// == OPEN IN A POPUP WINDOW ==
window.open('http://maps.google.co.uk/maps?f=q&hl=en&q='+document.mapForm.postcode.value+'+to+'+site,'roaddir','');
// == OPEN IN EXISTING ==
//this.window.location = 'http://maps.google.co.uk/maps?f=q&hl=en&q='+document.mapForm.postcode.value+'+to+'+site;
//return true;
}
<!-- ### FORM BUTTONS REDIRECTION ### -->
<!-- USES:  -->
function getLink(reference){
	parent.location.href=reference;
}



