var SITE_NAME = '';
//var SITE_NAME = '/concierge';
//var SITE_NAME = '/developments/concierge';


function selectAllCB(objChk,strFormName,strMainId) 
{
	var frm= gGetElementById(strFormName);
	var ele=frm.elements;
	for(var i=0;i<ele.length;i++)
	{
		if(ele[i].type == "checkbox") {

			if(ele[i].id==strMainId) {

				ele[i].checked=objChk.checked;

			}

		}
	}
}
// cross platform equiv. to document.getElementById
function gGetElementById(s) 
{
  var o = (document.getElementById ? document.getElementById(s) : document.all[s]);
  return o == null ? false : o;
}
function getCheckBoxSelectCount(strFormName,strMainId) {



	var frm= gGetElementById(strFormName);

	var ele=frm.elements;

	var cnt=0;

	for(var i=0;i<ele.length;i++)

	{

		if(ele[i].type == "checkbox") {

			if(ele[i].id==strMainId) {

				if(ele[i].checked) {

					cnt=cnt+1;
				}

			}

		}

	}

	return(cnt);
}
function getCheckBoxSelectedValues(strFormName,strMainId) {

	var frm= gGetElementById(strFormName);

	var ele=frm.elements;

	var cnt=0;

	var ans="";

	for(var i=0;i<ele.length;i++)

	{

		if(ele[i].type == "checkbox") {

			if(ele[i].id==strMainId) {

				if(ele[i].checked) {

					if(ans=="") 

						ans=ele[i].value;

					else

						ans=ans + "," + ele[i].value;

				}

			}

		}

	}



	return(ans);

}



function actions(strFormName,strAction,strMainId,objCmb) {

	var ans;

	var actionText;

	var frm= gGetElementById(strFormName);

	var cmbAction;

	var cnt;

	if(objCmb.value!="0" && objCmb.value!="-") {

		ans=getCheckBoxSelectedValues(strFormName,strMainId);

		if(ans != "") {

			var objIds;

			objIds=gGetElementById(strMainId + "s");

			if(objCmb.value.indexOf("*S") > 0){

				cnt=getCheckBoxSelectCount(strFormName,strMainId);

				if(cnt==1) {

					objIds.value=ans;

					frm.submit();

				} else {

					alert("Please Select Single Record.");

					objCmb.value=0;

					return false;

				}

			} else if(objCmb.value.indexOf("*M") > 0){

				objIds.value=ans;

				frm.submit();

			} else {
				actionText=gGetElementById(strAction).options[gGetElementById(strAction).selectedIndex].text;
				if(confirm("Are you sure to perform " + actionText + " Action on selected records ?")) {

					objIds.value=ans;

					frm.submit();

				} else {

					objCmb.value=0;

					return false;

				}

			}

		} else {

			alert("You need to some records.");

			objCmb.value=0;

			return false;

		}

	} else {

		objCmb.value=0;

		return false;

	}

}



function resetAndSubmit(strFormName) {

	var frm= gGetElementById(strFormName);

	var ele=frm.elements;

	for(var i=0;i<ele.length;i++)

	{

		if(ele[i].type == "hidden" || ele[i].type == "text") {

			ele[i].value="";

		} else if(ele[i].type == "select-one") {

			ele[i].options[0].selected=true;

		} else {

			

		}

	}

 	return true;

}



function getFront(mainStr,searchStr){
	
	foundOffset = mainStr.indexOf(searchStr)

	if (foundOffset == -1) {

		return null

	}

	return mainStr.substring(0,foundOffset)

}



// extract back end of string after searchString

function getEnd(mainStr,searchStr) {

	foundOffset = mainStr.indexOf(searchStr)

	if (foundOffset == -1) {

		return null

	}

	return mainStr.substring(foundOffset+searchStr.length,mainStr.length)

}



// insert insertString immediately before searchString

function insertString(mainStr,searchStr,insertStr) {

	var front = getFront(mainStr,searchStr)

	var end = getEnd(mainStr,searchStr)

	if (front != null && end != null) {

		return front + insertStr + searchStr + end

	}

	return null

}



// remove deleteString

function deleteString(mainStr,deleteStr) {

	return replaceString(mainStr,deleteStr,"")

}
// replace searchString with replaceString

function replaceString(mainStr,searchStr,replaceStr) {

	var front = getFront(mainStr,searchStr)

	var end = getEnd(mainStr,searchStr)

	if (front != null && end != null) {

		return front + replaceStr + end

	}

	return null

}

function edCmdImage(strCommand,opType) {

//opType=1 = Enable

//opType=2 = Disable
//	alert(strCommand +':::'+ opType);
	var Img;
	var temp;
	var strReplace;
	var strReplaceBy;
	Img=gGetElementById("cmd"+strCommand);
	temp=Img.src;
	
	if(Img)
	{
		if(getFront(temp,strCommand + "_o.jpg")) 
		{
			strReplace=strCommand + "_o.jpg";
		} else {
			strReplace=strCommand + "_d.jpg";
		}
		if(opType=="1") {
			strReplaceBy=strCommand + "_o.jpg";
		} else {
			strReplaceBy=strCommand + "_d.jpg";
		}
		temp=replaceString(temp,strReplace,strReplaceBy);
		Img.src=temp;
	}
}

function clickCmdImgs(opType,baseURL,strFormName,cbId) {

	var cnt;

	var a;

	switch(opType) {

		case "add":

			a=gGetElementById("addLink"+strFormName);

			window.location=a;

			break;

		case "edit":

			a=gGetElementById("editLink"+strFormName);

			a=a + getCheckBoxSelectedValues(strFormName,cbId);

			cnt=getCheckBoxSelectCount(strFormName,cbId)		

			if(cnt==1) {

				window.location=a;

			}

			break;

		case "delete":

			a=gGetElementById("deleteLink"+strFormName);

			a=a + getCheckBoxSelectedValues(strFormName,cbId);

			cnt=getCheckBoxSelectCount(strFormName,cbId)

			if(cnt>0) {

				window.location=a;

			}

			break;


case "display":
			a=gGetElementById("displayLink"+strFormName);

			a=a + getCheckBoxSelectedValues(strFormName,cbId);

			cnt=getCheckBoxSelectCount(strFormName,cbId)		

			if(cnt==1) {

				window.location=a;

			}

			break;

	}

	return false;

}

