// JavaScript Document
function isEmail(s)
{
	var i = 1,Length = s.length,result;
	
	if(s==""){
		
		alert("Email Address should not be Empty");
		return false;
	}
	
	while((i<Length) && (s.charAt(i) != '@')) i++;
	
	if ((i == Length) || (s.charAt(i) != '@'))
	{
		alert("Email Address don\'t have the character @ after the login name");
		return false;
	}
	
	i+=2;
	
	while((i<Length) && (s.charAt(i) != '.')) i++;

	if ((i == Length) || (s.charAt(i) != '.'))
	{
		alert("Email Address don\'t have the character after the domain name ");
		return false;
	}

	if (i+1 >= Length)
	{
		alert("Email Address should have atleast one character after.");
		return false;
	}
	
	return true;
}

function checkloginvalidation(){
	if (trim(document.login.emailaddress.value) == "")
	{
		alert("Enter the email address");
		document.login.emailaddress.focus();
		return false;
	}
	if(!isEmailAddr(document.login.emailaddress.value))
	{
		alert("Invalid Email Address");
		document.login.emailaddress.focus();
		return false;
	}
	
	if (trim(document.login.password.value) == "")
	{
		alert("Enter the password");
		document.login.password.focus();
		return false;
	}
	document.login.hdaction.value='login';
	return true;
}
function checkcontactusvalidation() {
	if (trim(document.contact.name.value) == "")
	{
		alert("Name sholud not be empty.");
		document.contact.name.focus();
		return false;
	}
	if (trim(document.contact.email.value) == "")
	{
		alert("Email Address sholud not be empty.");
		document.contact.email.focus();
		return false;
	}
	if(!isEmailAddr(document.contact.email.value))
	{
		alert("Invalid Email Address");
		document.contact.email.focus();
		return false;
	}	
	if (trim(document.contact.message.value) == "")
	{
		alert("Message sholud not be empty.");
		document.contact.message.focus();
		return false;
	}
	if (trim(document.contact.RVerification.value) == "")
	{
		alert("Verification Code sholud not be empty.");
		document.contact.RVerification.focus();
		return false;
	}
	document.contact.submit();
}
function checkupdateprofilevalidation(){
	if (trim(document.register.membername.value) == "")
	{
		alert("Enter the member name");
		document.register.membername.focus();
		return false;
	}
	if (trim(document.register.fname.value) == "")
	{
		alert("Enter the first name");
		document.register.fname.focus();
		return false;
	}
	if (trim(document.register.lname.value) == "")
	{
		alert("Enter the last name");
		document.register.lname.focus();
		return false;
	}
	if (trim(document.register.email.value) == "")
	{
		alert("Enter the email address");
		document.register.email.focus();
		return false;
	}
	if(!isEmailAddr(document.register.email.value))
	{
		alert("Invalid Email Address");
		document.register.email.focus();
		return false;
	}
	if (trim(document.register.zipcode.value) == "")
	{
		alert("Enter the zipcode");
		document.register.zipcode.focus();
		return false;
	}
	document.register.hdAction.value='updateprofile';
	return true;
}

function checkeditpublicprofilevalidation() {
	if(document.publicprofile.website.value != 'http://' && document.publicprofile.website.value != '') {
		if(!IsValidURL(document.publicprofile.website.value,"Website")) {
			alert("Enter valid website address");
			document.publicprofile.website.focus();			
			return false;
		}	
	}
}

function checkeditprofilevalidation() {
	if (trim(document.register.membername.value) == "") {
		alert("Enter the member name");
		document.register.membername.focus();
		return false;
	}
	if (trim(document.register.fname.value) == ""){
		alert("Enter the first name");
		document.register.fname.focus();
		return false;
	}
	if (trim(document.register.lname.value) == ""){
		alert("Enter the last name");
		document.register.lname.focus();
		return false;
	}
	if (trim(document.register.email.value) == ""){
		alert("Enter the email address");
		document.register.email.focus();
		return false;
	}
	if(!isEmailAddr(document.register.email.value)){
		alert("Invalid Email Address");
		document.register.email.focus();
		return false;
	}
	document.register.hdAction.value='editaccount';
	return true;
}

