
//---email check


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		  
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		  
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   
		    return false
		 }

 		 return true					
	}

function ValidateEmail(emailID){	
	if ((emailID.value==null)||(emailID.value=="")){
	
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true;
 }




//-- email check end

function pausecomp(millis) {
	date = new Date();
	var curDate = null;

	do { var curDate = new Date(); } 
		while(curDate-date < millis);
} 

//validates the form to see if all the required fields are completed
function validateForm(){


	if (document.enquiry.email.value.length == 0){
		alert("you must enter your email address");
	}else if( ValidateEmail(document.enquiry.email)==false){
		alert("you must enter a valid email address");
	} else {
		saveData()
		pausecomp(600)
		sendEnquiry()
	}
}


function saveData()
{
	document.enquiry.action = "processEnquiryForm.asp";
	document.enquiry.submit();
}

function sendEnquiry()
{
	document.enquiry.action = "http://secure4.spiderscope.com/vs/1688/scripts/sendmail_2005.asp";
	document.enquiry.submit();
}


function validateCode(){
	
	var code
	code = document.promo.code.value;

	if ((code==null)||(code=="")){
	
		alert("Please enter your promotional code.");
		return false;
	} else {
		document.promo.submit();
	}
	
 }


$(function() {
	// Use this example, or...
	$('a[rel*=lightbox1]').lightBox(); // Select all links that contains lightbox in the attribute rel
	$('a[rel*=lightbox2]').lightBox(); // Select all links that contains lightbox in the attribute rel
	// This, or...
	$('a.lightbox').lightBox({fixedNavigation:true}); // Select all links with lightbox class

	$('.moreDetails img').imghover();

	$('.category').hover(function(){
		$(this).addClass('hover');
	},function(){
		$(this).removeClass('hover');
	});
	$('.category').click(function(){
		var urlLink = $(this).find('a.link').attr('href');
		window.location = urlLink;
	});
});


String.prototype.RTrim = function() {return this.replace(/\s+$/, "");}
String.prototype.LTrim = function() {return this.replace(/^\s+/, "");}
String.prototype.Trim  = function() {return this.RTrim().LTrim();}

function Left (str, n) {
   return str.substring(0, n);
}

function Right (str, n) {
   len = str.length;
   return str.substring(len -n, len);
}


function ajaxGet(urlToGet) {
	//Gets a URL and returns the response
	var xmlhttp = GetXmlHttpObject();
	if (xmlhttp == null) {
		// Check if browser is compatable
		alert("Sorry, your browser does not support HTTP Request...");
		return;
	}

	xmlhttp.open("GET",urlToGet,false);
	xmlhttp.send(null);
	return xmlhttp.responseText;
}

function GetXmlHttpObject() {
	//Returns the XML HHTP object (browser dependant)
	var objXMLHttp=null;
	if (window.XMLHttpRequest) {
		//FF / Safari / Opera / Chrome Check
		objXMLHttp=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		//IE Check
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}


function returnSuccess(responseMessage,errorMessage) {
	//Checks for 'Success' at end of string and returns error message if not present
	responseMessage = responseMessage.Trim();
	if (Right(responseMessage,7) == "Success") {
		return true;
	} else {
		//changeValue("pageResponse", "innerHTML", responseMessage, "", "");
		alert(errorMessage);
		return false;
	}
}