function changeCmdImgs(baseURL,strFormName,cbId) {
	
	var cnt;
	cnt=getCheckBoxSelectCount(strFormName,cbId)
	if(cnt==1) 
	{
		edCmdImage("edit",1);
		edCmdImage("display",1);
	} else {
		edCmdImage("edit",0);
		edCmdImage("display",0);
	}


	if(cnt>0) {

		edCmdImage("delete",1);

	} else {

		edCmdImage("delete",0);

	}

}

function setAddOther(strFieldName) {

		var field;

		field=gGetElementById(strFieldName);

		field.value="1";

		return true;

}

function submitDelete(strFormName,cbId) {

var cnt;

var ids;

cnt=getCheckBoxSelectCount(strFormName,cbId);

if(cnt > 0 ) {

	ids=gGetElementById("deleteIds");

	ids.value=getCheckBoxSelectedValues(strFormName,cbId);

	return true;

} else {

	alert("You need to select the Records to Delete.");

	return false;

}

		

}



/*function setUrl(){

	var ele;

	ele=gGetElementById("name");

	ele1=gGetElementById("url");

	ele1.value=ele.value;

//	alert(ele.value);

}*/



function getComboValue(){

		var ele;

		ele=gGetElementById("pa");

		ele1=gGetElementById("spa");

		ele2=gGetElementById("province");

		ele3=gGetElementById("city");

		List=Array();

		List['pa']=ele.value;

		List['spa']=ele1.value;

		List['province']=ele2.value;

		List['city']=ele3.value;

		ele5=gGetElementById("list");

		ele5.value=List['pa']+","+List['spa'];

		return true;

}



function search_term(){

		var ele,val;

		ele=gGetElementById("txtTerm");

		if(ele.value=='e.g. toronto; civil lawyer;'){

			ele.value='';

		}

}

function set_same_value(){

	ele=gGetElementById("txtTerm");

	val=ele.value;

	if(val==''){

		ele.value='e.g. toronto; civil lawyer;';

	}

}



function check_combo_exist(){

	ids=Array();

	ids[0]='city_search';

	ids[1]='spa_search';

	ids[2]='city_search_1';

	ids[3]='spa_search_1';
	
	ids[4]='state_search';
	
	ids[5]='city_search2';
	//ids[6]='city_search_adv';
	ids[7]='province_search_adv';

	for(i=0;i<ids.length;i++){

		ele=gGetElementById(ids[i]);

		if(ele){

			Element.hide(ids[i]);

		}

	}

	return true;

}

function registerSelectPA(objChk,ids,idStr) {

	var tempObj;

	if(ids!="") {

		var myIDs=ids.split(",");

		var i=0;

		while (i < myIDs.length) {

			tempObj=gGetElementById(idStr + myIDs[i]);

			tempObj.checked=objChk.checked;

			i+=1;

		}

	}

}
function checkForPresenceInSelect2(optVal, text, selList) {
 for (i = 0; i < selList.length; i++) {
   if (selList.options[i].value == optVal) return true;
   if (selList.options[i].text == text) return true;
 }
 return false;
}
// Logic for moving a multi-select from element1 to element2
function gGetElementById(s) {
  var o = (document.getElementById ? document.getElementById(s) : document.all[s]);
  return o == null ? false : o;
}

function selectAllOptions(oblCmb)
{
var len = oblCmb.length;
for (var i = 0; i < len; ++i) {
 	 oblCmb.options[i].selected = true;
   }
  return;
}

function one2two(element1, element2) {
 var memberList = gGetElementById(element1);
 var selectedList = gGetElementById(element2);
 var len = memberList.length;

 // Ignore any selections that are made to "------"
 for (var i = 0; i < len; ++i) {
   if (memberList.options[i].selected == true) {
	 memberList.options[i].selected = false;
	 if (memberList.options[i].text == "------") {
	   continue;
	 }
	 
	 if (checkForPresenceInSelect2(memberList.options[i].value, memberList.options[i].text, selectedList) == false) {

	   selectedList.options[selectedList.length] = new Option(memberList.options[i].text, memberList.options[i].value);
	   
	 }
   }
 }
}

// moving a multi-select from element2 to element1.
// Actually this assumes that the values being moved are
// already present in element1 and ends up deleting
// the selected values in element2.
function two2one(element1, element2) {
 var selectedList = gGetElementById(element2);
 for (i = selectedList.length -1; i >= 0; i--) {
   if (selectedList.options[i].selected == true) {
	 selectedList.options[i] = null;
   }
 }
}

function one2twoSingle(element1, element2) {
 var memberList = gGetElementById(element1);
 var selectedList = gGetElementById(element2);
 var len = memberList.length;
 for (var i = 0; i < len; i++) {
    if (memberList.options[i].selected == true) {
		memberList.options[i].selected = false;
	 if (checkForPresenceInSelect2(memberList.options[i].value, memberList.options[i].text, selectedList) == false) {
	   selectedList.options[selectedList.length] = new Option(memberList.options[i].text, memberList.options[i].value);
	 }
	}
 }
}

function two2oneSingle(element1, element2) {
	var selectedList = gGetElementById(element2);
	for (i = selectedList.length -1; i >= 0; i--) {
		if(selectedList.options[i].selected==true) {
			selectedList.options[i].selected=false;
			selectedList.options[i] = null;
		}
	}
}

function setTextarea() {
		ele=gGetElementById('editor_Html Text');
		ele1=gGetElementById('editor_Simple Text');
		simed=gGetElementById('simTextEd1');
		htmed=gGetElementById('htmlTextEd1');
		if(ele.checked){	
			simed.style.display='none';
			htmed.style.display='';
			
			/*document.getElementById('simTextEd').style.display='none';
			document.getElementById('htmlTextEd').style.display='';*/
		}
		else if(ele1.checked){
			htmed.style.display='none';			
			simed.style.display='';
		}
}

function SelectList() {
		
	/*	pro=gGetElementById('SelMovie');
		pList=gGetElementById('ProvinceList');
		pList2=gGetElementById('Province');
		*/
		pro1=gGetElementById('SelType');
		pList1=gGetElementById('TypeList');
		pList21=gGetElementById('Type');
			//pro.style.display='none';
			pro1.style.display='none';
}


