/* Common Function For Valiudation*/
	var numb = '0123456789';
	
	var lwr = 'abcdefghijklmnopqrstuvwxyz';
	var lwrUser = 'abcdefghijklmnopqrstuvwxyz-_0123456789';
	var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var space=" ";
	function isValid(parm,val) {
	if (parm == "") return true;
	for (i=0; i<parm.length; i++) {
	if (val.indexOf(parm.charAt(i),0) == -1) return false;
	}
	 return true;
	}
	function validnamechk(parm) 
	{
	 return isValid(parm,lwr+upr+space);
	}
	function validUsernamechk(parm) 
	{
	 return isValid(parm,lwrUser+upr);
	}
	function validCountryCode(parm) 
	{
	 return isValid(parm,numb+"+");
	}
/* Common Function For Valiudation*/	
/*password validation*/
function validatePwd(strPass,strpass2) {
	var retStr="";
	var invalid = " "; // Invalid character is a space
	var minLength = 6; // Minimum length
	var pw1 = strPass;
	var pw2 = strpass2;
	// check for a value in both fields.
	if (pw1 == '' || pw2 == '') {
			retStr+='Please enter your password twice.\n';
		}
	// check for minimum length
	if (strPass.length < minLength) {
	retStr+='Your password must be at least ' + minLength + ' characters long. Try again.\n';
	}
// check for spaces
//alert(strPass.indexOf(invalid));
	if (strPass.indexOf(invalid) > -1) {
	retStr+="Sorry, spaces are not allowed.\n";
	
	}
	else if (pw1 != pw2) {
		retStr+="You did not enter the same new password twice. Please re-enter your password.\n";
		}
	return retStr;
}
//  End -->

/* Funtion To Validate Email Address Information*/ 
function emailCheck(emailStr) {
          var sw = true;
          var checkTLD=0;
          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) { sw = false; return sw; }
          var user=matchArray[1];
          var domain=matchArray[2];
          for (i=0; i<user.length; i++) {
          if (user.charCodeAt(i)>127) sw = false;
          }
          for (i=0; i<domain.length; i++) {
          if (domain.charCodeAt(i)>127) sw = false;
          }
          if (user.match(userPat)==null) sw = false;
          var IPArray=domain.match(ipDomainPat);
          if (IPArray!=null) {
          for (var i=1;i<=4;i++) {
          if (IPArray[i]>255) sw = false;
          }
          return true;
          }
          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) sw = false;
          }
          if (checkTLD && domArr[domArr.length-1].length!=2 &&
          domArr[domArr.length-1].search(knownDomsPat)==-1) sw = false;
          if (len<2) sw = false;
          return sw;
          }
