/**
 * @author Kitinfinet.com
 */


function popUpWindow01(URL,win,width,height) {
	wd=window.screen.width;
	ht=window.screen.height;
	top1=Math.ceil((ht-height)/2);
	left1=Math.ceil((wd-width)/2);
	window.open(URL,win,"width="+width+",height="+height+",top="+top1+",left="+left1+",scrollbars=yes");
}


function popUpWindow(URL,win,width,height) {
	wd=window.screen.width;
	ht=window.screen.height;
	top1=Math.ceil((ht-height)/2);
	left1=Math.ceil((wd-width)/2);
	window.open(URL,win,"width="+width+",height="+height+",top="+top1+",left="+left1+",scrollbars=yes");
}




function trimStr(sString) {
//	alert(sString);
	while (sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function IsNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++){ 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1){
         IsNumber = false;
      }
   }
   return IsNumber;
}

function IsPhone(sText){
   var ValidChars = "0123456789.-";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++){ 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1){
         IsNumber = false;
      }
   }
   return IsNumber;
}


function check_date(dateStr){
 	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		alert("Date is not in a valid format.");
		return false;
	}
	year = matchArray[4]; // parse date into variables
	month = matchArray[3];
	day = matchArray[1];
/*	if(day.length!=2){
		alert("Accepted Day Format is : DD. Ex: 05");
		return false;		
	}
	if(month.length!=2){
		alert("Accepted Month Format is : MM. Ex: 08");
		return false;		
	}		
	if(year.length!=4){
		alert("Accepted Year Format is : YYYY. Ex: 2004");
		return false;		
	}*/
//	alert(year + ":" + month +":" +day);
	if (month < 1 || month > 12) { // check month range
		alert("Month must be between 1 and 12.");
		return false;
	}
	if (day < 1 || day > 31) {
		alert("Day must be between 1 and 31.");
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Month "+month+" doesn't have 31 days!")
		return false
	}
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
			alert("February " + year + " doesn't have " + day + " days!");
			return false;
   		}
   	}
	var myDate=new Date();
	myDate.setFullYear(year,month-1,day);
	var today = new Date();
	if (myDate>today){
		alert("Can not enter a future date in Date of Birth");
		return false;
	}
}
//check if the date difference is more tahn 18 Years
function checkfor18(chkDate){
 	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	var matchArray = chkDate.match(datePat); // is the format ok?
	alert(matchArray.length);
	year = matchArray[1]; // parse date into variables
	month = matchArray[3];
	day = matchArray[4];	
	var myDate=new Date();
	myDate.setFullYear(year,month-1,day);	
	var currDate = new Date();
	var currMSec = Date.parse(currDate);
	var myDateMSec = Date.parse(myDate);
	//value of 18 years in millisec
	var mSec18Yers = Date.parse("Jan 1, 1988");
	if((currMSec-myDateMSec)>=mSec18Yers){
		return true;
	}
	else{
		return false;
	}
}

function checkAge(chkDate,dateInt,dtType){
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	var matchArray = chkDate.match(datePat); // is the format ok?
	year   = parseInt(matchArray[4]); // parse date into variables
	month   = parseInt(matchArray[3]);
	day   = parseInt(matchArray[1]);	

	var limitDtArray = dateInt.match(datePat);
	//Get the year , month and day in different array
	limitDay  =parseInt(limitDtArray[1]);
	limitMonth  = parseInt(limitDtArray[3]);
	limitYear  = parseInt(limitDtArray[4]);
if(dtType==13){
	//alert(month);
	if((limitYear-year)>3){
		return true;
	}
	else if((limitYear-year)<3){
		return false;
	}
	else{
		if(month < limitMonth){
			//alert(month);
			//alert(limitMonth);
			return true;		
		}
		else if((month==limitMonth)&&(limitDay>=day)){
			//alert("month1");
			return true;
		}
		else{
			//alert("month2");
			return false;
		}
	
	}
}else if(dtType==14){
	
	if((limitYear-year)>4){
		return true;
	}
	else if((limitYear-year)<4){
		return false;
	}
	else{
		if(month < limitMonth){
			return true;		
		}
		else if((month==limitMonth)&&(limitDay>=day)){
			//alert ("hi");
			return true;
		}
		else{
			return false;
			//alert ("hii");
		}
	
	}
	
}else{
	
	if((limitYear-year)>5){
		return true;
	}
	else if((limitYear-year)<5){
		return false;
	}
	else{
		if(month < limitMonth){
			return true;		
		}
		else if((month==limitMonth)&&(limitDay>=day)){
			//alert ("hi");
			return true;
		}
		else{
			return false;
			//alert ("hii");
		}
	
	}
	
}
}
//check if the email is a valid email address
function checkMail(x){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else return false;
}

function regType(str,str2){
	if(str=="x"){
		document.form1.action="regCompleted.php?msg=Free User";
		document.form1.submit();
	}
	else if(str=="i"){
		if(str2=='IN'){
			document.form1.action="regPlanISubType.php";
			document.form1.submit();		
		}
		else{
			document.form1.action="regPlanSubType.php";
			document.form1.submit();	
		}
	}
	else if(str=="promo"){
		document.form1.action="setPromo.php";
		document.form1.submit();
	}
}


function disclamer(){
	if(document.form1.b_agree.checked==false){
		alert("We regret!! You would not be able to register with us if you do not agree to our terms and condition");
		return false;
	}
}



function hidediv(divid) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(divid).style.visibility = 'hidden';
	}
	else {
		if (document.layers) { // Netscape 4
			document.divid.visibility = 'hidden';
		}
		else { // IE 4
			document.all.divid.style.visibility = 'hidden';
		}
	}
}

function showdiv(divid) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(divid).style.visibility = 'visible';
	}
	else {
		if (document.layers) { // Netscape 4
			document.divid.visibility = 'visible';
		}
		else { // IE 4
			document.all.divid.style.visibility = 'visible';
		}
	}
}
//Hide all the div when he page loades
function hideFields(){
//	hidediv("id_pg_sub_o");
//	hidediv("id_physical");
//id_pg_exampassed
//id_pg_exam
//id_phd_exam
fillYear();
}

function showCode(field_id){
	var code=eval("document.form1."+field_id).value;
	var tmpvar=field_id+"_div";
	if(code=="0"){
		document.getElementById(tmpvar).innerHTML="";
	}
	else{
		document.getElementById(tmpvar).innerHTML="Code:"+code;
	}
}


function showPGSubject(){
	var divid=document.getElementById("id_pg_exampassed");
	var field_val=document.form1.exam_passed.value;
	if(field_val=="1978"){
		divid.style.visibility="visible";
	}
	else{
		divid.style.visibility="hidden";
	}
}

function showPGUniversity(){
	var divid=document.getElementById("id_pg_exam");
	var field_val=document.form1.pg_unversity.value;
	if(field_val=="1978"){
		divid.style.visibility="visible";
	}
	else{
		divid.style.visibility="hidden";
	}
}