function DisplayDivs() {
		ele=gGetElementById('BannerType');
		
		cat=gGetElementById('Category');
		cat1=gGetElementById('Category1');
		city=gGetElementById('City');
		pList=gGetElementById('firstListAdd');
		pList2=gGetElementById('firstAdd');
		cList=gGetElementById('firstListCity');
		cList2=gGetElementById('firstCity');
		if(ele.value=='Advertisement'){
			cat.style.display='';
			city.style.display='';
		}
		else {
			
			cat.style.display='none';
			city.style.display='none';
		}
}

function checkStrLen(txtObj,minLength,MaxLength,msgDisplay)
{
var strData;
strData=txtObj.value;
if(strData.length < Number(minLength))
{
	alert("Please Enter Valid Value In The Following Field : " + msgDisplay);
	txtObj.focus();
	return false;
}
if(strData.length > Number(MaxLength))
{
	alert("Please Enter Value Lesser Than " + MaxLength +" In The Following Field : " + msgDisplay);
	txtObj.focus();
	return false;

}
}
function checkEmail(objTxt) {
	var GoodChars = "@_-.:/ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	var UpperEmail = objTxt.value.toUpperCase()
	var ValidChars = true;
	
	for (tfCharNum = 0; tfCharNum > objTxt.value.length; tfCharNum++) {
		Char = UpperEmail.charAt(tfCharNum);
		for (gcCharNum = 0;  gcCharNum < GoodChars.length;  gcCharNum++) {
				 if (Char == GoodChars.charAt(gcCharNum))
			     break;
		}
				 
		if (gcCharNum == GoodChars.length)   {
		     ValidChars = false;
		     break;
   		}
	}
	
	if (!ValidChars || objTxt.value.length < 7 || 
		objTxt.value.indexOf("@") == "-1" ||
		objTxt.value.indexOf(".") == "-1" || 
		objTxt.value.indexOf("..") != "-1" || 
		objTxt.value.indexOf("@.") != "-1" || 
		objTxt.value.indexOf("@:") != "-1" || 
		objTxt.value.indexOf("@/") != "-1" || 
		objTxt.value.indexOf("@-") != "-1" || 
		objTxt.value.indexOf("@_") != "-1" || 
		objTxt.value.indexOf(".@") != "-1" || 
		objTxt.value.indexOf(":@") != "-1" || 
		objTxt.value.indexOf("/@") != "-1" || 
		objTxt.value.indexOf("-@") != "-1" || 
		objTxt.value.indexOf("_@") != "-1" || 
		objTxt.value.indexOf("@") != objTxt.value.lastIndexOf("@")) {
		objTxt.focus();
			return (false);
	}
	return (true);
}
function validate_frm(){
	var name;
	var email;
name=gGetElementById("name");
email=gGetElementById("email");
if(checkStrLen(name,1,60," Name")==false){
	name.focus();	
	return false;
}

if(!checkEmail(email)){
	email.focus();
	alert("Please Enter Proper Value For Email");
	return false;

}
return;
}
function checkPwds(){
	var password;
	var confirm_password;
password=gGetElementById("password");
confirm_password=gGetElementById("confirm_password");
if(password.value!='' && confirm_password.value!=''){
	if(confirm_password.value!=password.value){
			alert("Passwords do not match");
			password.value='';
			confirm_password.value='';
			password.focus();
			return false;
	}
}	
return;	
}
function togglediv(){//vac home clients
		var r_yes=document.getElementById('vh_yard_y');	
		var r_no=document.getElementById('vh_yard_n');	 
		if(r_yes.checked)
		{
			document.getElementById('div_ysize').style.display='';
		}else{
			document.getElementById('div_ysize').style.display='none';
		}
}
function ValidateService(){//service type validation 
	if(document.getElementById('times').value=="")
	{
		if(document.getElementById('ServiceType').value == 'Monthly')
		{
			alert("Please enter service time.");
			document.getElementById('times').focus();
			return false;		
		}
	}else{
			if(isNaN(document.getElementById('times').value)==true){
				alert("Please enter numeric time.");
				document.getElementById('times').focus();
				return false;		
			}
	}
}
function ValidatePackageService()
{
	var package = document.getElementById('PackageServicePackageId');
	var service = document.getElementById('service_id');	
	var status = document.getElementById('PackageServiceStatus');	
	if(package.value == ""){
		alert("Select package.");
		package.focus();
		return false;			
	}
	if(service.value == ""){
		alert("Services cannot be empty.");
		service.focus();
		return false;			
	}
	if(status.value == ""){
		alert("Select status.");
		status.focus();
		return false;			
	}
}
function ValidateAmountNumeric()
{
	var elem = document.getElementById('frm').elements;		
	//alert(document.getElementById('amount['+']'));
	for(var i = 0; i < elem.length; i++)//elem.length
	{
		var str = elem[i].name;
		if(str.search('amount') == 0)
		{
			if(elem[i].value == 0)
			{
				alert("Please enter amount.");
				elem[i].focus();
				return false;
			}else{
				if(isNumber(elem[i].value,elem[i]) == false){
					return false;
				}
			}
		}
	}
	//return false;
	}