/* Funtion To Validate Email Address Information*/ 		  
/* Funtion To Validate Numeri Information*/ 
function isNumeric(s)
{
	var i

	for (i = 0; i < s.length; i++)
	{
		if (s.charAt(i) < "0" || s.charAt(i) > "9")
			return false;
	}
	return true;
}
function hasSpace(s)
{
	var i;

	for (i = 0; i < s.length; i++)
	{
		//alert(s.charAt(i));
		if (s.charAt(i) == " ")
			return false;
	}
	return true;
}
/* Funtion To Validate Numeri Information*/ 
/* Funtion To Validate Information Seeker Information*/
function chkSeeker()
	{
		var username=document.presister.username.value;
		var fname=document.presister.fname.value;
		var lname=document.presister.lname.value;
		var email=document.presister.email.value;
		var remail=document.presister.remail.value;
		if(document.presister.pass){
			var pass=document.presister.pass.value;
			var repass=document.presister.repass.value;
		}
		/*var streetaddress=document.presister.streetaddress.value;
		var state=document.presister.state.value;
		var country=document.presister.country.value;
		var zipcode=document.presister.zipcode.value;
		var primaryno=document.presister.primaryno.value;
		*/		
		var termsandcondition=document.presister.terms.checked;
		var securityQues=document.presister.securityQuestion.value;
		var securityAns=document.presister.securityAnswer.value;
		var countryCode=document.presister.countryCode.value;
		var secCountryCode=document.presister.secCountryCode.value;
		var secondaryno=document.presister.secondaryno.value;
		var securitycode=document.presister.code.value;
		var enterseccode=document.presister.codee.value;
		var msg="";
		if(username=="")
		{
			msg="Enter the username.\n";
			
		}else if(!validUsernamechk(username))
		{
		 msg+="Invalid character in User name.\n";
		}		
		if(document.presister.pass){
		if(pass=="")
		{
			msg+="Enter the password.\n";
		}else if(pass.length<6 ){
			
			msg+=validatePwd(pass,repass);//"Password must have more than 6 character.\n";
		}else if(hasSpace(pass)==false){
			msg+="Space is not allowed in password.\n"
			
		}else if(repass==""){
			msg+="Retype your password.\n";
		}else if(pass!=repass){
			msg+="Password not match.\n"
		}
		}
		
	  if(securityQues=="")
		{
			msg+="Select security question.\n";
		}
		if(securityAns=="")
		{
			msg+="Enter security question's answer.\n";
		}	
		
		if(fname=="")
		{
			msg+="Enter the First name.\n";
		}else if(!validnamechk(fname))
		{
		 msg+="Invalid character in First name.\n";
		}
		if(lname=="")
		{
			msg+="Enter the Last name.\n";
		}else if(!validnamechk(lname))
		{
		 msg+="Invalid character in Last name.\n";
		}
		if(email=="")
		{
			msg+="Enter the Email.\n";
		}else if(!emailCheck(email)){
				msg+="Please enter email in correct format i.e username@email.com.\n";
			 }/*else if((email != "") && (email.indexOf("@")==-1 || email.indexOf(".")==-1 ))
		{
			msg+="Please enter email in correct format i.e username@email.com.\n";
		}*/
		if(remail=="")
		{
			msg+="Enter the Confirm Email.\n";
		}else if(!emailCheck(remail)){
				msg+="Please enter email in correct format i.e username@email.com.\n";
			 }/*else if((remail != "") && (remail.indexOf("@")==-1 || remail.indexOf(".")==-1 ))
		{
			msg+="Please enter email in correct format i.e username@email.com.\n";
		}*/
		if(email!=remail)
		{
			msg+="Entered mail are not matching.\n";
		}
		if(enterseccode=="")
		{
			msg+="Enter the Security Code.\n";
		}else if(securitycode!=enterseccode){
			msg+="Enter the Correct Security Code.\n";
		}
		/*if(repass=="")
		{
			msg+="Enter the confirm password.\n";
		}
		if(pass!=repass)
		{
			msg+="Entered password are not matched.\n";
		}*/
/*		
if(streetaddress=="")
		{
			msg+="Enter the Street address.\n";
		}
		if(state=="")
		{
			msg+="Enter the state.\n";
		}else{
		if(document.presister.state.type!="select-one"){
 			if(!validnamechk(state)){
			msg+="Invalid character in state name.\n";		
			}
		}
	}

		if(country=="")
		{
			msg+="Enter the country.\n";
		}
		if(zipcode=="")
		{
			msg+="Enter the zipcode.\n";
		}
		if(countryCode=="")
		{
			msg+="Enter the Country code for phone number.\n";
		}
		else if(!validCountryCode(countryCode))
		{
		 msg+="Invalid character in Country code.\n";
		}		
		if(primaryno=="")
		{
			msg+="Enter the primary phone number.\n";
		}
		if(secCountryCode!=""){
			if(!validCountryCode(secCountryCode))
		    {
			 msg+="Invalid character in Country code.\n";
		   }		
		}*/
		
		if(termsandcondition==false)
		{
			msg+="Please check the terms and conditions.\n";
		}
		if(msg!="")
		{
		 alert(msg);
		 return false;
		}else
		{
		 return true;
		}
		
	}
