// Email Format 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 checkPCForm() {
var name = document.getElementById('pcname');
var email = document.getElementById('pcemail');	
var nameCheck = document.getElementById('nameCheck');
var emailCheck = document.getElementById('emailCheck');

// Check Name

if(!name.value) {
nameCheck.title = "Please enter your name.";
nameCheck.style.visibility = "visible";
nameCheck.src = "/images/validationerror.gif";
name.className = "formerror";
} else if(name.value.length < 3) {
name.className = "formerror";
nameCheck.src = "/images/validationerror.gif";
nameCheck.title = "Your name is too short.";
nameCheck.style.visibility = "visible";
} else {
name.className = "formgood";
nameCheck.src = "/images/validated.gif";
nameCheck.style.visibility = "visible";
var nameVal = true;
}

// Check Email Address
if(!email.value) {
email.className = "formerror";
emailCheck.src = "images/validationerror.gif";
emailCheck.title = "Please enter your email address.";
emailCheck.style.visibility = "visible";
} else if(email.value.length < 5) {
	email.className = "formerror";
	emailCheck.src = "images/validationerror.gif";
emailCheck.title = "Your email address is too short.";
emailCheck.style.visibility = "visible";	
} else if(echeck(email.value) == false) {
emailCheck.title = "Invalid email address.";
emailCheck.src = "images/validationerror.gif";
email.className = "formerror";
emailCheck.style.visibility = "visible";
} else {
email.className = "formgood";
emailCheck.src = "images/validated.gif";
emailCheck.style.visibility = "visible";
var emailVal = true;
emailCheck.title = "Validated Successfully.";
}

if(nameVal == true && emailVal == true) {
return true;
} else {
return false;	
}
}

function checkPCUnSubForm() {
var email = document.getElementById('pcemail');	
var emailCheck = document.getElementById('emailCheck');

// Check Email Address
if(!email.value) {
emailCheck.title = "Please enter your email address.";
emailCheck.style.visibility = "visible";
emailCheck.src = "images/validationerror.gif";
email.className = "formerror";
} else if(email.value.length < 5) {
emailCheck.title = "Your email address is too short.";
emailCheck.style.visibility = "visible";	
emailCheck.src = "images/validationerror.gif";
email.className = "formerror";
} else if(echeck(email.value) == false) {
emailCheck.title = "Invalid email address.";
emailCheck.style.visibility = "visible";
emailCheck.src = "images/validationerror.gif";
email.className = "formerror";
} else {
email.className = "formgood";
emailCheck.style.visibility = "visible";
emailCheck.src = "images/validated.gif";
emailCheck.title = "Validated Successfully.";
var emailVal = true;
}

if(emailVal == true) {
return true;
} else {
return false;	
}
}

function showformIndicator(elementid,error,msg) {
		el = document.getElementById(elementid);
		el2 = document.getElementById(elementid+"Error");
	if(error == true) {
		el.className = "formerror";
		el2.innerHTML = '<img src="images/validationerror.gif" alt="'+msg+'" title="'+msg+'" />';	
	} else {
		el2.innerHTML = '<img src="images/validated.gif" alt="'+msg+'" title="'+msg+'" />';	
		el.className = "formgood";
	}
}

function formCheck(type) {
	switch(type) {
		case(type='contact'):
		firstname = document.getElementById('FirstName');
		lastname = document.getElementById('LastName');
		email = document.getElementById('Email');
		comments = document.getElementById('Comments');
		
	
		if(!firstname.value) {
		showformIndicator('FirstName',true,'You did not enter a first name!');	
		firstnameerror = true;
		} else if(firstname.value.length > 50) {
		showformIndicator('FirstName',true,'Your first name is too long!');	
		firstnameerror = true;	
		} else {
		showformIndicator('FirstName',false,'Validated Successfully.');		
		firstnameerror = false;
		}
		
		if(lastname.value) {
		if(lastname.value.length > 50) {
		showformIndicator('LastName',true,'Your last name is too long!');	
		lastnameerror = true;
		} else {
		showformIndicator('LastName',false,'Validated Successfully.');		
		lastnameerror = false;
		}
		} else {
		lastnameerror = false;	
		}
		
		if(!email.value) {
		showformIndicator('Email',true,'You did not enter an email address!');	
		emailerror = true;
		} else if(echeck(email.value) == false) {
		showformIndicator('Email',true,'Your email address is not invalid!');	
		emailerror = true;
		} else if(email.value.length > 50) {
		showformIndicator('Email',true,'Your email address is too long!');	
		emailerror = true;	
		} else {
		showformIndicator('Email',false,'Validated Successfully.');		
		emailerror = false;	
		}
		
		if(!comments.value) {
		showformIndicator('Comments',true,'You did not enter any comments!');	
		commentserror = true;
		} else {
		showformIndicator('Comments',false,'Validated Successfully.');		
		commentserror = false;	
		}
		
		if(lastname.value) {		
		if(firstname.value == lastname.value) {
		showformIndicator('FirstName',true,'First Name cannot be the same as Last Name');	
		showformIndicator('LastName',true,'Last Name cannot be the same as First Name');	
		fnlnerror = true;
		} else {
		fnlnerror = false;
		}
		}
		
		if(firstnameerror == true || lastnameerror == true || emailerror == true || commentserror == true || fnlnerror == true) {
			return false;	
		} else {
			return true;	
		}

		break;
		
		case(type='tellafriend'):
		yourname = document.getElementById('YourName');
		theirname = document.getElementById('TheirName');
		youremail = document.getElementById('YourEmail');
		theiremail = document.getElementById('TheirEmail');
	
		if(!yourname.value) {
		showformIndicator('YourName',true,'You did not enter your name!');	
		yournameerror = true;
		} else if(yourname.value.length > 50) {
		showformIndicator('YourName',true,'Your name is too long!');	
		yournameerror = true;	
		} else {
		showformIndicator('YourName',false,'Validated Successfully.');		
		yournameerror = false;
		}
		
		if(!theirname.value) {
		showformIndicator('TheirName',true,'You did not enter Their Name!');	
		theirnameerror = true;
		} else if(theirname.value.length > 50) {
		showformIndicator('TheirName',true,'Their Name is too long!');	
		theirnameerror = true;	
		} else {
		showformIndicator('TheirName',false,'Validated Successfully.');		
		theirnameerror = false;
		}


		
		if(!youremail.value) {
		showformIndicator('YourEmail',true,'You did not enter an Your Email address!');	
		youremailerror = true;
		} else if(echeck(youremail.value) == false) {
		showformIndicator('YourEmail',true,'Your Email address is not invalid!');	
		youremailerror = true;
		} else if(youremail.value.length > 50) {
		showformIndicator('YourEmail',true,'Your Email address is too long!');	
		youremailerror = true;	
		} else {
		showformIndicator('YourEmail',false,'Validated Successfully.');		
		youremailerror = false;	
		}
		
		if(!theiremail.value) {
		showformIndicator('TheirEmail',true,'You did not enter an Their Email address!');	
		theiremailerror = true;
		} else if(echeck(theiremail.value) == false) {
		showformIndicator('TheirEmail',true,'Their Email address is not invalid!');	
		theiremailerror = true;
		} else if(theiremail.value.length > 50) {
		showformIndicator('TheirEmail',true,'Their Email address is too long!');	
		theiremailerror = true;	
		} else {
		showformIndicator('TheirEmail',false,'Validated Successfully.');		
		theiremailerror = false;	
		}
		
		if(yournameerror == true || theirnameerror == true || youremailerror == true || theiremailerror == true) {
			return false;	
		} else {
			return true;	
		}

		break;
	}
}