function isNumber(str,name)
{
	numdecs = 0;// not validate it for . only 
	for (i = 0; i < str.length; i++)
	{
		mychar = str.charAt(i);
		if((mychar >= "0" && mychar <= "9") || mychar == "." ){
				if(mychar == ".")
				numdecs++;
		}else{
			alert("Please enter numeric value.");
			name.focus();
			return false;
		}
	}
    if(numdecs > 1){
        alert("please enter valid amount value.");
		name.focus();		
        return false;
    }
    return true;
}
//--------------
//function ValidateAmountCharge(check,s)
function Check(check)
{
	var elem = document.getElementById('frm').elements;		
	var def_amount_no = new Array();
	var j = 0;
	if(check == 'n'){
			for(var i = 0; i < elem.length; i++){
			var str = elem[i].name;
			if(str.search('amount') == 0){//default rate value to amount text box 
				def_amount_no[j] = elem[i].value;
				elem[i].disabled = false;
				j++;
			}
		}
	}
}
function ValidateAmountCharge(check)
{
	var elem = document.getElementById('frm').elements;		
	var j=0;
	var ary = new Array();
	Check(check);
	if(check == 'y'){// get default rate value in array
		for(var i = 0; i < elem.length; i++){//elem.length
			var str = elem[i].name;
			if(str.search('default_rate') == 0){ // everytime looping
				ary[j] = elem[i].value;
				j++;
			}
		}
		j = 0;
		for(var i = 0; i < elem.length; i++){
			var str = elem[i].name;		
			if(str.search('amount') == 0){//default rate value to amount text box 
				elem[i].value = ary[j];
				elem[i].disabled = true;
				j++
			}		
		}
		//---
		if(check == 'y')
		{
			for(var i = 0; i < elem.length; i++){
				var str = elem[i].name;
				if(str.search('default_amount') == 0){//default rate value to amount text box 
					elem[i].value = ary[j];					
					j++
				}
			}
		}
	//---
	}else{		
			if(check == 'n'){
				for(var i = 0; i < elem.length; i++){
				var str = elem[i].name;
				if(str.search('amount') == 0){//default rate value to amount text box 
					//elem[i].value = '0';
					elem[i].disabled = false;
				}
			}
		}
	}
}

function setUrl()
{
	var ele;
	var regExp = /\s+/g;	
	var regExp1 = /&+/g;	
	var aString;

	ele=gGetElementById("name");
	ele1=gGetElementById("url");
	
	aString =ele.value;
	
	aString=aString.toLowerCase();
	aString=aString.replace(regExp1,''); 
	aString=aString.replace(regExp,'_'); 
	
	ele1.value=aString;
}

