function displayDiv(which) {
	 temp = document.getElementById(which);
	 
	 if (temp.style.display == "none"){
	 	display = "block";
	 }
	 else {
	 	display = "none";
	}

	 temp.style.display = display ;
	 }

function RemoveBad() { 
	strTemp = event.srcElement.value;
	strTemp = strTemp.replace(/\<|\>|\"|\'|\%|\;|\*|\(|\)|\&|\+/g,""); 
	event.srcElement.value = strTemp;
} 



function targetError(iItem, iColor){
	doc = document.all;
	doc[iItem].style.color = iColor
	doc[iItem].focus();
	}

function checkEmail(itemName, errName) {
	doc = document.all;
	elVal = doc[itemName].value;
	if (/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,7}|[0-9]{1,3})(\]?)$/.test(elVal))
		return (true);
	else {
		alert("You have entered an invalid email for '" + errName + "', please re-enter.\nCorrect formats: [support@jmphotography.com][info@jmphotography.org.uk]");
		targetError(itemName,"red");
		return (false);
		}
	}
	
	
function isTelephone(itemName, errName){
	doc = document.all;
	elVal = doc[itemName].value;
	elVal = elVal.replace(/\s/g, "");	
	for(var i=0;i<elVal.length;i++){
		if(!isDigit(elVal.charAt(i))){
			alert("You must input a valid Telephone Number for '" + errName + "'.");
			targetError(itemName,"red");
			return false;
			}
		}
	doc[itemName].value = TrimAll(doc[itemName].value);		
	return true;
	}
	
function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
	}
	
function isBlank(val){
	///if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
	}
	
function LTrimAll(str) {
	if (str==null){return str;}
	for (var i=0; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i++);
	return str.substring(i,str.length);
	}
	
function RTrimAll(str) {
	if (str==null){return str;}
	for (var i=str.length-1; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i--);
	return str.substring(0,i+1);
	}
	
function TrimAll(str) {
	return LTrimAll(RTrimAll(str));
	}
	
	
	function ChkForm(){
	
		if (isBlank(TrimAll(thisForm.YourName.value)) == true){
			alert("You must enter a value before continuing...");
			targetError('YourName',"red")
			return false;
			}
		if (isBlank(TrimAll(thisForm.YourTel.value)) == true){
			alert("You must enter a value before continuing...");
			targetError('YourTel',"red")
			return false;
			}
		if (!isTelephone('YourTel','Your Telephone')){
			targetError("YourTel","red");
			return false;
			}
		if (isBlank(TrimAll(thisForm.YourEmailAddress.value)) == true){
			alert("You must enter a value before continuing...");
			targetError('YourEmailAddress',"red")
			return false;
			}
		if (!checkEmail('YourEmailAddress','Your Email Address')){
			targetError("YourEmailAddress","red");
			return false;
			}
		if (isBlank(TrimAll(thisForm.YourMsg.value)) == true){
			alert("You must enter a value before continuing...");
			targetError('YourMsg',"red")
			return false;
			}
			
		SendEmail('thisForm')
		}
		
		
function buildQueryString(theFormName) {
  theForm = document.forms[theFormName];
  var qs = ''
  for (e=0;e<theForm.elements.length;e++) {
    if (theForm.elements[e].name!='') {
      qs+=(qs=='')?'?':'&'
      qs+=theForm.elements[e].name+'='+escape(theForm.elements[e].value)
      }
    }
  return qs
}		
	
	
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}	
		
function SendEmail(theFormName){

var strPage = "ServEmail.asp"
var strURL = 'ServerSide/'+ strPage + buildQueryString(theFormName);

	xmlhttp.open("GET",strURL,true);
 	xmlhttp.onreadystatechange=function() {
	
	
		if (xmlhttp.readyState == 4) {
			   strResponse = xmlhttp.responseText;
			   switch (xmlhttp.status) {
					   // Page-not-found error
					   case 404:
							   alert("Error: Not Found. The requested URL '"  + 
									   strPage + "' could not be found.");
							   break;
					   // Display results in a full window for server-side errors
					   case 500:
							   handleErr(strResponse);
							   break;
					   default:
							   // Call JS alert for custom error or debug messages
							   if (strResponse.indexOf('Error:') > -1 || 
									   strResponse.indexOf('Debug:') > -1) {
									   alert(strResponse);
							   }
							   // Call the desired result function
							   else {
									   //eval(strResultFunc + '(strResponse);');
									   alert(strResponse);
									   document.thisForm.reset();
							   }

							   break;
			   }
	   }
	  
 	}
 xmlhttp.send(null) 
  
}

function getIMG(str_dir, str_url){

STARTLOADER('WEDDING_IMG')

var strPage = str_url
var strURL = ''+str_dir+'/'+str_url+''

	xmlhttp.open("GET",strURL,true);
 	xmlhttp.onreadystatechange=function() {
	
	
		if (xmlhttp.readyState == 4) {
			   strResponse = xmlhttp.responseText;
			   switch (xmlhttp.status) {
					   // Page-not-found error
					   case 404:
							   alert("Error: Not Found. The requested URL '"  + 
									   strPage + "' could not be found.");
							   break;
					   // Display results in a full window for server-side errors
					   case 500:
							   handleErr(strResponse);
							   break;
					   default:
							   // Call JS alert for custom error or debug messages
							   if (strResponse.indexOf('Error:') > -1 || 
									   strResponse.indexOf('Debug:') > -1) {
									   alert(strResponse);
							   }
							   // Call the desired result function
							   else {
							   			STOPLOADER('WEDDING_IMG');
									   //eval(strResultFunc + '(strResponse);');
									   document.getElementById("WEDDING_IMG").innerHTML = strResponse
							   }
							   break;
			   }
	   }
	  
 	}
 xmlhttp.send(null) 
  
}

var TOPLOADER;
var LoaderStatus_Top = "";
var LOADINGSIZE_TOP = 0
var LOADING_TEXT_DOTS = new Array(".", "..", "...", "....", ".....")

function STOPLOADER(which){
	try {
		clearTimeout(TOPLOADER);
		LoaderStatus_Top = "";
		document.getElementById(which).innerHTML = "<font color='#000000'>Loaded</font>";
		}
	catch (e) {
		temp = 1
		}
	}

function STARTLOADER(which) {
	clearTimeout(TOPLOADER);
	LoaderStatus_Top = "working"
	CALLLOADER(which)
	}

function CALLLOADER(which) {
	if (LoaderStatus_Top == "working"){
		LOADINGSIZE_TOP++;
		if (LOADINGSIZE_TOP == 5) LOADINGSIZE_TOP = 0;
		document.getElementById(which).innerHTML = "<font color='#000000'>Loading" + LOADING_TEXT_DOTS[LOADINGSIZE_TOP] + "</font>";
		TOPLOADER = setTimeout("CALLLOADER('"+which+"')",300);
		}
	else 
		document.getElementById(which).innerHTML = "";
	}
