function validreg()
{
var cdt=0,dt=0,mn,dat,yr=0;
dt=document.frm.date.options[document.frm.date.options.selectedIndex].value;
mn=document.frm.month.options[document.frm.month.options.selectedIndex].value;
yr=document.frm.year.value;

if (dt>0 && mn!="mon" && parseFloat("0"+yr)>1700 )
{
		if (mn=="Feb")
			if (isleapreg()=="true") cdt=29; else	cdt=28;
		else
			if (mn=="Apr" || mn=="Jun" || mn=="Sep" || mn=="Nov" )	cdt=30;	else cdt=31;
		if(dt>cdt)
		{return("false");}
		else
		{
		    dat=dt+"-"+mn+"-"+yr;
		    document.frm.hiddob.value=dat;
		    return("true");
		}

}
else
	return("false");
}

function isleapreg()
{
var d=10,dd,t=0;
d=document.frm.year.value;
t=d-(Math.floor(d/4))*4;
if(t==0)
return ("true");
else
return("false");
}

function validatereg()
{
	if(document.frm.myprovince.options[document.frm.myprovince.options.selectedIndex].value=="0")
	{
		  alert("Please Select your Province");
		  document.frm.myprovince.focus();
		  return(true);
	}
	else if(document.frm.province.options[document.frm.province.options.selectedIndex].value=="0")
		{
		  alert("Please Select your Residing Province");
		  document.frm.province.focus();
		  return(true);
		}
    else if(document.frm.hidhouse.value=="0")
		{
		  alert("Please choose your House");
		}
	else if (isname())
		{
		if (removespace(document.frm.mailid.value)=="")
		   	{
		   		alert("\nThe E-Mail Address is empty. \n\nPlease enter your E-Mail Address.")
		   		document.frm.mailid.focus();
		   		return true;
		   	}
      	else if ( validreg()!="true")
           {
			document.frm.hiddob.value="";
			alert("Please enter your Date of Birth");
			return(true);
           }
    	else if ( isuserName() && isPass()) 
    	   {
              confirmregistration();
     	   }
       	}
}

function confirmregistration()
{
    if(confirm("Are you sure with your details ?"))
    { 	
      document.frm.hidmailid.value=document.frm.mailid.value;      
      document.frm.hidtxtusername.value=document.frm.chruserfullname.value;
      document.frm.hidmyprovince.value=document.frm.myprovince.options[document.frm.myprovince.options.selectedIndex].value;	 
      document.frm.submit();
    }<!-- final execution of onclick signup-->
}


function isname()
{	
	if(document.frm.hidcmbusername.value=="0")
	if (removespace(document.frm.chruserfullname.value) == "")
	{		
		alert("\nIf your Name is not in the List \n\nPlease enter your Name.")
		document.frm.chruserfullname.focus();
		return false;
	}
	return true;
}

function removespace(k)
{
str="";
for(i=0;i<k.length;i++)
if(k.substring(i,i+1)!=" ") str=str+k.substring(i,i+1);
return str;
}


function chooseprovincereg(k)
{	
document.frm.hidprovince.value=k;
document.frm.hidhouse.value='0';
if(house[k]+""=="undefined") house[k]=="";
document.getElementById("layerresi").innerHTML="<select name=house style='width:200px;' class='txtbox' onChange='choosehousereg(this.value);'><option value=0 selected>Your House</option>"+house[k]+"</select>";
choosehousereg(0);
}

function choosehousereg(k)
{
	document.frm.hidhouse.value=k;
	if(namess[k]+""=="undefined") namess[k]=="";
	document.getElementById("layername").innerHTML="<select style='width:200px;' class='txtbox' name=house onChange='FrontNameReg(this.value);'><option value=0 selected>Your Name</option>"+namess[k]+"</select>";
FrontNameReg(0);
}

function FrontNameReg(k)
{
	document.frm.hidcmbusername.value=k;
	document.frm.hidtxtusername.value='';
	document.frm.chruserfullname.value='';
}

