function trim(str)
{
	return str.replace(/^\s+|\s+$/, ''); 
}

function signupValidation()
{
	if(trim(document.getElementById("fName").value)=='')
	{
		alert('please enter first name!');
		document.getElementById("fName").focus();
		return false;
	}
	if(trim(document.getElementById("lname").value)=='')
	{
		alert('please enter last name!');
		document.getElementById("lname").focus();
		return false;
	}
	if(trim(document.getElementById("street").value)=='')
	{
		alert('please enter street!');
		document.getElementById("street").focus();
		return false;
	}
	if(trim(document.getElementById("city").value)=='')
	{
		alert('please enter city!');
		document.getElementById("city").focus();
		return false;
	}
	if(trim(document.getElementById("state").value)=='')
	{
		alert('please enter state!');
		document.getElementById("state").focus();
		return false;
	}
	if(trim(document.getElementById("zip").value)=='')
	{
		alert('please enter zip!');
		document.getElementById("zip").focus();
		return false;
	}
	if(document.getElementById("country").value==false)
	{
		alert('please select country!');
		document.getElementById("country").focus();
		return false;
	}
	if(trim(document.getElementById("dphone").value)=='')
	{
		alert('please enter daytime phone!');
		document.getElementById("dphone").focus();
		return false;
	}
	if(trim(document.getElementById("mail").value)=='')
	{
		alert('please enter email!');
		document.getElementById("mail").focus();
		return false;
	}
	if(!isValidEmail(trim(document.getElementById("mail").value)))
	{
		document.getElementById("mail").focus();
		return false;
	}
	if(document.getElementById("mail").value != document.getElementById("conmail").value)
	{
		alert('Email Not Match');
		document.getElementById("conmail").focus();
		return false;
	}
	if(trim(document.getElementById("dob").value)=='')
	{
		alert('please enter D.O.B.!');
		document.getElementById("dob").focus();
		return false;
	}
	/*if(trim(document.getElementById("sex").value)=='')
	{
		alert('please enter sex!');
		document.getElementById("sex").focus();
		return false;
	}*/
	if(trim(document.getElementById("uName").value)=='')
	{
		alert('please enter user name!');
		document.getElementById("uName").focus();
		return false;
	}
	if(trim(document.getElementById("password").value)=='')
	{
		alert('please enter password!');
		document.getElementById("password").focus();
		return false;
	}
	if(trim(document.getElementById("confirmPassword").value)=='')
	{
		alert('please enter confirm password!');
		document.getElementById("confirmPassword").focus();
		return false;
	}
	if(document.getElementById("password").value != document.getElementById("confirmPassword").value)
	{
		alert('Password Not Match');
		
		return false;
	}
    document.regForm.submit();
	return true;
}

function isValidEmail(emstr)
{
	var vEMailID=emstr
	var atPos= vEMailID.indexOf("@") + 1
	var lastDotPos= vEMailID.lastIndexOf(".") + 1
	var firstDotPos = vEMailID.indexOf(".") + 1
	var atInstances=0
	var dotInstances=0
	var inValid = new Array()
	var errorMessages = new Array()
	var errNo = 0

	for(var i=0;i<vEMailID.length;i++)
	{   
		if(vEMailID.charAt(i)=="@" )
		atInstances+=1
		else if(vEMailID.charAt(i)==".")
		dotInstances=1
	}

	inValid[errNo] = (atInstances==0)
	errorMessages[errNo] = "@ symbol is missing"
	errNo++

	inValid[errNo] = (dotInstances==0)
	errorMessages[errNo] = ". symbol is missing"
	errNo++

	inValid[errNo] = (atInstances>1)
	errorMessages[errNo] = "@ symbol should not repeat"
	errNo++

	inValid[errNo] = (Math.abs(firstDotPos-atPos)==1)
	errorMessages[errNo] = "@ and . symbols can't come together"
	errNo++

	inValid[errNo] = ((lastDotPos-atPos)<=1)
	errorMessages[errNo] = ". symbol is missing"
	errNo++

	inValid[errNo] = (atPos==vEMailID.length)
	errorMessages[errNo] = "@ symbol can't appear at end"
	errNo++

	inValid[errNo] = (lastDotPos==vEMailID.length)
	errorMessages[errNo] = ". symbol can't appear at end"
	errNo++

	inValid[errNo] = (atPos==0)
	errorMessages[errNo] = "@ symbol is missing"
	errNo++

	inValid[errNo] = (atPos==1)
	errorMessages[errNo] = "@ symbol should not appear at first position"
	errNo++

	inValid[errNo] = (firstDotPos==0)
	errorMessages[errNo] = ". symbol is missing"
	errNo++

	inValid[errNo] = (firstDotPos==1)
	errorMessages[errNo] = ". symbol should not appear at first position"
	errNo++

	inValid[errNo] = (vEMailID.indexOf(" ")>=0)
	errorMessages[errNo] = "E-mail can't contain blank spaces."
	errNo++

	inValid[errNo] = (vEMailID.indexOf("/")>=0) || (vEMailID.indexOf("\\")>=0)
	errorMessages[errNo] = "E-mail can't contain \\ or /"
	errNo++

	var fullErrorMessage = "Invalid " + name + " email address.\n"
	for(var ind=0; ind<errNo; ind++)
	{
		if(inValid[ind])
		{
		fullErrorMessage += errorMessages[ind] + "\n"
		alert(fullErrorMessage)			
		return false
		}
	}
	var SingleQuotePos = vEMailID.indexOf("'") 
	if(SingleQuotePos!=-1)
	{
		alert("Enter valid characters.Single Quotes ( ' ) are not allowed.")					
		return false
	} 

	return true;
}