function checkregistervalidation(){
	if (trim(document.register.membername.value)== ""){			
		alert("Enter the member name");
		document.register.membername.focus();
		return false;
	}
	if (document.register.email.value== "") {
		alert("Enter the email address");
		document.register.email.focus();
		return false;
	}
	if(!isEmailAddr(document.register.email.value))	{
		alert("Invalid Email Address");
		document.register.email.focus();
		return false;
	}
	if (trim(document.register.password.value)== "") {
		alert("Enter the password");
		document.register.password.focus();
		return false;
	}
	if (trim(document.register.retypepassword.value) == "") {
		alert("Enter the retype password");
		document.register.retypepassword.focus();
		return false;
	}
	if (document.register.password.value!=document.register.retypepassword.value) {
		alert("Enter the retype password correctly");
		document.register.retypepassword.focus();
		return false;
	}
	if (trim(document.register.RVerification.value) == "") {
		alert("Enter the Verfication code");
		document.register.RVerification.focus();
		return false;
	}
	if (!(document.register.acceptterm.checked)) {
		alert("Accept and agree to the terms of use and privacy policy.");
		document.register.acceptterm.focus();
		return false;
	}	

	if (!(document.register.yearsold.checked)) {
		alert("Members should be atleast 18 years old.");
		document.register.yearsold.focus();
		return false;
	}	
	document.register.hdAction.value='register';
	return true;
}

function checkforgotpassvalidation() {
	if (document.forgotpass.emailaddress.value== "") {
		alert("Enter the email address");
		document.forgotpass.emailaddress.focus();
		return false;
	}
	if(!isEmailAddr(document.forgotpass.emailaddress.value)) {
		alert("Invalid Email Address");
		document.forgotpass.emailaddress.focus();
		return false;
	}
	document.forgotpass.op.value='forgotpass';
	document.forgotpass.hdaction.value='forgotpass';
	return true;
}

function checkforgotpassreturnlogin(){ 
	document.forgotpass.op.value='login';
	document.forgotpass.hdaction.value='login';
	return true;
}

function returntomyaccount(){
	document.changepass.op.value='myaccount';
	return true;
}
function profileinforeturntomyaccount(){
	document.profileinfo.op.value='myaccount';
	return true;
}
function checkprofileinfovalidation(){
	if (trim(document.profileinfo.fname.value)== "") {
		alert("Enter the first name");
		document.profileinfo.fname.focus();
		return false;
	}
	if (trim(document.profileinfo.lname.value)== "") {
		alert("Enter the last name");
		document.profileinfo.lname.focus();
		return false;
	}
	document.profileinfo.op.value='profileinfo';
	document.profileinfo.hdaction.value='profileinfo';
	return true;	
}
function checkpasswordvalidation() {
	if (trim(document.changepass.password.value)== "") {
		alert("Enter the password");
		document.changepass.password.focus();
		return false;
	}
	if (trim(document.changepass.retypepassword.value)== "") {
		alert("Enter the retype password");
		document.changepass.retypepassword.focus();
		return false;
	}
	if (document.changepass.password.value!=document.changepass.retypepassword.value) {
		alert("Enter the retype password correctly");
		document.changepass.retypepassword.focus();
		return false;
	}
	document.changepass.op.value='changepass';
	document.changepass.hdaction.value='changepass';
	return true;
}
function checkUploadphotovalidation() {
	if (trim(document.uploadphoto.uploadphotoid.value) == "") {
		alert("Select an image to upload");
		document.uploadphoto.uploadphotoid.focus();
		return false;
	}
	document.uploadphoto.op.value='uploadphoto';
	document.uploadphoto.hdaction.value='uploadphoto';
	return true;
}