//********************* Select option for state and city
function choosestatereg(k)
{	
document.frm.hidstate.value=k;
document.frm.hidcity.value='0';
if(city[k]+""=="undefined") city[k]=="";
document.getElementById("layercity").innerHTML="<select name='city' style='width:200px;' class='txtbox'><option value='0' selected>Your City</option>"+city[k]+"</select>";

}


var remote = null;
function popup_win( loc, wd, hg ) {
    remote = window.open('','TheRemote','width=' + wd + ',height=' + hg + ',resizable=0,scrollbars=1,top=0,left=0');
    if (remote != null) {
            if (remote.opener == null) {
            remote.opener = self;
        }
            remote.location.href = loc;
    } else { self.close(); }
}

function oldvalidate()
{

	if ( isuserName() && isPass()) document.frm.submit();
   
}


// Login Validator
function isuserName()
{
	var str = document.frm.chrusername.value;
	if (str == "")
	{
		alert("\n User Name is blank .\n\nPlease enter your User Name.")
		document.frm.chrusername.focus();
		return false;
	}
	if((str.substring(0,1)<"a" || str.substring(0,1)>"z") && (str.substring(0,1)<"A" || str.substring(0,1)>"Z"))
	{
		alert("The User Name should begin with an alphabetic character.");
		return false;
	}
	for (var i = 1; i < str.length; i++)
	{
		var ch = str.substring(i, i + 1);
		if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch) && (ch != '_'))
		{
			alert("\nThe User Name field  accepts letters,numbers & underscore.\n\nPlease re-enter your User Name.");
			document.frm.chrusername.select();
			document.frm.chrusername.focus();
			return false;
		}
	}
	return true;
}

// Password Validator
function isPass()
{
	var str = document.frm.chrpassword.value;
	if ((str == "") || (str.length < 4))
	{
		alert("\nThe Password is either empty or less than or 4 characters.\n\nPlease enter your Password.")
		document.frm.chrpassword.focus();
		return false;
	}
	for (var i = 1; i < str.length; i++)
	{
		var ch = str.substring(i, i + 1);
		if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch) && (ch != '_'))
		{
			alert("\nThe Password field  accepts letters,numbers & underscore.\n\nPlease re-enter your Password.");
			document.frm.chrpassword.select();
			document.frm.chrpassword.focus();
			return false;
		}
	}

	var str2 = document.frm.chrpassword1.value;
	if (str != str2)
	{
		alert("Passwords typed do not match, please enter your passwords.\n\n");
		document.frm.chrpassword1.focus();
		return false;
	}
	return true;
}
function RegFailure(msg)
{	
	var aTag = document.createElement('a');
	var ahref = 'Register.php?ajx=1&msg='+msg;
	aTag.setAttribute('href',ahref);
	AJAXURLCall(aTag,"LoginDIV");	
}
function RegSuccess(MsgStatus)
{	
	//alert(MsgStatus);
	var aTag = document.createElement('a');
	var ahref = 'Register.php?ajx=1&msg='+MsgStatus;
	aTag.setAttribute('href',ahref);
	AJAXURLCall(aTag,"divCenterPanel");
}

function AddProfileSuccess(msg,curpath)
{
	var aTag = document.createElement('a');
	var ahref = curpath + 'addprofile.php?msg='+msg;
	aTag.setAttribute('href',ahref);	
	AJAXURLCall(aTag,"divCenterPanel");
}