/* Funtion To Validate Information Seeker Information*/	
/* Funtion To Validate Research Professional Information*/	
	function chkProfessional()
	{
		var username=document.presister.username.value;
		var fname=document.presister.fname.value;
		var lname=document.presister.lname.value;
		var email=document.presister.email.value;
		var remail=document.presister.remail.value;
		if(document.presister.pass){
			var pass=document.presister.pass.value;
			var repass=document.presister.repass.value;
		}
		
		/*var streetaddress=document.presister.streetaddress.value;
		var state=document.presister.state.value;
		*/
		var country=document.presister.country.value;
		/*var zipcode=document.presister.zipcode.value;
		var primaryno=document.presister.primaryno.value;
		*/
		var screenname=document.presister.screenname.value;
		var chooseservicetype1=document.presister.chooseservicetype.length;

		var chooseCategoryNum=document.presister.industrycategory.length;
		var premiumtype1=document.presister.premiumtype.length;
		var termsandcondition=document.presister.terms.checked;
		var securityQues=document.presister.securityQuestion.value;
		var securityAns=document.presister.securityAnswer.value;
		var countryCode=document.presister.countryCode.value;
		var secCountryCode=document.presister.secCountryCode.value;
		var secondaryno=document.presister.secondaryno.value;
		var securitycode=document.presister.code.value;
		var enterseccode=document.presister.codee.value;
		var i,j,k,chooseCategory=0;
		for(i=0;i<chooseCategoryNum;i++)
		{
			if(document.presister.industrycategory[i].selected==true)
			{
				//chooseservicetype2=document.presister.chooseservicetype[i].value;
				chooseCategory++;
			}
		}

		var chooseservicetype2="",premiumtype2="",msg="";
		for(i=0;i<chooseservicetype1;i++)
		{
			if(document.presister.chooseservicetype[i].checked==true)
			{
				chooseservicetype2=document.presister.chooseservicetype[i].value;
			}
		}
		for(j=0;j<premiumtype1;j++)
		{
			if(document.presister.premiumtype[j].checked==true)
			{
				premiumtype2=document.presister.premiumtype[j].value;
			}
		}
	
		if(username=="")
		{
			msg="Enter the username.\n";
		}else if(!validUsernamechk(username))
		{
		 msg+="Invalid character in User name.\n";
		}
		
		
		if(document.presister.pass){
		if(pass=="")
		{
			msg+="Enter the password.\n";
		}else if(pass.length<6 ){
			
			msg+=validatePwd(pass,repass);//"Password must have more than 6 character.\n";
		}else if(hasSpace(pass)==false){
			msg+="Space is not allowed in password.\n"
			
		}else if(repass==""){
			msg+="Retype your password.\n";
		}else if(pass!=repass){
			msg+="Password not match.\n"
		}
	}
		if(securityQues=="")
		{
			msg+="Select security question.\n";
		}
		if(securityAns=="")
		{
			msg+="Enter security question's answer.\n";
		}
		if(screenname=="")
		{
			msg+="Enter the screen name.\n";
		}else if(!validUsernamechk(screenname)){
			msg+="Invalid characters in screen name.\n";
		}
		
		if(fname=="")
		{
			msg+="Enter the First name.\n";
		}else if(!validnamechk(fname))
		{
		 msg+="Invalid character in First name.\n";
		}
		if(lname=="")
		{
			msg+="Enter the Last name.\n";
		}else if(!validnamechk(lname))
		{
		 msg+="Invalid character in Last name.\n";
		}
		
		if(email=="")
		{
			msg+="Enter the Email.\n";
		}else if(!emailCheck(email)){
				msg+="Please enter email in correct format i.e username@email.com.\n";
			 }
		/*else if((email != "") && (email.indexOf("@")==-1 || email.indexOf(".")==-1 ))
		{
			msg+="Please enter email in correct format i.e username@email.com.\n";
		}*/
		if(remail=="")
		{
			msg+="Enter the Confirm Email.\n";
		}else if(!emailCheck(remail)){
				msg+="Please enter email in correct format i.e username@email.com.\n";
			 }/*else if((remail != "") && (remail.indexOf("@")==-1 || remail.indexOf(".")==-1 ))
		{
			msg+="Please enter email in correct format i.e username@email.com.\n";
		}*/
		if(email!=remail)
		{
			msg+="Entered mail are not matching.\n";
		}
if(chooseCategory==0 || chooseCategory<1){
msg+="Please select Industry Category.\n";
	
}
if(chooseCategory>3){
msg+="Please select three Industry Category only.\n";
	
}
/*
		if(streetaddress=="")
		{
			msg+="Enter the Street address.\n";
		}*/
/*		
if(state=="")
		{
			msg+="Enter the state.\n";
		}else{
		if(document.presister.state.type!="select-one"){
 			if(!validnamechk(state)){
			msg+="Invalid character in state name.\n";		
			}
		}
	}*/
		if(country=="")
		{
			msg+="Enter the country.\n";
		}
		if(enterseccode=="")
		{
			msg+="Enter the Security Code.\n";
		}else if(securitycode!=enterseccode){
			msg+="Enter the Correct Security Code.\n";
		}
		/*if(zipcode=="")
		{
			msg+="Enter the zipcode.\n";
		}*//*
		if(countryCode=="")
		{
			msg+="Enter the Country code for phone number.\n";
		}
		else if(!validCountryCode(countryCode))
		{
		 msg+="Invalid character in Country code.\n";
		}	
		if(primaryno=="")
		{
			msg+="Enter the primary phone number.\n";
		}
		if(secCountryCode!=""){
			if(!validCountryCode(secCountryCode))
		    {
			 msg+="Invalid character in Country code.\n";
		   }		
		}*/
		
		if(chooseservicetype2=="")
		{
			msg+="select the service type.\n";
		}else if (chooseservicetype2=="Premium")
		{
			if(premiumtype2=="")
			{
				msg+="select the Premium type.\n";
			}
		}
		if(termsandcondition==false)
		{
			msg+="Please check the terms and conditions.\n";
		}
		if(msg!="")
		{
		alert(msg);
		return false;
		}else
		{
		return true;
		}
	}

