
// SCRIPT REQUIRED BY SIDE DROP MENUS //

function ViewCrossReference (selSelectObject)
{
   if (selSelectObject.options[selSelectObject.selectedIndex].value != "")
   {
     location.href=selSelectObject.options[selSelectObject.selectedIndex].value
   }
}


// SCRIPT REQUIRED BY POPUP LAYERS //

function getObj(elementID){

		return document.getElementById(elementID);
	 }

		 

function show(element){
     
		 getObj(element).style.visibility= "visible";  
		 getObj(element).style.display= "block";  
	 }



function hide(element){

     		getObj(element).style.visibility= "hidden";    
			getObj(element).style.display= "none";  
     	}






// ========================= Webmonkey Preload Images ========================================== //

function WM_preloadImages() {

/*
WM_preloadImages()
Loads images into the browser's cache for later use.

Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)

Author: Nadav Savio
Author Email: nadav@wired.com

Usage: WM_preloadImages('image 1 URL', 'image 2 URL', 'image 3 URL', ...);
*/

  // Don't bother if there's no document.images
  if (document.images) {
    if (typeof(document.WM) == 'undefined'){
      document.WM = new Object();
    }
    document.WM.loadedImages = new Array();
    // Loop through all the arguments.
    var argLength = WM_preloadImages.arguments.length;
    for(arg=0;arg<argLength;arg++) {
      // For each arg, create a new image.
      document.WM.loadedImages[arg] = new Image();
      // Then set the source of that image to the current argument.
      document.WM.loadedImages[arg].src = WM_preloadImages.arguments[arg];
    }
  }
}


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) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); 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];}
}


// ========================= RANDOM IMAGES SELECTION FROM RANDOMPHOTO.PHP ========================================== //

function RANDOM_MAINPAGEPHOTOselect(numberofpics,directory,picid){

  var objStr,obj;
  var daImage= picid;
  var choice= Math.random();
  var thechoice= (choice * (numberofpics-1));
  var randomrounded= Math.round(thechoice); 
 
if(randomrounded == 0){randomrounded = 1};

 daSrc= 'quote' + randomrounded + '.jpg';

 daSrc = directory + daSrc;



if(document.images){
    // Check to see whether you are using a name, number, or object

    if (typeof(daImage) == 'string') {
      // This whole objStr nonesense is here solely to gain compatability
      // with ie3 for the mac.
      objStr = 'document.' + daImage;
      obj = eval(objStr);
      obj.src = daSrc;
    } else if ((typeof(daImage) == 'object') && daImage && daImage.src) {
      daImage.src = daSrc;
    }
  }
}



/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

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
}
}
}

// SCRIPT REQUIRED HOME PAGE AJAX AND VALIDATION //

	// check fields are correct and provide feedback then send form via AJAX
	function emailvalidatecheck()
		{
			var emailsubscribe=document.lastdropform.email.value;
			var name=document.lastdropform.name.value;
			
			// variable used to only provide one error message for email
			var emailATtest1="PASS";
			var anytest="PASS";
			
			if (emailsubscribe=="")
			{
			   	// Trap error and provide feedback
				
					 document.lastdropform.email.style.backgroundColor="red";
					  document.lastdropform.email.value="Please provide an email";
					  
					  var emailATtest1="FAIL";
					  var anytest="FAIL";
			}
			
			if (name=="")
			{
			   	// Trap error and provide feedback
				
					 document.lastdropform.name.style.backgroundColor="red";
					  document.lastdropform.name.value="Please provide your name";
					  
					  
					  var anytest="FAIL";
			}
			
			
			if ((emailsubscribe.indexOf("@")==-1) && (emailATtest1=="PASS"))
			{
			   	// Trap error and provide feedback
				//alert("Please input a valid email address, like john@bigpond.com")
					 document.lastdropform.email.style.backgroundColor="red";
					 document.lastdropform.email.value="NOT a valid email";
					  
					   var anytest="FAIL";
					
			}
			
				
			
			// SUBMIT FORM VIA AJAX ONLY IF ALL TEST PASS - display connecting message
			
			if (anytest=="PASS")
			
					 {
					document.getElementById('lastdropsubmitbutton').style.visibility= "hidden";     
					document.getElementById('lastdropsubmitbutton').style.width= "0px"; 
					document.getElementById('lastdropsubmitbutton').style.height= "0px"; 
					
					document.getElementById('lastdropsubmitting').style.visibility= "visible";     
					document.getElementById('lastdropsubmitting').style.height= "20px"; 
					
					
					document.lastdropform.ajform_submit();
					
					}

		}


  function getReturnData( data , statusCode , statusMessage) {
	 	//AJFORM failed. Submit form normally. display submitted message even if it fails
		
	 	if( statusCode != AJForm.STATUS['SUCCESS'] ) {
	 	 //alert( statusMessage );
		
				document.getElementById('lastdropsubmitting').style.visibility= "hidden";     
				document.getElementById('lastdropsubmitting').style.height= "0px"; 
		
				document.getElementById('lastdropsubmitted').style.visibility= "visible";     
				document.getElementById('lastdropsubmitted').style.height= "20px"; 
		
			 
		 return true;
	 	}
	 	//AJFORM succeeded. - display submitted message
	 	else {
		
				
				document.getElementById('lastdropsubmitting').style.visibility= "hidden";     
				document.getElementById('lastdropsubmitting').style.height= "0px"; 
		
				document.getElementById('lastdropsubmitted').style.visibility= "visible";     
				document.getElementById('lastdropsubmitted').style.height= "20px"; 
				
		
		 // Can be used to display the echo from the php scripting sendind data to	
		 //alert( "Data:\n" + data);
	 	}
	}

 