//The following script used for validate websites.htm page
function web_validatereg()
{
	var chrlevel=document.frmWebsites.hidchrlevel.value;	
	if (chrlevel<33)
	{
			if(document.frmWebsites.myprovince.options[document.frmWebsites.myprovince.options.selectedIndex].value=="0")
				{
					  alert("Please Select the Province");
					  document.frmWebsites.myprovince.focus();
					  return(true);
				}
			else if (removespace(document.frmWebsites.chrdomaincode.value)=="")
			   	{
			   		alert("Please enter Domain Code.")
			   		document.frmWebsites.chrdomaincode.focus();
			   		return true;
			   	}
			else if (removespace(document.frmWebsites.chrdomainname.value)=="")
			   	{
			   		alert("Please enter Domain Name.")
			   		document.frmWebsites.chrdomainname.focus();
			   		return true;
			   	}			
			   else
			   {
			   	document.frmWebsites.submit();
			   }
	}
	else if (chrlevel>33)
	{		
			if(document.frmWebsites.websitetype.options[document.frmWebsites.websitetype.options.selectedIndex].value=="0")
				{
					  alert("Please Select the Website Type");
					  document.frmWebsites.websitetype.focus();
					  return(true);
				}		
				
				else if (document.frmWebsites.house.options[document.frmWebsites.house.options.selectedIndex].value=="0" && document.frmWebsites.websitetype.options[document.frmWebsites.websitetype.options.selectedIndex].value=="1")
				{
					  alert("Please Select the House");
					  document.frmWebsites.house.focus();
					  return(true);
				}
				
				else if (document.frmWebsites.Centres.options[document.frmWebsites.Centres.options.selectedIndex].value=="0" && document.frmWebsites.websitetype.options[document.frmWebsites.websitetype.options.selectedIndex].value=="2")
				{
					  alert("Please Select the Centre");
					  document.frmWebsites.Centres.focus();
					  return(true);
				}
						
			else if (removespace(document.frmWebsites.chrdomaincode.value)=="")
			   	{
			   		alert("Please enter Domain Code.")
			   		document.frmWebsites.chrdomaincode.focus();
			   		return true;
			   	}
			else if (removespace(document.frmWebsites.chrdomainname.value)=="")
			   	{
			   		alert("Please enter Domain Name.")
			   		document.frmWebsites.chrdomainname.focus();
			   		return true;
			   	}
			else if (removespace(document.frmWebsites.chrdomainalias.value)=="")
			   	{
			   		alert("Please enter Domain Alias.")
			   		document.frmWebsites.chrdomainalias.focus();
			   		return true;
			   	}
			   else
			   {
			   	document.frmWebsites.submit();
			   }	
			
	}
		   		   		   	
}

function choosecentrereg(k)
{
	//alert(k);
	document.frmWebsites.hidhouse.value=k;
	if(namess[k]+""=="undefined") namess[k]=="";
	document.getElementById("layername").innerHTML="<select style='width:200px;' class='txtbox' name=centre onChange='choosenamereg(this.value);'><option value=0 selected>Select Centre</option>"+namess[k]+"</select>";
	choosenamereg(0);
}

function choosenamereg(k)
{	
	document.frmWebsites.hidcmbcentreid.value=k;
	//document.frm.hidtxtusername.value='';
	//document.frm.chruserfullname.value='';
}

// Function for prompt and add state in to database
function AddState() 
{
	var state = prompt("New State", "");
	if(state)
	if(state != "")
	{    	
	    var aTag = document.createElement('a');
	    var ahref = 'AjaxStates.php?function=AddStates&State='+state+'&msg=Success';
	    aTag.setAttribute('href',ahref);   
	    AJAXURLCall(aTag,'States');
	}	
}

// Function for prompt and add city in to database
function AddCity() 
{
	if(document.frm.State.value >0)
	{
		var city = prompt("New City", "");
		if(city)
	    if(city != "")
	    {    	
	        var aTag = document.createElement('a');
	        var ahref = 'AjaxStates.php?function=AddCities&City='+city + '&StateId=' + document.frm.State.value;
	        aTag.setAttribute('href',ahref);   
	        AJAXURLCall(aTag,'Cities');
	    }

	}	
	else
	{
		alert("Please select the state first");
		document.frm.State.focus();
	}
}