function checkwritereviewvalidation(){	
	if (trim(document.writereview.businessname.value)== "") {
		alert("Enter the business name");
		document.writereview.businessname.focus();
		return false;
	}
	if (trim(document.writereview.morateval.value) == "") {
		alert("Select the rating");
		return false;
	}
	if (trim(document.writereview.category.value) == "") {
		alert("Select the Category");
		document.writereview.category.focus();
		return false;
	}
	
	if (trim(document.writereview.city.value) == "") {
		alert("Enter the city");
		document.writereview.city.focus();
		return false;
	}
	
	if(trim(document.writereview.zipcode.value) != '') {
		if (!IsNumber(document.writereview.zipcode.value,"Zip Code"))
		{
			document.writereview.zipcode.focus();
			return false;
		}
	}
	var browser=navigator.userAgent.toLowerCase();
	var is_ie7    = (browser.indexOf("msie 7.")!=-1);	
	
	
	if(is_ie7) {
	
		document.getElementById('yourreview').value = tinyMCE.getContent('yourreview');
			if(trim(document.getElementById('yourreview').value) == '')
			{
				alert("Enter your review");
				//document.writereview.yourreview.focus();
				return false;
			}
	} else {
		document.getElementById('yourreview').innerHTML = tinyMCE.getContent('yourreview');
			if(trim(document.getElementById('yourreview').innerHTML) == '')
			{
				alert("Enter your review");
				//document.writereview.yourreview.focus();
				return false;
			}
	}

	if (trim(document.writereview.RVerification.value) == "")
	{
		alert("Enter the Verification Code");
		document.writereview.RVerification.focus();
		return false;
	}
	document.writereview.hdAction.value='writereview';
	document.writereview.submit();	

	//return true;
}


function checkbusinessvalidation(){

	
	if (trim(document.writereview.businessname.value)== "") {
		alert("Enter the business name");
		document.writereview.businessname.focus();
		return false;
	}
	if (trim(document.writereview.category.value) == "") {
		alert("Select the Category");
		document.writereview.category.focus();
		return false;
	}
	
	if (trim(document.writereview.city.value) == "") {
		alert("Enter the city");
		document.writereview.city.focus();
		return false;
	}
	
	if(trim(document.writereview.zipcode.value) != '') {
		if (!IsNumber(document.writereview.zipcode.value,"Zip Code"))
		{
			document.writereview.zipcode.focus();
			return false;
		}
	}
	document.writereview.hdAction.value='editbusiness';
	document.writereview.submit();	

	//return true;


	
}



function checkinvitegroupfriendsvalidation() {
	var emailids = new Array();
	groupemailaddress = document.getElementById("groupemailaddress").value;
	if (groupemailaddress != "") {
		emailids = groupemailaddress.split(",");	
	} else {
		alert("Enter atleast one email address");
		document.getElementById("groupemailaddress").focus();	
		return false;
	}
	
	//alert(emailids.length);	
	for (i=0;i<emailids.length;i++) {
		if (emailids[i] != "") {
			if(!isEmail(emailids[i])) {
				errid = parseInt(i+1);
				alert("Email id "+ emailids[i] + "at pos "+ errid +" is not valid");
				document.getElementById("groupemailaddress").focus();
				return false;
			}
		} 		
 	}
	
	document.invitefriends.hdemailOption.value = "group";
	document.invitefriends.hdAction.value='invitefriends';
	return true;
	
}

function checkinviteseperatefriendsvalidation() {
	var flag = 0;
	var empty = new Array();
	var valid = new Array();
	for (i=1;i<6;i++) {
		emailid = "email"+i;
		if (trim(document.getElementById(emailid).value)=="") {
			empty[i] = i;
			flag = 1;
		} else {			
			if(!isEmail(document.getElementById(emailid).value)) {
				document.getElementById(emailid).focus();				
			} else {
				flag = 0;	
				valid[i] = i;
			}
			
		}
	}
	
	if (valid.length == 0)	{
		alert("Enter atleast one email address");
		document.getElementById("email1").focus();	
		return false;
	}
	document.invitefriends.hdemailOption.value = "seperate";
	document.invitefriends.hdAction.value='invitefriends';
	return true;
	
}

function checkwritereviewsvalidation(){ 

	if (trim(document.writereviews.morateval.value) =="")
	{
		alert("Select the rating");
		return false;
	}
	
	var browser=navigator.userAgent.toLowerCase();
	var is_ie7    = (browser.indexOf("msie 7.")!=-1);	
	
	
	if(is_ie7) {
	
		document.getElementById('yourreview').value = tinyMCE.getContent('yourreview');
			if(trim(document.getElementById('yourreview').value) == '')
			{
				alert("Enter your review");
				//document.writereviews.yourreview.focus();
				return false;
			}
	} else {
		document.getElementById('yourreview').innerHTML = tinyMCE.getContent('yourreview');
			if(trim(document.getElementById('yourreview').innerHTML) == '')
			{
				alert("Enter your review");
				//document.writereviews.yourreview.focus();
				return false;
			}
	}
	
/*	if (document.writereviews.yourreview.value == "")
	{
		alert("Enter your review");
		document.writereviews.yourreview.focus();
		return false;
	}*/
	document.writereviews.hdAction.value='writereviews';
	document.writereviews.submit();	
}
function checksuggestcorrectionvalidation(){ 
	if (trim(document.correction.correctiontype.value) ==""){
		alert("select the correction type");
		document.correction.correctiontype.focus();
		return false;
	}
	if (trim(document.getElementById("suggestcomment").value) == ""){
		alert("Please enter the comment");
		document.getElementById("suggestcomment").focus();
		return false;
	}
	document.correction.hdAction.value='suggest';
	return true;
}