function fill_billing_address()
{ //mailing address is same as billing address 
	var y = document.getElementById("mail_phy_y");
	var n = document.getElementById("mail_phy_n");	
	if(y.checked == true){
		document.getElementById("AgentMailAddress1").value = document.getElementById("AgentBAddress1").value;
	}
	if(n.checked == true){
		document.getElementById("AgentMailAddress1").value = "";
	}

	//alert(document.getElementById(mail_phy_y).value);
}
function month_selected(val)
{
		// optional service month selected or not
		if(val == 2 || val == 3)
		{
			var exec = document.getElementsByName("chk_optional_id[" + "]");
			var j =0;
			if(exec.length>0)
			{
				for(var i=0;i<exec.length;i++)
				{
					if(exec[i].checked == true)
					{
						j++;
					}
				}
			}
			if(j==0)
			{
				if(val==2){
					alert("Please select optional service");	
				}else if(val ==3){
					alert("Please select calendar optional service");						
				}
				return false;
			}
		}
		
		if(document.getElementById("monthly_val").value == "" ||  document.getElementById("monthly_val").value==0)	
		{
			alert("Please Select Month");
			document.getElementById("monthly_val").focus();	
			return false;
		}
}
function amountchange()
{
		ary = new Array();
		var monthly_val = document.getElementById("monthly_val").value;
		
		var package_id = document.getElementById("PackageId").value;

		var str = monthly_val;
		ary = str.split("_");
		//ary = String.split(monthly_val,"_");		
		var check_ary = new Array();
		var exec = document.getElementsByName("chk_optional_id[" + "]");
		var j =0;
		if(exec.length>0)
		{
			for(var i=0;i<exec.length;i++){
				if(exec[i].checked == true)
				{
					check_ary[j] = exec[i].value;	
					j++;
				}
			}
		}
		document.frmaddservice.action = SITE_NAME+'/clients/optional_services/'+package_id+'/'+ary[0];
		//document.frmaddservice.action = '/clients/optional_services/'+package_id+'/'+ary[0];		
		document.frmaddservice.submit();
		return true;
}
function validatealacarte()
{
		var exec = document.getElementsByName("chk_optional_id[" + "]");
		var j =0;
		if(exec.length>0)
		{
			for(var i=0;i<exec.length;i++)
			{
				if(exec[i].checked == true)
				{
					j++;
				}
			}
		}
		if(j==0)
		{
			alert("Please select alacarte service");	
			return false;
		}//else{
			//document.frmaddservice.submit();
		//}
}
function acceptterm(val)
{
	/*if(val == 'quote')	
	{
		var c = document.getElementById('QuoteTerms');
		var c1 = document.getElementById('QuoteTerms1');		
	}else*/ if(val == 'client'){
		var c = document.getElementById('ClientTerms');
		var c1 = document.getElementById('ClientTerms1');				
	}
	if(c.checked == false)
	{
		alert("Please accept terms & conditions.");
		c.focus();
		return false;
	}else if(c1.checked == false){
		alert("Please accept it.");
		c1.focus();
		return false;
	}{
		if(val == 'client')
		{
			document.frmaddservice.submit();
		}else if(val == 'quote')
		{
			document.frmaddquote.submit();
		}
	}
}
function validate_vachome(str)
{
		if(str == 'estimate')
		{
			 if(document.getElementById('VacationhomesClientPhyAddress1').value!='' 
			 && document.getElementById('city').value!=''
			 && document.getElementById('VacationhomesClientProvinceId').value!=''
			 && document.getElementById('zipcode').value!=''
			 && document.getElementById('vh_size').value!='')
			 {
				 document.getElementById('VacationhomesClientCheckEstimate').value = 1;	 
			 }else{
				window.location.href = SITE_NAME+'/vacationhomes_clients/vachome/';
				//window.location.href = '/Concierge_4_4_09_qry_chnge/vacationhomes_clients/vachome/';				
				//window.location.href = '/vacationhomes_clients/vachome/';				
			 }
				document.forms[0].submit();
		}else if(str == 'vachome'){
				if(document.getElementById('VacationhomesClientPhyAddress1').value!='' 
				 && document.getElementById('city').value!=''
				 && document.getElementById('VacationhomesClientProvinceId').value!=''
				 && document.getElementById('zipcode').value!=''
				 && document.getElementById('vh_size').value!='')
				{ // it's all for redirect page
					 document.getElementById('VacationhomesClientCheckEstimate').value = 2;	 
					  document.getElementById('VacationhomesClientCheckAdditionalhelp').value = 2;	 
				}
		}else if(str == 'additional_help'){
			 if(document.getElementById('VacationhomesClientPhyAddress1').value!='' 
			 && document.getElementById('city').value!=''
			 && document.getElementById('VacationhomesClientProvinceId').value!=''
			 && document.getElementById('zipcode').value!=''
			 && document.getElementById('vh_size').value!='')
			 {
				 document.getElementById('VacationhomesClientCheckAdditionalhelp').value = 1;	 
			 }else{
				//window.location.href = '/Concierge_4_4_09_qry_chnge/vacationhomes_clients/vachome/';
				//window.location.href = '/vacationhomes_clients/vachome/';				
				window.location.href = SITE_NAME+'/vacationhomes_clients/vachome/';
			 }
				document.forms[0].submit();
		}
}
function validate_estimate_tool1(){
	var home_size = document.getElementById('VacationhomesClientHomeSize').value;
	if((document.getElementById('vh_yard_size_dx').value=='' && document.getElementById('vh_yard_size_dy').value!='')){
		alert("Please enter  yard size dimensions");
		document.getElementById("vh_yard_size_dx").focus();
		return false;
	}
	if((document.getElementById('vh_yard_size_dy').value=='' && document.getElementById('vh_yard_size_dx').value!='')){
		alert("Please enter  yard size dimensions");
		document.getElementById("vh_yard_size_dy").focus();
		return false;
	}
	if((document.getElementById('vh_lot_size_x').value=='' && document.getElementById('vh_lot_size_y').value!=''))	{
		alert("Please enter numeric lot dimensions");
		document.getElementById("vh_lot_size_x").focus();
		return false;
	}
	if((document.getElementById('vh_lot_size_x').value!='' && document.getElementById('vh_lot_size_y').value==''))	{
		alert("Please enter numeric lot dimensions");
		document.getElementById("vh_lot_size_y").focus();
		return false;
	}
//-------
	if(isNaN(document.getElementById('vh_yard_size_dx').value) ==true){
		alert("Please enter  numeric yard size dimensions");
		document.getElementById("vh_yard_size_dx").focus();
		return false;
	}else if(isNaN(document.getElementById('vh_yard_size_dy').value) == true){
		alert("Please enter  numeric yard size dimensions");
		document.getElementById("vh_yard_size_dy").focus();
		return false;
	}
//-------
	if(isNaN(document.getElementById('vh_lot_size_x').value) ==true){
		alert("Please enter numeric lot dimensions");
		document.getElementById("vh_lot_size_x").focus();
		return false;
	}else if(isNaN(document.getElementById('vh_lot_size_y').value) == true){
		alert("Please enter numeric lot dimensions");
		document.getElementById("vh_lot_size_y").focus();
		return false;
	}else if(isNaN(document.getElementById('in_acre').value) == true){
		alert("Please enter numeric lot value");
		document.getElementById("in_acre").focus();
		return false;
	}
	if(document.getElementById('vh_yard_size_dx').value!='' && document.getElementById('vh_yard_size_dy').value!=''){
			var size_xy = document.getElementById('vh_yard_size_dx').value * document.getElementById('vh_yard_size_dy').value;
			
	}
	if(document.getElementById('vh_lot_size_x').value!='' && document.getElementById('vh_lot_size_y').value!=''){
			var size_xy = document.getElementById('vh_lot_size_x').value * document.getElementById('vh_lot_size_y').value;
			
	}
	/*if(document.getElementById('in_acre').value!=''){
		var size = 43560 * document.getElementById('in_acre').value;
	}*/
	if(size_xy < home_size){
				alert("Please enter  valid dimensions.");
				return false;
	}
}
function validate_estimate_tool(form_name,val2){
		if(val2 == 'estimate'){
			var home_size = document.getElementById('VacationhomesClientHomeSize').value;			
		}else if(val2 == 'add_vachome'){
			var home_size = document.getElementById('vh_size').value;			
		}
		var elem = document.getElementById(form_name.id).elements;	
		var num = 0;
		for(var i=0;i<elem.length;i++){//elem.length
			var str = elem[i].name;
			if(elem[i].value == 'yard_size_xy'){
				if(elem[i].checked == true){
					var num = 1;
				}
			}else if(elem[i].value == 'lot_size_xy'){
				if(elem[i].checked == true){
					var num = 2;
				}
			}else if(elem[i].value == 'in_acre'){
				if(elem[i].checked == true){
					 	var num = 3;
				}
			}
		}
		if(num == 1){
			if((document.getElementById('vh_yard_size_dx').value=='' && document.getElementById('vh_yard_size_dy').value!='')){
				alert("Please enter  yard size dimensions");
				document.getElementById("vh_yard_size_dx").focus();
				return false;
			}
			if((document.getElementById('vh_yard_size_dy').value=='' && document.getElementById('vh_yard_size_dx').value!='')){
				alert("Please enter  yard size dimensions");
				document.getElementById("vh_yard_size_dy").focus();
				return false;
			}
			if(isNaN(document.getElementById('vh_yard_size_dx').value) ==true){
				alert("Please enter  numeric yard size dimensions");
				document.getElementById("vh_yard_size_dx").focus();
				return false;
			}else if(isNaN(document.getElementById('vh_yard_size_dy').value) == true){
				alert("Please enter  numeric yard size dimensions");
				document.getElementById("vh_yard_size_dy").focus();
				return false;
			}
			if(document.getElementById('vh_yard_size_dx').value!='' && document.getElementById('vh_yard_size_dy').value!=''){
				var size_xy = document.getElementById('vh_yard_size_dx').value * document.getElementById('vh_yard_size_dy').value;
			}
			if(size_xy < home_size){
						alert("home size is less than given dimension.");
						document.getElementById("vh_yard_size_dy").focus();
						return false;
			}			
		}
		else if(num == 2){
			if((document.getElementById('vh_lot_size_x').value=='' && document.getElementById('vh_lot_size_y').value!=''))	{
				alert("Please enter numeric lot dimensions");
				document.getElementById("vh_lot_size_x").focus();
				return false;
			}
			if((document.getElementById('vh_lot_size_x').value!='' && document.getElementById('vh_lot_size_y').value==''))	{
				alert("Please enter numeric lot dimensions");
				document.getElementById("vh_lot_size_y").focus();
				return false;
			}
			if(isNaN(document.getElementById('vh_lot_size_x').value) ==true){
				alert("Please enter numeric lot dimensions");
				document.getElementById("vh_lot_size_x").focus();
				return false;
			}else if(isNaN(document.getElementById('vh_lot_size_y').value) == true){
				alert("Please enter numeric lot dimensions");
				document.getElementById("vh_lot_size_y").focus();
				return false;
			}	
			if(document.getElementById('vh_lot_size_x').value!='' && document.getElementById('vh_lot_size_y').value!=''){
					var size_xy = document.getElementById('vh_lot_size_x').value * document.getElementById('vh_lot_size_y').value;
					
			}
			if(size_xy < home_size)
			{
					alert("home size is less than given dimension.");
					document.getElementById("vh_lot_size_y").focus();
					return false;
			}			
		}
		else if(num == 3){
				if(document.getElementById('in_acre').value !=''){
					 if(isNaN(document.getElementById('in_acre').value) == true){
						alert("Please enter numeric lot value");
						document.getElementById("in_acre").focus();
						return false;
					}
				}
		}
		//return false;
}

