//The following variables are set to the TIDs of their respective campaigns// Defined here because these should be updated depending on DEV or LIVE status.var loginFlow = 164;var memberBrokerFlow = 165;var zipFlow = 166;function getOffices(type){	var agentOfficeZip = $("#agentOfficeZip").val();	var propertyZip = $("#zipCode").val();		$("#officesList").html("");		$("#officesList").hide();	if(!IsNumeric(agentOfficeZip)){			alert("Numeric Values Only");			$("#agentOfficeZip").val("");	}else{		if(agentOfficeZip.length == 5){			$("#ziplookupError").hide();			$("#ziplookupError").html("");			$.post("ziplookup/officeList.lasso", { 					zip: agentOfficeZip,					type: type				},				function(html){					if(html.length){						$("#officesList").html(html);						$("#officesList").show();						$("#ccmIDLIST").focus();						if(propertyZip){							$("#ziplookupRowMain").css("height", "350px");						}else{							$("#ziplookupRowMain").css("height", "310px");						}					}else{						$("#officesList").html("<span class='ziplookupErMsg'>No offices were found for that zip code</span><INPUT TYPE='HIDDEN' NAME='ccmID' VALUE='0'>");						$("#officesList").show();					}			});		}	} // end check for numeric values}function checkMemberBroker(){	var go = "Y";	$("#ziplookupError").hide();	$("#ziplookupError").html("");	var ccmid = $("#ccmIDbox").val();	var propertyZip = document.memberBrokerNumber.zipCode.value;	if(ccmid.length < 3){		$("#ziplookupError").show();		$("#ziplookupError").html("You must provide your Member Broker Number");		go = "N";	}		if(propertyZip.length < 1){		$("#ziplookupError").show();		$("#ziplookupError").html("You must provide your property zip code");		go = "N";	}		if(go == "Y"){		$("#memberBrokerSubmit").val("Processing");		$("#memberBrokerSubmit").attr("disabled", "true");		officeInfo(propertyZip,ccmid);		addClick(memberBrokerFlow);	}		return false;}function checkZipLookup(){	var go = "Y";	$("#ziplookupError").hide();	$("#ziplookupError").html("");	var officeZip = document.zipLookup.agentOfficeZip.value;		//var ccmid = document.zipLookup.ccmID.value;	var ccmid = $("#ccmIDLIST").val();	var propertyZip = document.zipLookup.zipCode.value;	if(ccmid == "NOT"){		go="N";		enterOffice();	}else if(!ccmid || ccmid.length < 1){		$("#ziplookupError").show();		$("#ziplookupError").html("You must select an office");		go = "N";	}		if(propertyZip.length < 5){		$("#ziplookupError").show();		$("#ziplookupError").html("You must provide your property zip code");		go = "N";	}		if(officeZip.length < 5){		$("#ziplookupError").show();		$("#ziplookupError").html("You must enter your office zip code");		go = "N";	}		if(go == "Y"){		$("#zipSubmit").val("Processing");		$("#zipSubmit").attr("disabled", "true");		officeInfo(propertyZip,ccmid);		addClick(zipFlow);	}	return false;}function checkLogin(){	addClick(loginFlow);	return true;}function officeInfo(zip,ccmid){	$.post("ziplookup/officeInfo.lasso", { 			zipCode: zip,			ccmid: ccmid		},		function(html){			if(html.length){				$("#zipLookupPlacement").html(html);			}else{				//showCreatOffice();				//Unfortunately an error has occurred				$("#ziplookupError").show();				$("#ziplookupError").html("We can not process enrollments at this time.");			}	});}function checkOfficeInfo(userType){	// clear error message	$("#ziplookupError").hide();	$("#ziplookupError").html("");		//declare variables	var reProName = $("#reProName").val();	var phone1 = $("#reProCellAreaCode").val();	var phone2 = $("#reProCellFirst").val();	var phone3 = $("#reProCellSecond").val();	var fullMobile = phone1+phone2+phone3;	var email = $("#reProEmail").val();	var trimEmail = trim(email);	var agentCheck = $('#agentCheck').val();	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;		if( reProName.length < 1 ){		$("#ziplookupError").show();		if(userType == "GMAC"){			$("#ziplookupError").html("You must enter your Sales-Partner Name");		}else{			$("#ziplookupError").html("You must enter your Agent Name");		}		return false;	}	/*	if(fullMobile.length < 9){		$("#ziplookupError").show();		$("#ziplookupError").html("You must enter a mobile phone number");		return false;	}		*/	if(!(trimEmail.match(emailExp))){		$("#ziplookupError").show();		$("#ziplookupError").html("You must enter a valid email address");		return false;	}		if (agentCheck == "Y"){		var agentID = $('#agentID').val();		if(agentID.length < 2){			$("#ziplookupError").show();			$("#ziplookupError").html("You must enter your agent ID");			return false;		}	}	$("#continueButton").attr("disabled", "true");	$("#continueButton").val("Please wait while we gather plans in your area...");		return true;}function enterOffice(){	$.post("ziplookup/newOffice.lasso", {},		function(html){			if(html.length){				$("#zipLookupPlacement").html(html);			}else{				//showCreatOffice();				$("#ziplookupError").show();				$("#ziplookupError").html("We can not process new offices at this time.");			}	});}function inBrokerList(zip,type){	//alert("showBroker");	var substance = $("#ccmIDLIST").val();	/*	if(substance == "NOT"){		var answer= confirm("Are you sure your office is not on the list?\n\nPressing \"Okay\" will take you to a form for adding your office to our database.");		if (answer){			enterOffice();		}else{			$("#ccmIDLIST").val("");		}	}	*/}function submitNewOffice(){	var posts = "";	for(i=0; i<document.officeForm.elements.length; i++){		var n = document.officeForm.elements[i].name;		var v = document.officeForm.elements[i].value;		posts += n+"="+v+"&"; // put all posts in a string to pass with ajax	}		posts = removeTrailing(posts);			$.ajax({			type: "POST",			url: "ziplookup/newAgent.lasso",			data: posts,			success: function(html){				if(html.length){					$("#zipLookupPlacement").html(html);				}else{					//showCreatOffice();					$("#ziplookupError").show();					$("#ziplookupError").html("We can not process new offices at this time.");				}			}		});}function submitNewAgent(){	$("#ziplookupError").hide();	var posts = "";	var pass = "";	for(i=0; i<document.agentForm.elements.length; i++){		var n = document.agentForm.elements[i].name;		var v = document.agentForm.elements[i].value;		posts += n+"="+v+"&"; // put all posts in a string to pass with ajax	}		posts = removeTrailing(posts);		/*var check = $.ajax({					type: "POST",					url: "ziplookup/agentCheck.lasso",					data: posts,					success: function(html){						var pass = html;						//alert(pass);					}				});	*/		var check = $.ajax({			type: "POST",			async: false,			url: "ziplookup/checkNewAgent.lasso",			data: posts,			success: function(html){				pass = html;			}		});				if(pass == "Y"){			return "Y";		}else if(pass == "exists"){			$("#ziplookupError").show();			$("#ziplookupError").html("That email address already exists in our system. Do you already have a Marketopia account? <a href='Marketopia.153.lasso' class='zipErrorLink'>Log in here.</a>");			return "N";		}else if(pass == "inUse"){			$("#ziplookupError").show();			$("#ziplookupError").html("That user name already exists in our system. Please choose a different user name.");			return "N";		}}function removeTrailing(fld) {	var ln = fld.length;	var end = ln - 1;	return fld.substr(0,end);}function setFlow(flow, zip){	$("#flowContent").html("");	if(flow == "member"){		var D = "ziplookup/memberFlow.lasso";	}else{		var D = "ziplookup/zipFlow.lasso";	}		if(zip.length < 1){		$("#ziplookupRowMain").css("height", "325px");	}else{		$("#ziplookupRowMain").css("height", "285px");	}    $.post(D, { zip: zip},		function(html){		$("#flowContent").html(html);	});}/* ================================================ FUNCTIONS FOR SHOWING WHICH FLOW OF ZIP LOOK-UP ==============================*//* ================================================ END FUNCTIONS FOR SHOWING WHICH FLOW OF ZIP LOOK-UP ==============================*//* ================================================ OLDER FUNCTIONS FROM FIRST ITERATION OF ZIP LOOK-UP ==============================*/function showBroker(zip,type){	//alert("showBroker");	var substance = $("#ccmIDLIST").val();	if(substance == "NOT"){		hideOfficeList();		showMemberBroker();		showCreatOffice();	}else if(substance == ""){		//do nothing for now	}else{		$("#ccmIDbox").val("");		hideMemberBroker();		$("#CCMID_method").val("1");	}}function hideCCMoptions(zip,type){	//alert("hideCCMoptions");	$("#createOffice").hide();	var substance = $("#ccmIDbox").val();	if(substance.length > 0){		hideOfficeZip(zip,type);		//$("#officesSection").html('<td>&nbsp;<\/td><td><a href="enrollment.lasso?zip='+zip+'&type='+type+'">Want to select from office list?<\/a><\/td>');		//$("#showOfficeZip").html('<td>&nbsp;<\/td><td><a href="javascript: showOfficeZip()">Want to find office by zip? (optional)<\/a><\/td>');		//$("#showOfficeZip").show();		//$("#officesSection").hide();	}}function hideMemberBroker(){	//alert("hideMemberBroker");		$("#memBroker").html("<td><\/td><td><\/td>");		$("#memBorker").hide();	/*	var memBroker = $("#ccmIDbox").val();	if(memBroker.length < 1){		$("#memBroker").html("<td><\/td><td><\/td>");		$("#memBorker").hide();	}	*/}function hideOfficeZip(zip,type){	//alert("hideOfficeZip");	$("#agentOfficeZip").val("");	$("#officesSection").html('<td>&nbsp;<\/td><td><a href="enrollment.lasso?zip='+zip+'&type='+type+'">Want to select from office list?<\/a><\/td>');	$("#CCMID_method").val("0");	/*	var agentOfficeZip = $("#agentOfficeZip").val();	if(agentOfficeZip.length < 1){		$("#officesSection").html("<td><\/td><td><\/td>");		$("#officesSection").hide();	}	*/}function hideOfficeList(){	//alert("hideOfficeList");	$("#officesList").html("<td><\/td><td><\/td>");	$("#officesList").hide();	$("#agentOfficeZip").val("");	$("#CCMID_method").val("0");}function showMemberBroker(){	//alert("showMemberBroker");	$("#memBroker").html('<td>Member-Broker #:<\/td><td><span id="memberContent"><input name="ccmID" id="ccmIDbox" value="" onblur="hideCCMoptions(\'33065\', \'Professional\')" type="text"><\/span><\/td>');	//$("#memberContent").html('<a href="enrollment.lasso?zip='+zip+'&type='+type+'">Need to enter a Member-Broker Number?<\/a>');}function showCreatOffice(){	//alert("showCreatOffice");	$("#createOffice").html('<td>&nbsp;<\/td><td><a href="no_login.lasso?act=unknownUnknown">No offices found. Create one?<\/a><br>Or enter Member Broker # above<\/td>');	$("#createOffice").show();}function showOfficeZip(){	//alert("showOfficeZip");	$("#officesSection").show();	$("#showOfficeZip").hide();	//$("#officesSection").html('<td align="right">Office Zip Code:<\/td><td><input name="agentOfficeZip" id="agentOfficeZip" type="text" size="5" maxlength="5" onchange="getOffices(\'[action_param('type')]\');"><\/td>');}/* ------------------------------------------------------------------------------------	CHECKS IF A VALUE IS NUMERIC	EXAMPLE:		if(!IsNumeric(value)){			var youSuck = 'true';		}--------------------------------------------------------------------------------------- */function IsNumeric(sText){	var ValidChars = "0123456789.-";	var IsNumber=true;	var Char;	var usedPeriod = 0; 	for (i = 0; i < sText.length && IsNumber == true; i++) { 		Char = sText.charAt(i); 		if (ValidChars.indexOf(Char) == -1) {			IsNumber = false;		}				if(Char == "."){			usedPeriod++;		}				if(usedPeriod > 1){			IsNumber = false;		}	}	return IsNumber;}function MM_openBrWindow(theURL,winName,features) {    window.open("forgotPassword.lasso",winName,features);}function showPlanType(mySelect) {	var spanShow = document.getElementById('purchaseTypeCode').value;	if(mySelect.value == "SHW") {		document.getElementById("dateSelect").style.display = 'none';		document.getElementById("dateLabel").innerHTML="";		//document.getElementById("dateLabel").innerHTML="Listing Date:";		document.getElementById("bottomNote").style.display = '';		document.getElementById("bottomNote").innerHTML="<BLOCKQUOTE><B>A Seller Home Warranty</B>, which is placed on the home by a prospective home seller at or near the time of listing, is effective immediately upon receipt and processing of the Seller Home Warranty application by us and continues for the remaining term of the listing agreement, not to exceed one hundred and eighty (180) days from the date of listing, unless sooner terminated by the sale of the dwelling or cancellation of the listing agreement. The Seller Home Warranty may be extended by us at our sole discretion. The Seller Home Warranty converts to a Buyer Conversion Warranty on the date of closing (title transfer), provided required payment has been received by us within seven (7) business days of closing.</BLOCKQUOTE>";	} else if(mySelect.value == "BDW") {		document.getElementById("dateSelect").style.display = '';		document.getElementById("dateLabel").innerHTML="Closing Date:";		document.getElementById("bottomNote").style.display = '';		document.getElementById("bottomNote").innerHTML="<BLOCKQUOTE><B>A 'Buyer' (Buyer Direct) Warranty</B>, which is purchased by or on behalf of a home buyer at the time of closing, is effective on the date of closing, provided required payment has been received by us within seven (7) business days of closing, unless otherwise agreed to by us in writing.</BLOCKQUOTE>";	} else if(mySelect.value == "NHW") {		document.getElementById("dateSelect").style.display = '';		document.getElementById("dateLabel").innerHTML="Closing Date:";		document.getElementById("bottomNote").style.display = '';		document.getElementById("bottomNote").innerHTML="<BLOCKQUOTE><B>A New Home Warranty</B>, which is purchased by or on behalf of a home buyer at the time of closing of a newly constructed single family home, is effective on the date of closing, provided required payment has been received by us within seven (7) business days of closing, unless otherwise agreed to by us in writing.</BLOCKQUOTE>";	} else if(mySelect.value == "ODW") {		document.getElementById("dateSelect").style.display = 'none';		document.getElementById("bottomNote").style.display = '';		document.getElementById("dateLabel").innerHTML="";		document.getElementById("bottomNote").innerHTML="<BLOCKQUOTE><B>A 'Homeowner' (Open Direct) Warranty</B>, which is available to homeowners not immediately purchasing or selling their home (i.e., when the home is not listed for sale and/or it is more than seven (7) business days after closing), is effective thirty (30) days after required payment has been received by us, unless we otherwise agree in writing.</BLOCKQUOTE>";	} else {		document.getElementById("dateSelect").style.display = 'none';		document.getElementById("bottomNote").style.display = '';		document.getElementById("dateLabel").innerHTML="";		document.getElementById("bottomNote").innerHTML="<BLOCKQUOTE><B>A 'Homeowner' (Open Direct) Warranty</B>, which is available to homeowners not immediately purchasing or selling their home (i.e., when the home is not listed for sale and/or it is more than seven (7) business days after closing), is effective thirty (30) days after required payment has been received by us, unless we otherwise agree in writing.</BLOCKQUOTE>";	}  }/* ---------------------------------------------------------------------------- */function formatPhone(obj,del,parens){	/* This function formats a phone number as the user types		This function takes three values			obj = the identifier of the calling field			* = the delimiter to be used			yes/no = group area code in parenthesis or not 		EXAMPLE: onkeyup="formatPhone(this,'-','no')" */	var phone = $(obj).val();	if(parens == 'yes'){		phone = phone.substring(0,13);	}else{		phone = phone.substring(0,12);	}	var phoneLen = phone.length;	var num = phoneLen - 1;	var lastChar = phone.charAt(num);		if(lastChar != del){		if(!IsAllowed(lastChar)){			phone = phone.replace(lastChar, "");			$(obj).val(phone);		}	}		switch(phoneLen)	{		case 1:			if(parens == 'yes'){				var C = phone.charAt(num);				if(C != "("){					newSTRING = "(" + C;					$(obj).val(newSTRING);				}			}		break;		case 4:			if(parens == 'no'){				var C = phone.charAt(num);				if(C != del){					var newSTRING = phone.substring(0,num);					newSTRING = newSTRING + del + C;					$(obj).val(newSTRING);				}			}		break;		case 5:			if(parens == 'yes'){				var C = phone.charAt(num);				if(C != ")"){					var newSTRING = phone.substring(0,num);					newSTRING = newSTRING + ")" + C;					$(obj).val(newSTRING);				}			}		break;		case 8:			if(parens == 'no'){				var C = phone.charAt(num);				if(C != del){					var newSTRING = phone.substring(0,num);					newSTRING = newSTRING + del + C;					$(obj).val(newSTRING);				}			}		break;		case 9:			if(parens == 'yes'){				var C = phone.charAt(num);				if(C != del){					var newSTRING = phone.substring(0,num);					newSTRING = newSTRING + del + C;					$(obj).val(newSTRING);				}			}		break;		default:			$(obj).val(phone);	}}/* ---------------------------------------------------------------------------- *//* ------------------------------------------------------------------------------------	CHECKS IF A STRING CONTAINS AN ALLOWABLE CHARACTER	EXAMPLE:		if(!IsAllowed(value)){			var youSuck = 'true';		}--------------------------------------------------------------------------------------- */function IsAllowed(sText){	// A LIST OF ALLOWABLE CHARACTERS	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;}/* ---------------------------------------------------------------------------- *//* ---------------------------------------------------------------------------- *//* CHECKS FOR VALIDATION ON NEW AGENT FORM *//* ---------------------------------------------------------------------------- */function checkOfficeAgent(){	var problem = "N";	var disableBtn = $("#submit").attr('disabled', 'disabled');	var brokerName = $("#agencyBroker").val();	var agentPhone = document.getElementById("agentPhone");	var agencyEmail = document.getElementById("agencyEmail");	var userName = document.getElementById("userName");	var password = document.getElementById("password");	var password2 = document.getElementById("password2");	var agentID = document.getElementById("agentID");	//alert(document.getElementById("password").value.length);	//alert(brokerName);	var proDetail = "";		if(brokerName.length < 1){		var problem = "Y";		proDetail += "Please provide your name\n";	}	if(brokerName == "First and Last Name"){		var problem = "Y";		proDetail += "Please provide your first and last name\n";	}	/*	if(problem != "Y"){		if(brokerName.value.indexOf("/")){			proDetail += "Please remove the '/' from your name\n";			var problem = "Y";		}	}	*/	if(problem != "Y"){		var breakup = document.getElementById("agencyBroker").value;		var splitArr = breakup.split(" ");		var arrLen = splitArr.length;		if(arrLen < 2){			proDetail += "Please provide your first and last name\n";			var problem = "Y";		}	}	if(agentID.value.length < 1){		var problem = "Y";		proDetail += "Please provide your Weichert Agent ID\n";	}	if(agentPhone.value == ""){		var problem = "Y";		proDetail += "Please provide your mobile phone number\n";	}	if(problem != "Y"){		if(agentPhone.value.length < 10){			var problem = "Y";			proDetail += "Please provide a valid mobile phone number\n";		}	}	if(agencyEmail.value == ""){		var problem = "Y";		proDetail += "Please provide your email address\n";	}	if(problem != "Y"){		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(agencyEmail.value)){			proDetail += "";		}else{			var problem = "Y";			proDetail += "Please provide a valid email address\n";		}	}	if(userName.value == ""){		var problem = "Y";		proDetail += "Please select a user name\n";	}	if(password.value == ""){		var problem = "Y";		proDetail += "Please provide your desired password\n";	}		if(problem != "Y"){		if(password.value.length < 6){			var problem = "Y";			proDetail += "Your password must be at least 6 digits long\n";		}	}		if(problem != "Y"){		if(password.value != password2.value){			var problem = "Y";			proDetail += "Your confirmed password must match your desired password\n";		}	}		if(problem == "Y"){		$("#submit").removeAttr('disabled');		alert(proDetail);		return false;	} else {		// validate(check to see if in system) email address and user name		var checkAgent = submitNewAgent();		if(checkAgent == "Y"){			$("#submit").val("Processing");			return true;		}else{			$("#submit").removeAttr('disabled');			return false;		}	}}function addClick(trackingID){	$.post("ziplookup/tracking.lasso", { 			trackingID: trackingID		},		function(html){			// currently doing nothing with reply	});}function trim(a){	var result = a.replace(/^\s+|\s+$/g,"");	return result;}function showVideo(){	var height = $(document).height();	var width = $(document).width();	var ww = $(window).width();	var half = ww / 2;	var qw = half - 270;	$('#playVid').height(height);	$('#playVid').width(width);	$('#playVid').show();		$('#videoPlayer').vCenter();	$('#videoPlayer').css('left', qw);		$("#closeVid").click(function () { 			closeVid();	 });}function closeVid(){	$('#playVid').hide();}/*--------------------------------------------------------------------------------------------------------------*//* ---------------------------------------------------------------------------- */// These two function remove default name and put it back if no name is givenfunction removeName(){	var count = document.getElementById("nameCount").value;	//alert(count);	if(count == 0){		document.getElementById("agencyBroker").value = "";		document.getElementById("nameCount").value = 1;	}}function putNameBack(){	var name = document.getElementById("agencyBroker");	var value = name.value;	var size = value.length;	if(size < 1){		document.getElementById("agencyBroker").value = "First and Last Name";		document.getElementById("nameCount").value = 0;	}}/* ---------------------------------------------------------------------------- *//*--------------------------------------------------------------------------------------------------------------*/
