
function toggle(div_id) {
	var el = document.getElementById(div_id);
	
	if ( el.style.display == 'none' ) {	
			el.style.display = 'block';
	}
	else {el.style.display = 'none';}
}

function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-150;//150 is half popup's height
	popUpDiv.style.top = popUpDiv_height + 'px';
}
function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-150;//150 is half popup's width
	popUpDiv.style.left = window_width + 'px';
}
function popup(windowname) {
	blanket_size(windowname);
	window_pos(windowname);
	toggle('blanket');
	toggle(windowname);		
}



function firstTimeUser(div_id){
	toggle(div_id)
}



function chkEmails(){
var email = document.signup.emailone.value;
	var email2 = document.signup.mainemailtwo.value;
	
	if(email != email2){
		errMsg ="E-mail and retyped E-mail are the same, please try again. Thank you !";
		alert(errMsg);
		return false;
		
	
    }
	
}



function chkEmails2(){

var Email =document.signup2.emailone.value;
var Email2= document.signup2.mainemailtwo.value;

if(Email != Email2){
		errMsg ="E-mail and retyped E-mail are the same, please try again. Thank you !";
		alert(errMsg);
		return false;
   }
 }

function checkemail(str){
    var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true		

}

function chkSignUpForm(){

	var email = document.signup.emailone.value;
	var email2 = document.signup.mainemailtwo.value;
	var pw= document.signup.pw.value;
		checkemail(email);	
	
	if (pw == ''){
	    alert("Please type in your password. Thank you!");
            return false; 
	}
	
}

function chkSignUpForm2(){
var Email = document.signup2.emailone.value;
	var Email2 = document.signup2.mainemailtwo.value;
	var PW= document.signup2.pw.value;
	checkemail(Email);	
	if(Email2 != 're-type-your-email-here'){
		chkEmails2();
	}
	if (PW == ''){
		alert("Please type in your password. Thank you !");
                return false;
	}

}


function chkCareGiverAD(){
	
	var currnetkids = document.postYourCareGiverAd.currnetkids.value;
	var kidsAgeFrom  = document.postYourCareGiverAd.kidsAgeFrom.value;
	var kidsAgeEnd  =document.postYourCareGiverAd.kidsAgeEnd.value;
	var maxKidNum =document.postYourCareGiverAd.maxKidNum.value;
	
	var ihcEx =document.postYourCareGiverAd.ihcEx.value;
	var openDayFrom =document.postYourCareGiverAd.openDayFrom.value;
	var openDayEnd  =document.postYourCareGiverAd.openDayEnd.value;
	var openHourFrom =document.postYourCareGiverAd.openHourFrom.value;
    var openHourEnd =document.postYourCareGiverAd.openHourEnd.value;
    var fullWeeklyPrice8 =document.postYourCareGiverAd.fullWeeklyPrice8.value;
	var fullWeeklyPrice9  =document.postYourCareGiverAd.fullWeeklyPrice9.value;
	var fullWeeklyPrice10 =document.postYourCareGiverAd.fullWeeklyPrice10.value;
	var fullWeeklyPrice3 =document.postYourCareGiverAd.fullWeeklyPrice3.value;
	var fullWeeklyPrice4 =document.postYourCareGiverAd.fullWeeklyPrice4.value;
	var fullWeeklyPrice5 =document.postYourCareGiverAd.fullWeeklyPrice5.value;
	var dropinPrice =document.postYourCareGiverAd.dropinPrice.value;
	var descs = document.postYourCareGiverAd.descs.value;
    var serviceName= document.postYourCareGiverAd.serviceName.value;
	var ihcpStreet = document.postYourCareGiverAd.ihcpStreet.value;
	var ihcpCity = document.postYourCareGiverAd.ihcpCity.value;
    var ihcpState = document.postYourCareGiverAd.ihcpState.value;
	var ihcpZip = document.postYourCareGiverAd.ihcpZip.value;

	var email = document.postYourCareGiverAd.email.value;
	var contact_name= document.postYourCareGiverAd.contact_name.value;
	var area_code = document.postYourCareGiverAd.area_code.value;
	var phone_number = document.postYourCareGiverAd.phone_number.value;
 
    if(descs =='' || serviceName=='' || ihcpStreet =='' || ihcpCity =='' || ihcpState =='' || contact_name =='' || email ==''){
			alert("All fields are requird");
			return false;
	}
	
	

	var checking=new Array(currnetkids,kidsAgeFrom,kidsAgeEnd,maxKidNum,ihcEx,openDayFrom,openDayEnd,openHourFrom,openHourEnd,fullWeeklyPrice8,fullWeeklyPrice9,fullWeeklyPrice10,fullWeeklyPrice3,fullWeeklyPrice4,fullWeeklyPrice5,dropinPrice,ihcpZip,area_code,phone_number);
		for (counter=0; counter<checking.length; counter++){
			   if(checking[counter]==='' || checking[counter] ===undefined){
			   
				 alert("All fields are required. Thank You");
				 return false;
			   }
			   if(IsNumeric(checking[counter])===false){
					 alert("Make sure you only enter number(s) for the price,kids and zip,phone number fields. Thank You");
					 //alert(checking[counter]);
					 return false;
				}
		}

		if(openDayEnd <= openDayFrom){
			alert("Check your open from field. Start from Monday to Sunday, Make sure you start day is less then end day");
	                return false;
	         }

		
		
	}
	
function chkHourlyRateSearch(str){
	if(IsNumeric(str)===false){
		alert("Make sure you only enter number(s) for houly rate box Thank You");
		 //alert(checking[counter]);
		return false;
	}

}
function chkNannyJobZipSearch(){
    var nannyJobZip = document.searchNannyJob.zip.value;
	var nannyJobState = document.searchNannyJob.state.value;
	if (nannyJobState=='' && nannyJobZip ==''){
		alert("Make sure you select a state or at least have a zip code for your search");
		return false
	}
	if(nannyJobZip !='' && (nannyJobZip.length < 5 || IsNumeric(nannyJobZip)===false)){
		alert("Make sure the zip code is five digits or at leaset select a state");
		return false;
	}
}

function IsNumeric(sText){
//alert(sText);
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++){
		Char = sText.charAt(i);
		
		if ((i == 0) && (Char == "-")) // check first character for minus sign
		continue;
		
		if (ValidChars.indexOf(Char) == -1){
		IsNumber = false;
		}
	}

	return IsNumber;

}


function popitup(url) {
	newwindow=window.open(url,'name','height=250,width=300');

}
function textBlank(x)
{
var y=document.getElementById(x).value;
document.getElementById(x).value='';
}
