function emailCheck(emailStr) 
{
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null)
	 {	
		document.getElementById('ErrMsg').innerHTML = "<span class='redcolor' style='font-size:12;'>Email address seems incorrect (check @ and .'s)</span>";
		return false;
	 }
	var user=matchArray[1];
	var domain=matchArray[2];
	
	for (i=0; i<user.length; i++) 
	{
		if (user.charCodeAt(i)>127) 
		{
			document.getElementById('ErrMsg').innerHTML = "<span class='redcolor' style='font-size:12;'>Ths username contains invalid characters in Email address</span>";
			return false;
	    }
	}
	for (i=0; i<domain.length; i++) 
	{
		if (domain.charCodeAt(i)>127) 
		{
			document.getElementById('ErrMsg').innerHTML = "<span class='redcolor' style='font-size:12;'>Ths domain name contains invalid characters in Email address</span>";
			return false;
	   }
	}
	
	if (user.match(userPat)==null) 
	{	
			document.getElementById('ErrMsg').innerHTML = "<span class='redcolor' style='font-size:12;'>The username doesn't seem to be valid in Email Address</span>";
		return false;
	}
	
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) 
	{	
		for (var i=1;i<=4;i++) 
		{
			if (IPArray[i]>255) 
			{
			document.getElementById('ErrMsg').innerHTML = "<span class='redcolor' style='font-size:12;'>Destination IP address is invalid! in email address</span>";
				return false;
		   }
		}	
		return true;
		}
	
	// Domain is symbolic name.  Check if it's valid.
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
			document.getElementById('ErrMsg').innerHTML = "<span class='redcolor' style='font-size:12;'>The domain name does not seem to be valid in email address</span>";
	return false;
	   }
	}
	
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
			document.getElementById('ErrMsg').innerHTML = "<span class='redcolor' style='font-size:12;'>The address must end in a well-known domain or two letter " + "country in email address</span>";
	return false;
	}
	
	if (len<2) {
			document.getElementById('ErrMsg').innerHTML = "<span class='redcolor' style='font-size:12;'>This address is missing a hostname! in email address</span>";
	return false;
	}	
	return true;
}

function IsCharacter(strString)
 {
   var strValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return true;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}

function IsValidIDSpace(strString)
 {
   var strValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._-,()[] ";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}
function ValidUrl(strUrl)
{
	var RegexUrl = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return RegexUrl.test(strUrl);
}

function isPhoneNumber(s)
{
	rePhoneNumber = new RegExp(/^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/);
	return rePhoneNumber.test(s);
} 

function ValidateLogin()
{
	//alert("Mohsin");return false;
	if(document.Form.email.value == "")
	{
		document.getElementById('ErrMsg1').innerHTML = '<span class="redcolor">Enter Email Address</span>';
		document.Form.email.focus()
		return false
	}
	if(document.Form.password.value == "")
	{
		document.getElementById('ErrMsg1').innerHTML = 'Please Enter Your Password';
		document.Form.password.focus()
		return false
	}
	else
	{
		document.Form.mothod = "post"
		document.Form.action = "chk_login.php?action=1"
		document.Form.submit()
	}
}

function ValidateEmail()
{
	//alert("Mohsin");return false;
	if(document.Form.email.value == "")
	{
		document.getElementById('ErrMsg1').innerHTML = '<span class="redcolor">Enter Email Address</span>';
		document.Form.email.focus()
		return false
	}
	if(!emailCheck(document.Form.txtEmail.value))
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor">Please Enter Valid Email Address in the field</span></td></tr></table>';
		document.Form.txtEmail.focus()
		return false
	}
	else
	{
		document.Form.mothod = "post"
		document.Form.action = "chk_password.php?action=1"
		document.Form.submit()
	}
}

function ValidatePassword()
{
	
//	alert("Mohsin");return false;
	if(document.Form.txtPassword.value == "")
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor">Please Enter New Password in the field</span></td></tr></table>';
		document.Form.txtPassword.focus()
		return false
	}
	if(document.Form.txtRePassword.value == "")
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor">Please Re Enter Password in the field</span></td></tr></table>';
		document.Form.txtRePassword.focus()
		return false
	}
	if(document.Form.txtPassword.value != document.Form.txtRePassword.value)
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor">Your Password Does not Match Re Password</span></td></tr></table>';
		document.Form.txtRePassword.focus()
		return false
	}
	else
	{
		document.Form.mothod = "post"
		document.Form.action = "change_pwd.php?action=1"
		document.Form.submit()
	}
}