function checksuggestvalidation(){ 

	if (trim(document.getElementById("email").value) != ""){
		if(!isEmailAddr(document.getElementById("email").value))
		{
			alert("Invalid Email Address");
			document.getElementById("email").focus();
			return false;
		}
	}
	if (trim(document.getElementById("suggestcomment").value) == ""){
		alert("Please enter the comment");
		document.getElementById("suggestcomment").focus();
		return false;
	}
	if (trim(document.getElementById("RVerification").value) == "") {
		alert("Enter the Verfication code");
		document.getElementById("RVerification").focus();
		return false;
	}
	
	document.suggest_form.hdAction.value='suggestion';
	document.suggest_form.submit();
	
}

function checkphotouploadvalidation(){
	if(trim(document.photoupload.photo.value) !=''){
		photo=document.photoupload.photo.value;
		if(!/(\.jpg|\.gif)$/i.test(photo)) {
			alert("Invalid file type.");
			document.photoupload.photo.focus();
			return false;
		}
	} else {
		alert("Please browse the image to upload");
		document.photoupload.photo.focus();
		return false;
	}

	document.photoupload.hdAction.value='photoupload';
	return true;
}
function checkphotouploadvalidation1(){
	if(trim(document.photoupload.photo.value) != ''){
		photo=document.photoupload.photo.value;
		if(!/(\.jpg|\.gif)$/i.test(photo)) {
			alert("Invalid file type.");
			document.photoupload.photo.focus();
			return false;
		}
	} else {
		alert("Please browse the image to upload");
		document.photoupload.photo.focus();
		return false;
	}
	if (trim(document.photoupload.location.value) == "")
	{
		alert("Please enter the location");
		document.photoupload.location.focus();
		return false;
	}
	document.photoupload.hdAction.value='photosupload';
	return true;
}

function checkpfofilephotouploadvalidation(){
	if(trim(document.photoupload.photo.value) != ''){
		photo=document.photoupload.photo.value;
		if(!/(\.jpg|\.gif)$/i.test(photo)) {
			alert("Invalid file type.");
			document.photoupload.photo.focus();
			return false;
		}
	} else {
		alert("Please browse the image to upload");
		document.photoupload.photo.focus();
		return false;
	}

	document.photoupload.hdAction.value='profilephotosupload';
	return true;
}

function checksendtoafriendvalidation(){ 
	if (trim(document.sendtoafriend.email1.value) == "")
	{
		alert("Atleast one email should be entered");
		document.sendtoafriend.email1.focus();
		return false;
	}

	if (trim(document.sendtoafriend.email1.value) != "")
	{
		if(!isEmailAddr(document.sendtoafriend.email1.value))
		{
			alert("Invalid Email Address");
			document.sendtoafriend.email1.focus();
			return false;
		}
	}
	if (trim(document.sendtoafriend.yourname.value) == "")
	{
		alert("Enter your name");
		document.sendtoafriend.yourname.focus();
		return false;
	}
	if (trim(document.sendtoafriend.youremail.value) == "")
	{
		alert("Enter your email address");
		document.sendtoafriend.youremail.focus();
		return false;
	}
	if(!isEmailAddr(document.sendtoafriend.youremail.value))
	{
		alert("Invalid Your Email Address");
		document.sendtoafriend.youremail.focus();
		return false;
	}
	document.sendtoafriend.hdaction.value='sendtoafriend';
	return true;
}

function checksitesuggestionvalidation(){ 
	if (trim(document.sitesuggestion.suggestion.value) == "")
	{
		alert("Enter your suggestion");
		document.sitesuggestion.suggestion.focus();
		return false;
	}	
	document.sitesuggestion.hdaction.value='sitesuggestion';
	return true;
}