///*
/* Funtion To chkProfessionalUpgrade Validate Research Professional Information*/	
	function chkProfessionalUpgrade()
	{
		var screenname=document.presister.screenname.value;
		var chooseservicetype1=document.presister.chooseservicetype.length;
		var premiumtype1=document.presister.premiumtype.length;
		var termsandcondition=document.presister.terms.checked;
		
		var i,j;
		var chooseservicetype2="",premiumtype2="",msg="";
		
		
		/*if(chooseservicetype2=="")
		{
			msg+="select the service type.\n";
		}else if (chooseservicetype2=="Premium")
		{
			if(premiumtype2=="")
			{
				msg+="select the Premium type.\n";
			}
		}*/
		if(termsandcondition==false)
		{
			msg+="Please check the terms and conditions.\n";
		}
		if(msg!="")
		{
		alert(msg);
		return false;
		}else
		{
		return true;
		}
	}
//
	function show()
	{
		var trp=document.getElementById("premiumtype1");
		var premiumtypeAcc=document.getElementById("premiumtypeAccount");
		var chooseservicetype1=document.presister.chooseservicetype.length;		
		var i;
		var chooseservicetype2="";
		for(i=0;i<chooseservicetype1;i++)
		{
			if(document.presister.chooseservicetype[i].checked==true)
			{
				chooseservicetype2=document.presister.chooseservicetype[i].value;
			}
		}
		if(chooseservicetype2=="Premium")
		{
			trp.style.display="block";
			premiumtypeAcc.style.display="none";
			premiumPromo.style.display="block";
		}else
		{
			trp.style.display="none";
			premiumtypeAcc.style.display="none";
			premiumPromo.style.display="none";
			//premiumtypeAcc.style.display="none";
		}
	}
	function onSubmit(objFrm)
	{
		objFrm.submit();
	}
/* Funtion To Validate Research Professional Information*/	
/*Validate Phone Fax Mobile*/

//////////**************************************************/////////////
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters ="";// "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars =phoneNumberDelimiters;// + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 5;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidateForm(Phone)
{
        //var Phone=document.employee_reg.phone;

        if ((Phone.value==null)||(Phone.value==""))
                {
                alert("Please Enter your Phone Number")
                Phone.focus()
                return false
        }
        if (checkInternationalPhone(Phone.value)==false)
                {
                alert("Please Enter a Valid Phone Number")
                Phone.value=""
                Phone.focus()
                return false
        }
        return true
 }
function ValidateFormmobile(MPhone)
{
        //var Phone=document.employee_reg.phone;

        if ((MPhone.value==null)||(MPhone.value==""))
                {
                alert("Please Enter your mobile number")
                MPhone.focus()
                return false
        }
        if (checkInternationalPhone(MPhone.value)==false)
                {
                alert("Please Enter a Valid Mobile Number")
                MPhone.value=""
                MPhone.focus()
                return false
        }
        return true
 }


function ValidateFormfax(faxfield)
{
       // var Phone=document.employee_reg.phone;

        if ((faxfield.value==null)||(faxfield.value==""))
                {
                alert("Please Enter your fax number")
                faxfield.focus()
                return false
        }
        if (checkInternationalPhone(faxfield.value)==false)
                {
                alert("Please Enter a Valid fax number")
                faxfield.value=""
                faxfield.focus()
                return false
        }
        return true
 }