function ValidateReply(CID,PID,Page)
{
	if(document.Form.txtComments.value == "")
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor">Please Enter Comments in the field</span></td></tr></table>';
		document.Form.txtComments.focus()
		return false
	}
	else
	{
		document.Form.mothod = "post";
		document.Form.action = "save_comments.php?cid="+CID+"&pid="+PID+"&page="+Page+"&action=1";
		document.Form.submit();
	}
}


function ValidateFeedback()
{
	if(document.Form.txtName.value == "")
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor" >Please Enter Name in the field.</span></td></tr></table>';
		document.Form.txtName.focus()
		return false
	}
	if(document.Form.txtEmail.value == "")
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor">Please Enter Your Email Address in the field</span></td></tr></table>';
		document.Form.txtEmail.focus()
		return false
	}
	if(!emailCheck(document.Form.txtEmail.value))
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor">Please Enter Valid Email Address in the field</span></td></tr></table>';
		document.Form.txtEmail.focus()
		return false
	}
	if(document.Form.txtSubject.value == "")
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor">Please Enter Your Subject in the field</span></td></tr></table>';
		document.Form.txtSubject.focus()
		return false
	}
	if(document.Form.txtComments.value == "")
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor">Please Enter Comments in the field</span></td></tr></table>';
		document.Form.txtComments.focus()
		return false
	}
	else
	{
		document.Form.mothod = "post"
		document.Form.action = "save_feedback.php?action=add"
		document.Form.submit()
	}
}

function ValidatePost()
{
	if(document.Form.txtPost.value == "")
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor">Please Enter Your Post in the field</span></td></tr></table>';
		document.Form.txtPost.focus()
		return false
	}
	else
	{
		document.Form.mothod = "post"
		document.Form.action = "save_post.php?action=add"
		document.Form.submit()
	}
}

function ValidateSignUp()
{
	if(document.Form.txtEmail.value == "")
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor">Please Enter Your Email Address in the field</span></td></tr></table>';
		document.Form.txtEmail.focus()
		return false
	}
	if(!emailCheck(document.Form.txtEmail.value))
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor">Please Enter Valid Email Address in the field</span></td></tr></table>';
		document.Form.txtEmail.focus()
		return false
	}
	if(document.Form.hdnEmail.value == 1)
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor">Email Adress Already Exist !</span></td></tr></table>';
		document.Form.txtEmail.focus()
		return false
	}
	if(document.Form.txtPassword.value == "")
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor" >Please Enter Password in the field.</span></td></tr></table>';
		document.Form.txtPassword.focus()
		return false
	}
	if(document.Form.txtRePassword.value == "")
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor" >Please Re Enter Password in the field.</span></td></tr></table>';
		document.Form.txtRePassword.focus()
		return false
	}
	if(document.Form.txtPassword.value != document.Form.txtRePassword.value)
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor" >Your Password Does not Match the Retype Password</span></td></tr></table>';
		document.Form.txtRePassword.focus()
		return false
	}
	if(document.Form.txtUserName.value == "")
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor" >Please Enter Nick Name in the field.</span></td></tr></table>';
		document.Form.txtUserName.focus()
		return false
	}
	if(document.Form.hdnUser.value == 1)
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor">User Name Already Exist !</span></td></tr></table>';
		document.Form.hdnUser.focus()
		return false
	}
	if(document.Form.txtMobile.value == "")
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor" >Please Enter Mobile No in the field.</span></td></tr></table>';
		document.Form.txtMobile.focus()
		return false
	}
	
	if(document.Form.txtFirstName.value == "")
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor" >Please Enter First Name in the field.</span></td></tr></table>';
		document.Form.txtFirstName.focus()
		return false
	}
	
	if(document.Form.txtLastName.value == "")
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor" >Please Enter Last Name in the field.</span></td></tr></table>';
		document.Form.txtLastName.focus()
		return false
	}
	
	if(document.Form.txtAddress.value == "")
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor" >Please Enter Address in the field.</span></td></tr></table>';
		document.Form.txtAddress.focus()
		return false
	}
	if(document.Form.txtNationality.value == "")
	{
		document.getElementById('ErrMsg').innerHTML = '<table width="320" cellpadding="0" cellspacing="0" style="border:1px solid #FF0000"><tr><td align="center" height="20" class="errtext" bgcolor="#FFEAEA"><span class="redcolor" >Please Enter Nationality in the field.</span></td></tr></table>';
		document.Form.txtNationality.focus()
		return false
	}
	else
	{
		document.Form.mothod = "post"
		document.Form.action = "save_user.php?action=add"
		document.Form.submit()
	}
}