//VALIDATION
function validEmail(email) {
			var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
			return re.test(email); 
		}
		
//VALIDATION
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
		
//VALIDATION
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
		
//VALIDATION
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}
		
//VALIDATION
function isFilled(elm) {
	//alert(elm.type);
	//Last Updated by Sol - 6/14/07
	switch(elm.type){
	case "text":
		if (trim(elm.value) == "" || elm.value == null){
		return false;}
		else {return true;}
		break;
	case "password":
		if (trim(elm.value) == "" || elm.value == null){
		return false;}
		else {return true;}
		break;
	case "textarea":
		if (trim(elm.value) == "" || elm.value == null){
		return false;}
		else {return true;}
		break;
	case "select-one":
		var myindex=elm.selectedIndex;
		if (myindex==0){
		return false;}
		else {return true;}
		break;
	}
}

//VALIDATION
function validateform(formname,color1,color2){
	//last updated on 9/27/07
	//index of is mo betta
	var x = document.forms[formname];
	var allgood = true;
	for (var i=0;i<x.length;i++){
		if (x.elements[i].className.indexOf('required')>-1) {
		 	var thisformname = x.elements[i].name;
			var thisformid = x.elements[i].id;
			if (!isFilled(x.elements[i])) {
				document.getElementById(thisformid).style.background = color1;
				allgood = false;
				} else {
				  document.getElementById(thisformid).style.background = color2; 
				}
			}
		}
		if (allgood) {
			return true;
			} else {
			return false;
			}
	}

//CONTACT
function contactus(formname,validateid,color1,color2) {
	//VALIDATE REQUIRED
	if(validateform(formname,color1,color2)){	
	    var email = document.getElementById("email").value;
	    if(validEmail(email)){
	        new Ajax.Request('sc_contactus.aspx', {
		    method: "post",
		    parameters: Form.serialize(document.forms[formname]),
		    onComplete: function(transport) {
		            var r = transport.responseText; 
		             document.getElementById(validateid).innerHTML = 'Thank You';
		             document.getElementById('submitbutton').innerHTML = '';
			    }
		    }
		    );
	    } else {
	        document.getElementById(validateid).innerHTML = 'Invalid Email';
	        document.getElementById("email").style.background = color1;
	        if (document.getElementById(validateid).style.display == "none"){
			    Effect.Appear(validateid,'blind');
		    } else {
			    Effect.Shake(validateid);
		    }
	    } 
	} else {
	    document.getElementById(validateid).innerHTML = 'Please fill in Required Fields.';
	    if (document.getElementById(validateid).style.display == "none"){
			Effect.Appear(validateid,'blind');
		} else {
			Effect.Shake(validateid);
		}
	}
}

//IMAGE ROLLOVER
function rolloverInit(){
	for (var i=0; i<document.images.length; i++) {
	if (navigator.appName == "Netscape"){
		if (document.images[i].hasAttribute("name")){ 
				if (document.images[i].getAttribute('name').indexOf("rollover")>-1){			
					setupRollover(document.images[i]);
				}
		}
	} else
		if (document.images[i].getAttribute('name').indexOf("rollover")>-1){			
			setupRollover(document.images[i]);
		}
	}
}

//IMAGE ROLLOVER
//Last Update August 1, 2008
function setupRollover(thisImage) {
	thisImage.outImage = new Image();
	thisImage.outImage.src = thisImage.src;
	//alert(thisImage.id);
	thisImage.outImage.id = thisImage.id;
	thisImage.onmouseout = rollOut;
	thisImage.overImage = new Image();
	thisImage.overImage.id = thisImage.id
	thisImage.overImage.src = thisImage.src.replace('/off/','/on/')
	thisImage.onmouseover = rollOver;	
}

//IMAGE ROLLOVER
function rollOver() {
	this.src = this.overImage.src;
}

//IMAGE ROLLOVER
function rollOut() {
	this.src = this.outImage.src;
}

window.onload = masterloader;

function masterloader(){
	rolloverInit();
}