function printit()
{ //print document
  var disp_setting="toolbar=no,location=no,directories=no,menubar=no,"; 
  disp_setting+="scrollbars=no,width=650, height=600, left=100, top=25"; 
 /*
  var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
  disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25";*/
  
  var content_vlue = document.getElementById("print_content").innerHTML; 
  var docprint=window.open("","",disp_setting,true); 
   docprint.document.open(); 
   docprint.document.write('<html><head>'); 
   docprint.document.write('</head><body onLoad="self.print()"><center>');          
   docprint.document.write(content_vlue);          
   docprint.document.write('</center></body></html>'); 
   docprint.document.close(); 
   docprint.focus(); 
}
function CheckValidEmail()
{
	var email;
	email=document.getElementById("ClientEmail1");
	if(!checkEmail(email))
	{
		email.focus();
		alert("Please enter valid email.");
		return false;
	}
return;
}
function SelectList(val)
{
	ele=gGetElementById('refer_friend');
	cat=gGetElementById('ReferFriend');
	if(val == 1)
	{
		cat.style.display='none';		
	}else if(val == 2)
	{
		cat.style.display='';
		return false;
	}
}
function ValidReferFriend()
{
	var email;
	var name;
	name = document.getElementById("name");
	if(name.value == "")
	{
		alert("Please enter name.");
		name.focus();
		return false;
	}
	email=document.getElementById("email");
	if(!checkEmail(email))
	{
		alert("Please enter valid email.");
		email.focus();
		return false;
	}
}
function CheckApplyCoupon(){
	var val= gGetElementById("coupon_code");
	if(val.value == '')	
	{
		alert("Please enter coupon code.");
		val.focus();
		return false;
	}
}
function validatecompany()
{
		cmp=gGetElementById('CompanyCompanyName');
		if(cmp.value == '')
		{
			alert("Please enter company name.");
			cmp.focus();
			return false;
		}
		reg_legal=gGetElementById('CompanyRegLegalName');
		if(reg_legal.value == '')
		{
			alert("Please enter registered legal name.");
			reg_legal.focus();
			return false;
		}
		no_emp=gGetElementById('CompanyNoOfEmp');
		if(no_emp.value == 0)
		{
			alert("Please select no of employee.");
			no_emp.focus();
			return false;
		}
		email=gGetElementById('CompanyBusinessEmail');
		if(email.value == 0)
		{
			alert("Please enter email.");
			email.focus();
			return false;
		}else if(!checkEmail(email))
		{
			alert("Please enter valid email.");
			email.focus();
			return false;
		}
		fname=gGetElementById('CompanyFirstName');
		if(fname.value == "")
		{
			alert("Please enter first name.");
			fname.focus();
			return false;
		}
		lname=gGetElementById('CompanyLastName');
		if(lname.value == "")
		{
			alert("Please enter last name.");
			lname.focus();
			return false;
		}
		address1=gGetElementById('CompanyAddress1');
		if(address1.value == "")
		{
			alert("Please enter address.");
			address1.focus();
			return false;
		}
}
//-------------------------- calender
function tdmv(aItem)
{
	aItem.style.backgroundColor = '#fff';
}

function tdmu(aItem)
{
	aItem.style.backgroundColor = '#fafaf8';
}

function tdtmo(aItem)
{
	aItem.style.backgroundColor = '#fafaf8';	
}

function ensureRefresh()
{
	document.calendarPage.day.value = "";
	document.calendarPage.view.value = "calendar";
	document.calendarPage.submit();
}