function loginValidation()
{
	if(trim(document.getElementById("uName").value)=='')
	{
		alert('please enter user name!');
		document.getElementById("uName").focus();
		return false;
	}
	if(trim(document.getElementById("password").value)=='')
	{
		alert('please enter password!');
		document.getElementById("password").focus();
		return false;
	}
}

function passValidation()
{
	if(trim(document.getElementById("old_password").value)=='')
	{
		alert('please enter old password!');
		document.getElementById("old_password").focus();
		return false;
	}
	if(trim(document.getElementById("password").value)=='')
	{
		alert('please enter new password!');
		document.getElementById("password").focus();
		return false;
	}
	if(trim(document.getElementById("confirmPassword").value)=='')
	{
		alert('please enter confirm password!');
		document.getElementById("confirmPassword").focus();
		return false;
	}
	if(document.getElementById("password").value != document.getElementById("confirmPassword").value)
	{
		alert('Password Not Match');
		
		return false;
	}
}








function affiliateValidation()
{
	if(trim(document.getElementById("fName").value)=='')
	{
		alert('please enter first name!');
		document.getElementById("fName").focus();
		return false;
	}
	if(trim(document.getElementById("lname").value)=='')
	{
		alert('please enter last name!');
		document.getElementById("lname").focus();
		return false;
	}
/*	if(trim(document.getElementById("company").value)=='')
	{
		alert('please enter company name!');
		document.getElementById("company").focus();
		return false;
	}*/
	if(trim(document.getElementById("dob").value)=='')
	{
		alert('please enter D.O.B.!');
		document.getElementById("dob").focus();
		return false;
	}
	if(trim(document.getElementById("contact").value)=='')
	{
		alert('please enter contact number!');
		document.getElementById("contact").focus();
		return false;
	}
	if(trim(document.getElementById("mail").value)=='')
	{
		alert('please enter email!');
		document.getElementById("mail").focus();
		return false;
	}
	if(!isValidEmail(trim(document.getElementById("mail").value)))
	{
		document.getElementById("mail").focus();
		return false;
	}
	if(document.getElementById("mail").value != document.getElementById("conmail").value)
	{
		alert('Email Not Match');
		document.getElementById("conmail").focus();
		return false;
	}
		if(trim(document.getElementById("address").value)=='')
	{
		alert('please enter address!');
		document.getElementById("address").focus();
		return false;
	}
	if(trim(document.getElementById("city").value)=='')
	{
		alert('please enter city!');
		document.getElementById("city").focus();
		return false;
	}
	if(trim(document.getElementById("state").value)=='')
	{
		alert('please enter state!');
		document.getElementById("state").focus();
		return false;
	}
	if(trim(document.getElementById("zip").value)=='')
	{
		alert('please enter zip!');
		document.getElementById("zip").focus();
		return false;
	}
		if(document.getElementById("country").value==false)
	{
		alert('please select country!');
		document.getElementById("country").focus();
		return false;
	}
	if(trim(document.getElementById("website").value)=='')
	{
		alert('please enter website!');
		document.getElementById("website").focus();
		return false;
	}
	
	
	

	if(trim(document.getElementById("uName").value)=='')
	{
		alert('please enter user name!');
		document.getElementById("uName").focus();
		return false;
	}
	if(trim(document.getElementById("password").value)=='')
	{
		alert('please enter password!');
		document.getElementById("password").focus();
		return false;
	}
	if(trim(document.getElementById("confirmPassword").value)=='')
	{
		alert('please enter confirm password!');
		document.getElementById("confirmPassword").focus();
		return false;
	}
	if(document.getElementById("password").value != document.getElementById("confirmPassword").value)
	{
		alert('Password Not Match');
		
		return false;
	}
   // document.regForm.submit();
	return true;
}






















/*
function showUser(str)
{
	//alert(str);
	if(str=="")
	{
		document.getElementById("textHint").innerHTML="";	
	}
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
	alert ("Browser does not support HTTP Request");
	return;
	}
	var url="js/checkuser.php";
	
	url=url+"?str="+str;
	//alert(url);
	
	//url=url+"&sid="+Math.random();
	
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
		document.getElementById("textHint").innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}


	
function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	{
	// code for IE7+, Firefox, Chrome, Opera, Safari
	return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
	// code for IE6, IE5
	return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}
*/