// JavaScript Document

// clear text box 
function clearText(thefield)	{
	if (thefield.defaultValue == thefield.value)
		thefield.value = "";
}

// slideshow image 
function iList () {
	this.name = '';
	this.img = new Array();
	this.url = new Array();
	this.zum = new Array();
	this.pause = new Array();
	this.last = null;
	this.current = null;
	this.defaultpause = 2000;
	this.buttons = false;
	this.stopped = false;
	this.loaded = false;
	this.startstop = false;
}
function iLoad (i) {
	if (i.loaded == true) { return; }
	i.loaded = true;
	iRotate(i);
}
function iLink (i) {
	if (!i.loaded) { return; }
	if (typeof(i.url[i.current]) != "undefined") { window.location.href = i.url[i.current]; }
	else if (typeof(i.zum[i.current]) != "undefined") { zoom(i.zum[i.current]); }
	else if (i.startstop) { iSwitch(i); }
}
function iSwitch (i) {
	if (!i.loaded) { return; }
	if (i.stopped) { i.stopped = false; iRotate(i); }
	else { i.stopped = true; }
}
function iRotate (i) {
	if (i.stopped) { return; }
	iNext(i);
	var pause = i.defaultpause;
	if (typeof(i.pause[i.current]) != "undefined") { pause = i.pause[i.current]; }
	setTimeout("iRotate("+i.name+")",pause);
}
function iNext (i) {
	if (!i.loaded||!document['image_'+i.name]) { return; }
	if (i.buttons) { document['form_'+i.name].nextButton.value = "Loading..."; }
	i.current++; if (i.current > i.last) { i.current = 0; }
	document['image_'+i.name].src = i.img[i.current].src;
	if (i.buttons) { document['form_'+i.name].nextButton.value = "Next Image"; }
}
function iPrev (i) {
	if (!i.loaded||!document['image_'+i.name]) { return; }
	if (i.buttons) { document['form_'+i.name].prevButton.value = "Loading..."; }
	i.current--; if (i.current < 0) { i.current = i.last; }
	document['image_'+i.name].src = i.img[i.current].src;
	if (i.buttons) { document['form_'+i.name].prevButton.value = "Previous Image"; }
}
function zoom (url) {
	z = window.open('','zoom_popUp','status=0,directories=0,toolbar=0,menubar=0,resizable=1,scrollbars=1,location=0');
	z.document.write("<html>\n<head>\n<title>Picture Zoom</title>\n</head>\n<body>\n<div align=\"center\">\n<img src=\"" + url + "\"><br>\n<form><input type=\"button\" value=\"Close Window\" onClick=\"self.close(true)\"></form>\n</div>\n</body>\n</html>\n");
	z.document.close();
	z.focus(true);
}

// contact form script
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					
	}

//allow only numbers in a form field, plus . ( ) -  
function checkForInt(evt) {
	evt = ( evt ) ? evt : window.event;
	var charCode = ( evt.which ) ? evt.which : evt.keyCode
	return (charCode == 45 || charCode == 46 || charCode == 40 || charCode == 41 || charCode <= 31 || (charCode >= 48 && charCode <= 57))
	}

function validate_form ( ){
	var emailID=document.contact_form.from;
    valid = true;
	var errors = "Some required information was left blank. Please provide the following:<ul>";
	if ((emailID.value==null)||(emailID.value=="")){
		errors += "<li>Enter Email address<\/li>" ;
		valid = false;
	}
	else if (echeck(emailID.value)==false){
		errors += "<li>Enter Valid email address<\/li>" ;
		valid = false;
	}
	errors += '</ul>';
	if(valid == false)	{
		document.getElementById('contact_errors').innerHTML = errors;
		}
    return valid;
}


