
//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;}
		//document.getElementById('numberofplayers1').style.display = 'block';
		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;
			}
	}

function arethesame(condition1,condition2){
	if (condition1 == condition2) {
			return true;
			} else {
			return false;
			}
}

function spiderform(formname,validateid,successid,indicatorid,ajaxpage) {
	//VALIDATE REQUIRED
	if(validateform(formname,'#f9f7cb','#f9f7cb')){	
	
		//EMAIL IS VALID?
		var email = document.getElementById("email").value;
		if(!validEmail(email)){
			document.getElementById("email").style.background = "white"; 
			document.getElementById(validateid).innerHTML = 'Invalid Email';
			if (document.getElementById(validateid).style.display == "none"){
					Effect.Appear(validateid,'blind');
					} else {
					Effect.Shake(validateid);
					}
			} else {
			document.getElementById(validateid).style.display = "none";
			document.getElementById(indicatorid).style.display = "block";
			//alert('got here')
			//AJAX POST
			new Ajax.Request(ajaxpage, {
			method: "post",
			parameters: Form.serialize(document.forms[formname]),
			onComplete: function(transport) {		
			document.getElementById(successid).innerHTML = transport.responseText;
			document.getElementById(indicatorid).style.display = "none";
				//alert(transport.responseText);			
				
				}//-onSuccess
			}//-request arguments
			);// new ajax request	
			
			//document.form.formname.submit();	
			}
	}
}





function logoff(){
		//AJAX POST
		new Ajax.Request('/ajax/logoff.asp', {
		method: "get",
		onSuccess: function(transport,formname) { 	
				document.location.href = '/';
			}
			//-onSuccess
			}//-request arguments
			);// new ajax request		
}

function forgotpassword(formname,validateid,color1,color2){
	if(validateform(formname,color1,color2)){		
		new Ajax.Request('/ajax/emailpassword.asp', {
		method: "post",
		parameters: Form.serialize(document.forms[formname]),
		onSuccess: function(transport,formname) { 	
			//LOG IN EXISTS?
			if (transport.responseText=='false'){	
					
					document.getElementById(validateid).innerHTML = 'Incorect Email Address';
					
				} else {
				
					document.getElementById(validateid).innerHTML = 'Your Password has been Emailed.  Thank you.';
				}
			}//-onSuccess
			}//-request arguments
			);// new ajax request		
	}
}

function ajaxlogin(formname,validateid,color1,color2) {
	//VALIDATE REQUIRED
	if(validateform(formname,color1,color2)){			
		//AJAX POST
		//alert ('got here')
		new Ajax.Request('/ajax/login.asp', {
		method: "post",
		parameters: Form.serialize(document.forms[formname]),
		onSuccess: function(transport,formname) { 	
			//LOG IN EXISTS?
			if (transport.responseText.indexOf('/')>-1 ){			
					document.getElementById(validateid).innerHTML = '';
					document.forms.login.submit();
					//document.location.href=transport.responseText
				} else {
					document.getElementById(validateid).innerHTML = 'Invalid Log In';
					document.getElementById('forgot').style.color = "#ff780b";
					document.getElementById('forgot').innerHTML = 'forgot password?'
					if (document.getElementById(validateid).style.display == "none"){
					Effect.Appear(validateid,'blind');
					} else {
					Effect.Shake(validateid);
					}
				}
			}//-onSuccess
			}//-request arguments
			);// new ajax request		
	
	}
	else{
		document.getElementById(validateid).innerHTML = 'Please fill out all the<br /> fields in <span style="color:orange">orange</span>';
		if (document.getElementById(validateid).style.display == "none"){
		Effect.Appear(validateid,'blind');
		} else {
		Effect.Shake(validateid);
		}
		}
		
}


function newaccount(formname,validateid,color1,color2){
	
	//VALIDATE REQUIRED
	if(validateform(formname,color1,color2)){				
	
		//EMAIL IS VALID?
		var email = document.getElementById("email").value;
		if(!validEmail(email)){
			document.getElementById("email").style.background = "yellow"; 
			document.getElementById(validateid).innerHTML = 'Invalid Email';
			if (document.getElementById(validateid).style.display == "none"){
					Effect.Appear(validateid,'blind');
					} else {
					Effect.Shake(validateid);
					}
			}
			
		//PASSWORDS	MATCH?
		var condition1 = document.getElementById("password1").value;
		var condition2 = document.getElementById("password2").value;
		if (!arethesame(condition1,condition2)){
			document.getElementById("password1").style.background = "yellow"; 
			document.getElementById("password2").style.background = "yellow"; 
			document.getElementById(validateid).innerHTML = 'Your Password Does Not Match';
		}
			
			else if ((validEmail(email) && arethesame(condition1,condition2))) {

			//AJAX POST
			new Ajax.Request('/ajax/newaccount.asp', {
			method: "post",
			parameters: Form.serialize(document.forms[formname]),
			onComplete: function(transport) { 
			
			//USER IS AVAILABLE?
			if (transport.responseText=='The Username you want to use is already being used.'){
				document.getElementById("validatemessage1").innerHTML = transport.responseText;	
			}else{
				document.getElementById("validatemessage2").innerHTML = transport.responseText;
				Effect.Appear(validateid,'blind');
				}
			}//-onComplete
			}//-request arguments
			);// new ajax request	
			}
	} 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 (document.images[i].getAttribute('name') == "rollover") {			
			setupRollover(document.images[i]);
		}
	}
}

//IMAGE ROLLOVER
//Last Update August 1, 2008
function setupRollover(thisImage) {
	thisImage.outImage = new Image();
	thisImage.outImage.src = thisImage.src;
	thisImage.onmouseout = rollOut;
	thisImage.overImage = new Image();
	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();
}