function sendDay(schedDay, schedMonth, schedYear)
{
	document.calendarPage.day.value = schedDay;
	document.calendarPage.month.value = schedMonth;
	document.calendarPage.year.value = schedYear;
	document.calendarPage.view.value = "schedule";
	document.calendarPage.submit();
}
function event_add(str)
{
		if(str == 'edit')
		{
			desc=gGetElementById('ClientDescription');
			if(desc.value == '')
			{
				alert('Please enter description');
				desc.focus();	
				return false;
			}
		}else if(str == 'add'){
			desc=gGetElementById('ClientDescription');
			if(desc.value == '')
			{
				alert('Please enter description');
				desc.focus();	
				return false;
			}
			no_of_days=gGetElementById('no_of_days');
			if(no_of_days.value == '')
			{
				alert('Please enter no of days');
				no_of_days.focus();	
				return false;			
			}else if(isNaN(no_of_days.value) == true){
				alert('Please enter numeric no of days');
				no_of_days.focus();	
				return false;			
			}
			persons=gGetElementById('persons');
			if(persons.value == '')
			{
				alert('Please enter no of persons');
				persons.focus();	
				return false;			
			}else if(isNaN(persons.value) == true){
				alert('Please enter numeric no of persons');
				persons.focus();	
				return false;			
			}	
		}
		
		//opener.location.reload(true);
		//self.close();
		//window.parent.reload();		
		//window.close();
}
function popitup(url) 
{
	newwindow=window.open(url,'name','height=300,width=500,menubar=no');
	//newwindow=window.open(url,'name');	
	if (window.focus) {newwindow.focus()}
	return false;
}
function DeleteEvent($url)
{
	n = window.open($url,"","width=300,height=150,resizable=no,status=no,scrollbars =no,menubar=no");
	if (window.focus){
		n.focus();
	}return false;
}
function del_event()
{
	//opener.location.reload(true);
	//self.close();
}
function refresh_month_year(){
	var month = gGetElementById('ClientMonth');
	var year = gGetElementById('ClientYear');	
	if(month.value == 0 && year.value ==0)
	{
		alert('Please select month or year.');
		month.focus();	
		return false;
	}
}
//********** added on 6-3-09
function SelectYardSizeList(){
		
	var size_xy=gGetElementById("radio_yard_size_xy");
	
	var lot_size_xy=gGetElementById('radio_lot_size_xy');
	var lot_value_in_acre=gGetElementById('radio_lot_value_in_acre');
	var in_acre=gGetElementById('radio_in_acre');
	var yard_text=gGetElementById('radio_yard_text');
	
		var size_xy_div=gGetElementById('size_xy');
		var lot_xy_div=gGetElementById('lot_xy'); 
		var lot_value_acre_div=gGetElementById('lot_value_acre');		
		var in_acre_div=gGetElementById('in_acre_div');				
		var yard_size_div=gGetElementById('yard_size_without_div');						
		
	if(size_xy.checked == true){
			size_xy_div.style.display='';
			lot_xy_div.style.display='none';
			lot_value_acre_div.style.display='none';
			in_acre_div.style.display='none';			
			yard_size_div.style.display='none';						
	}else if (lot_size_xy.checked == true){
			size_xy_div.style.display='none';
			lot_xy_div.style.display='';
			lot_value_acre_div.style.display='none';
			in_acre_div.style.display='none';			
			yard_size_div.style.display='none';									
	}else if (lot_value_in_acre.checked == true){
			size_xy_div.style.display='none';
			lot_xy_div.style.display='none';
			lot_value_acre_div.style.display='';
			in_acre_div.style.display='none';			
			yard_size_div.style.display='none';									
	}else if (in_acre.checked == true){
			size_xy_div.style.display='none';
			lot_xy_div.style.display='none';
			lot_value_acre_div.style.display='none';
			in_acre_div.style.display='';
			yard_size_div.style.display='none';									
	}else if(yard_text.checked == true){
			size_xy_div.style.display='none';
			lot_xy_div.style.display='none';
			lot_value_acre_div.style.display='none';
			in_acre_div.style.display='none';
			yard_size_div.style.display='';									
	}else{
			size_xy_div.style.display='none';
			lot_xy_div.style.display='none';
			lot_value_acre_div.style.display='none';
			in_acre_div.style.display='none';			
	}
}
//**********
function amountchange_no_agent()
{	
		var monthly_val = document.getElementById("monthly_val").value;
		var package_id = document.getElementById("PackageId").value;
		var str = monthly_val;
		ary = str.split("_");
		//document.frmaddservice.action = '/clients/no_agent_package/'+package_id+'/'+ary[0];
		//document.frmaddservice.action = '/Concierge_4_4_09_qry_chnge/clients/no_agent_package/'+package_id+'/'+ary[0];
		//document.frmaddservice.action = '/concierge/clients/no_agent_package/'+package_id+'/'+ary[0];				
		document.frmaddservice.action = SITE_NAME+'/clients/no_agent_package/'+package_id+'/'+ary[0];		
		document.frmaddservice.submit();
		return true;
}
function checkEmpty(frm){
	
	if (frm.username.value == "" || frm.password.value == "")
	{
		alert("Please enter username & password.");
		frm.username.focus();
		return false;
	}
	return true;
}
function checkall(thestate)
{
	// in email grabber
	
	var frm= gGetElementById('email_grabber_display');
	var ele=frm.elements;
	for(var i=0;i<ele.length;i++){ 
			if(ele[i].type == "checkbox"){
				if(ele[i].id=="ClientChk"){
					ele[i].checked=thestate;
				}
		}
	}
}
// added on 17-6-09
	function check_step_1()
	{
		var no_of_bedrooms= gGetElementById('VacationhomesClientIsNoOfBedrooms');
		var no_of_beds= gGetElementById('VacationhomesClientIsNoOfBeds');		
		var no_of_bathrooms= gGetElementById('VacationhomesClientIsNoOfBathrooms');		
		var squre_feet= gGetElementById('VacationhomesClientIsSqureFeet');		
		
		
		if(no_of_bedrooms.value <= 0 || no_of_bedrooms.value == ''){
			alert('Enter no of bedrooms.');
			no_of_bedrooms.focus();
			return false;
		}else if(isNaN(no_of_bedrooms.value) == true){
			alert('Enter numeric value for no of bedrooms.');
			no_of_bedrooms.focus();
			return false;
		}
		if(no_of_beds.value <= 0 || no_of_beds.value == '')
		{
			alert('Enter no of beds.');
			no_of_beds.focus();
			return false;
		}else if(isNaN(no_of_beds.value) == true){
			alert('Enter numeric value for no of beds.');
			no_of_beds.focus();
			return false;
		}
		if(isNaN(no_of_bathrooms.value) == true){
			alert('Enter numeric value for no of bathrooms.');
			no_of_bathrooms.focus();
			return false;
		}
		if(squre_feet.value!='')
		{
			//return price_validation(squre_feet);
		}
	}
	function RedirectPathRentalstep5(type,client_id)
	{
		//to redirect from rental step 5 to rental step 6
		if(type == 'admin')
		{
			window.location = SITE_NAME+"/vacationhomes_clients/rental_step_6/"+client_id; 		
			return false;
		}else{
			window.location = SITE_NAME+"/vacationhomes_clients/rental_step_6/"; 		
		}
	}
	/* rental step 3 validation */
	function rental_step_3_validation()
	{
		var radios = document.getElementsByName('data[VacationhomesClient][guest_reserved_type]');
		
		var radios_share_all = document.getElementsByName('data[VacationhomesClient][share_all]');		
		var share_month = gGetElementById('VacationhomesClientShareUnoccupiedDateUptoMonth');
		var share_period = gGetElementById('VacationhomesClientShareOnePeriodDay');		
		
		for(var i=0;i<radios_share_all.length;i++)
		{
			var chk = false;
			if(radios_share_all[i].checked == true)
			{
				chk = true;
				break;
			}
		}
		if(chk == false)
		{
			alert('Select atleast one option for sharing rules');
			
			return false;
		}
		else if(radios_share_all[1].checked == true && radios_share_all[1].value == 'unoccupied_date_upto'){
				if(share_month.value == '')
				{
					alert('Select vacation home unoccupied dates upto');
					share_month.focus();
					return false;
				}
				
		}else if(radios_share_all[2].checked == true && radios_share_all[2].value == 'one_period'){
				if(share_period.value == '')
				{
					alert('Select length of period');
					share_period.focus();
					return false;
				}			
		}
		
		if(radios[0].checked == false && radios[1].checked == false)
		{
			alert('Select atleast one option for calendar rules');
			return false;
		}
		
		var escrow= gGetElementById('VacationhomesClientRentalEscrow');
		var notification= gGetElementById('VacationhomesClientRentalNotification');		
		var refund_policy= gGetElementById('VacationhomesClientRentalRefundPolicy');				
		
		if(escrow.value == ''){
			alert('Select escrow type');
			escrow.focus();
			return false;
		}else if(escrow.value == 'other'){
			var escrow_other = gGetElementById('VacationhomesClientOtherEscrow');						
			//******* check for numeric ,blank and rage between 1 to 100
			txt = escrow_other;
			if(txt.value == '' || txt.value == 0)
			{
				alert('Other field cannot be blank');
				txt.focus();
				return false;
			}else if(isNaN(txt.value) == true){
				alert('Enter numeric value in other text field');
				txt.focus();
				return false;
			}else{
					if(txt.value <1 || txt.value >100){
						alert('Other Value should be in between 1 to 100');
						txt.focus();
						return false;
					}
			}
			//*******			
			//return other_txt_validation(1,escrow_other);	
		}
		
		if(notification.value == '')
		{
			alert('Select notification type');
			notification.focus();
			return false;
		}else if(notification.value == 'other'){
				var notification_other = gGetElementById('VacationhomesClientOtherNotification');						
				//******* check for numeric ,blank and rage between 1 to 100
				txt = notification_other;
				if(txt.value == '' || txt.value == 0)
				{
					alert('Other field cannot be blank');
					txt.focus();
					return false;
				}else if(isNaN(txt.value) == true){
					alert('Enter numeric value in other text field');
					txt.focus();
					return false;
				}else{
					if(txt.value <1 || txt.value >31){
						alert('Other Value should be in between 1 to 31');
						txt.focus();
						return false;
					}
			}
				//*******			
				//return other_txt_validation(2,notification_other);	
		}
	
		if(refund_policy.value == '')
		{
			alert('Select refund type');
			refund_policy.focus();
			return false;
		}else if(refund_policy.value == 'other'){

				var refund_other = gGetElementById('VacationhomesClientOtherRefund');						
				//******* check for numeric ,blank and rage between 1 to 100
				txt = refund_other;
				if(txt.value == '' || txt.value == 0)
				{
					alert('Other field cannot be blank');
					txt.focus();
					return false;
				}else if(isNaN(txt.value) == true){
					alert('Enter numeric value in other text field');
					txt.focus();
					return false;
				}else{
					if(txt.value <1 || txt.value >100){
						alert('Other Value should be in between 1 to 100');
						txt.focus();
						return false;
					}
			}
				//*******							
				//return other_txt_validation(1,refund_other);	
		}	
	}
	
	/*function other_txt_validation(type,txt)
	{
			if(txt.value == '' || txt.value == 0)
			{
				alert('Other field cannot be blank');
				txt.focus();
				return false;
			}else if(isNaN(txt.value) == true){
				alert('Enter numeric value in other text field');
				txt.focus();
				return false;
			}else{
				if(type == 1)
				{
					if(txt.value <= 1 || txt.value >100)
					{
						alert('Other Value should be in between 1 to 100');
						txt.focus();
						return false;
					}else{
						return true;
					}
				}
				if(type == 2)
				{
					if(txt.value <= 1 || txt.value >31){
					alert('Other Value should be in between 1 to 31');
					txt.focus();
					return false;
				}
				}
			}
	}*/
	function displayothertext(val)
	{
		if(val == 1){
			var div_escrow=gGetElementById('div_other_escrow');
			var txt_escrow = gGetElementById('VacationhomesClientRentalEscrow');
			 dispalyothertext_check(txt_escrow,div_escrow);
		}
		if(val == 2){
			var div_notification=gGetElementById('div_other_notification');
			var txt_notification = gGetElementById('VacationhomesClientRentalNotification');
			 dispalyothertext_check(txt_notification,div_notification);
		}
		if(val == 3){
			var div_refund=gGetElementById('div_other_refund');
			var txt_refund = gGetElementById('VacationhomesClientRentalRefundPolicy');
			 dispalyothertext_check(txt_refund,div_refund);			
		}
	}
	function dispalyothertext_check(txt,div)
	{
		txt_1 = txt;
		div_1 = div;
		if(txt_1.value == 'other')
		{
			div_1.style.display='';
		}else{
			div_1.style.display='none';
		}	
	}
	
	function confirm_del()
	{
		if(!window.confirm("Do you Really Want To Delete Record?"))
		{
			return false;
		}else{
			return true;
		}	
	}	
	function rental_step_6_valid()
	{
		var nightly=gGetElementById('VacationhomesClientMinNightly');
		var weekly=gGetElementById('VacationhomesClientMinWeekly');
		var monthly=gGetElementById('VacationhomesClientMinMonthly');		
		
		if(nightly.value != '')
		{
			if(isNaN(nightly.value) == true)
			{
				alert('Enter numeric value for min nightly ');	
				nightly.focus();
				return false;
			}
		}
		if(weekly.value != '')
		{
			if(isNaN(weekly.value) == true)
			{
				alert('Enter numeric value for min weekly ');	
				nightly.focus();
				return false;
			}
		}
		if(monthly.value != '')
		{
			if(isNaN(monthly.value) == true)
			{
				alert('Enter numeric value for min monthly');	
				monthly.focus();
				return false;
			}
		}
		
	}
	/* rental step 3 validation */	