//////////**************************************************/////////////
///Ajax Function//////////
function GetXmlHttpObject()
{ 
		var objXMLHttp=null
		if (window.XMLHttpRequest)
		{
		objXMLHttp=new XMLHttpRequest()
		}
		else if (window.ActiveXObject)
		{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
		}
		return objXMLHttp
}
//////Common Ajax Function////////
function main(id,tdName)	
{
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  	alert ("Browser does not support HTTP Request")
	 	 return
	  }
	//at
  //alert(document.getElementById(id));
  if(tdName=="stateTd"){
	  url="admin/state_ajax.php";
	  url=url+"?country_name="+id
	  xmlHttp.onreadystatechange=matterState;
	  xmlHttp.open("GET",url,true)
      xmlHttp.send(null)
  }
   if(tdName=="premiumPromoDiv"){
	  url="/admin/promo_ajax.php";
	  url=url+"?promo_code="+id
	  xmlHttp.onreadystatechange=matterPromo;
	  xmlHttp.open("GET",url,true)
      xmlHttp.send(null)
  }
	  	
}
function matterState()	{

	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 {
		//alert(xmlHttp.responseText);
		
		document.getElementById("stateTd").innerHTML=xmlHttp.responseText;
	}
}
function matterPromo()	{
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 {
		document.getElementById("premiumPromoDiv").innerHTML=xmlHttp.responseText;
		
	}
}
//sc
function selectState(strName){
if(strName=="other"){
	 main(id="other","stateTd");
 }
}
///Ajax Function//////////
function MM_openBrWindow(theURL,winName,features) 
{ //v2.0
  window.open(theURL,winName,features+",resizable=yes,scrollbars=yes");
}
///
function showSub(id)	{
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  	alert ("Browser does not support HTTP Request")
	 	 return
	  }
	
	  url="/admin/subcat_ajax.php";
	  url=url+"?catparent="+id
	  xmlHttp.onreadystatechange=showSubcategories;
	  xmlHttp.open("GET",url,true)
      xmlHttp.send(null)
  
	  	
}
function showSubcategories()	{
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 {
		//alert(xmlHttp.responseText);
		
		document.getElementById("reportsubcatstd").innerHTML=xmlHttp.responseText;
	}
}
//
function showOtherOption(strName,divtd){
var divtdId=document.getElementById(divtd);
if(strName=="Other")
		{			
			divtdId.style.display="block";
		}else
		{
			divtdId.style.display="none";
			
		}
}
//FckEditor Validations
function checkFckeditor(strObjname)
{
	// This functions shows that you can interact directly with the editor area
	// DOM. In this way you have the freedom to do anything you want with it.

	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance(strObjname) ;

	// Get the Editor Area DOM (Document object).
	var oDOM = oEditor.EditorDocument ;

	var iLength ;

	// The are two diffent ways to get the text (without HTML markups).
	// It is browser specific.

	if ( document.all )		// If Internet Explorer.
	{
		iLength = oDOM.body.innerText.length ;
	}
	else					// If Gecko.
	{
		var r = oDOM.createRange() ;
		r.selectNodeContents( oDOM.body ) ;
		iLength = r.toString().length ;
	}
//alert( 'Actual text length (without HTML markups): ' + iLength + ' characters' ) ;
return iLength;
	
}
//FckEditor Validations
//compare dates
function CompareDates(fromDate,toDate) 
{ 
   var str1  =fromDate;// document.getElementById("Fromdate").value;
   var str2  =toDate;// document.getElementById("Todate").value;
   var dt1   = parseInt(str1.substring(8,10),10); 
   var mon1  = parseInt(str1.substring(5,8),10);
   var yr1   = parseInt(str1.substring(0,4),10); 

   var dt2   = parseInt(str2.substring(8,10),10);
   var mon2  =parseInt(str2.substring(5,8),10);
   var yr2   = parseInt(str2.substring(0,4),10);
   var date1 = new Date(yr1, mon1, dt1); 
   var date2 = new Date(yr2, mon2, dt2); 

   if(date2 >= date1)
   {
      //alert("Expiry date cannot be less than Current date");
      return false; 
   } 
   else 
   { 
     //alert("Submitting ...");
	return true;
     // document.form1.submit(); 
   } 
} 
//compare dates