
var odialog_cippropertysearch;
if ( typeof EstateWeb_Objects_DialogManager != "undefined" ){
	odialog_cippropertysearch = new EstateWeb_Objects_DialogManager("cippropertysearch");
}else{
	alert("Dialog Manager not found");
}

function EstateWeb_Objects_CIPInlineRegistration(){
	this.setListingType = CIPInlineRegistration_setListingType;
	this.setMinimumPrice = CIPInlineRegistration_setMinimumPrice;
	this.setMaximumPrice = CIPInlineRegistration_setMaximumPrice;
	this.setMinimumBedrooms = CIPInlineRegistration_setMinimumBedrooms;
	this.setAreaNames = CIPInlineRegistration_setAreaNames;
}

function CIPInlineRegistration_setAreaNames(value){
	HttpManager.Document.GetObject("__cip_requirements_areaNames").value = value;
}

function CIPInlineRegistration_setListingType(value){
	HttpManager.Document.GetObject("__cip_requirements_listingtype").value = value;
}

function CIPInlineRegistration_setMinimumPrice(value){
	HttpManager.Document.GetObject("__cip_requirements_minimumprice").value = value;
}

function CIPInlineRegistration_setMaximumPrice(value){
	HttpManager.Document.GetObject("__cip_requirements_maximumprice").value = value;
}

function CIPInlineRegistration_setMinimumBedrooms(value){
	HttpManager.Document.GetObject("__cip_requirements_minimumbedrooms").value = value;
}

var CIPInlineRegistration = new EstateWeb_Objects_CIPInlineRegistration();

function CIPInlineRegistration_Start(){
	
	if ( CIPInlineRegistration_IsRequired() ){
		if ( CIPInlineRegistration_Validate() ){
			
			with ( odialog_cippropertysearch ){
				parentID = "body";
				styleID = 1;
				parentMarginLeftOffset = 0;
				backgroundOptions.opacity = 0.5;
				dialogOptions.backgroundColour = "#000000";
				dialogOptions.width = 510;
				dialogOptions.height = 490;
				dialogOptions.contentPaddingLeft = "15px";
				dialogOptions.contentPaddingRight = "15px";
				dialogOptions.contentPaddingTop = "10px";
				dialogOptions.contentPaddingBottom = "7px";
				dialogOptions.title.text = "Property E-mail Alerts";
				dialogOptions.title.cssClass = "cipPropertySearchRegisterTitle";
				dialogOptions.title.fontColour = "#FFFFFF";
				dialogOptions.type = dialogTypes.page;
				dialogOptions.pageOptions.url = "/Controls/CIP/CIPInlineRegistration.aspx?"+CIPInlineRegistration_GetParmeters();
				show();
			}
			
		}
	}else{
		CIPInlineRegistration_Redirect();
	}
}

function CIPInlineRegistration_onStart(params) {
	with ( odialog_cippropertysearch ){
		parentID = "body";
		styleID = 1;
		parentMarginLeftOffset = 0;
		backgroundOptions.opacity = 0.5;
		dialogOptions.backgroundColour = "#000000";
		dialogOptions.width = 510;
		dialogOptions.height = 490;
		dialogOptions.contentPaddingLeft = "15px";
		dialogOptions.contentPaddingRight = "15px";
		dialogOptions.contentPaddingTop = "10px";
		dialogOptions.contentPaddingBottom = "7px";
		dialogOptions.title.text = "Property E-mail Alerts";
		dialogOptions.title.cssClass = "cipPropertySearchRegisterTitle";
		dialogOptions.title.fontColour = "#FFFFFF";
		dialogOptions.type = dialogTypes.page;
		dialogOptions.pageOptions.url = "/Controls/CIP/CIPInlineRegistration.aspx?"+params + "&oid=odialog_cippropertysearch";
		show();
	}
}

function CIPInlineRegistration_Redirect(){
	switch ( parseInt(HttpManager.Document.GetObject("__cip_requirements_redirectionType").value) ){
		case 0:
			if ( HttpManager.Document.GetObject("__cip_requirements_formName").value.length > 0 ){
				if ( HttpManager.Document.GetObject( HttpManager.Document.GetObject("__cip_requirements_formName").value ) ){
					HttpManager.Document.GetObject( HttpManager.Document.GetObject("__cip_requirements_formName").value ).submit();
				}else{
					alert("CIP: Form could not be found");
				}
			}else{
				alert("CIP: Form name not defined");
			}
			break;
		case 1:
			if ( HttpManager.Document.GetObject("__cip_requirements_redirectionURL").value.length > 0 ){
				location.href = HttpManager.Document.GetObject("__cip_requirements_redirectionURL").value;
			}else{
				alert("CIP: No redirection URL could be found");
			}
			
			break;
	}
}

function CIPInlineRegistration_GetParmeters(){
	var aparams = [];
	aparams.push( "minprice=" + ( HttpManager.Document.GetObject("__cip_requirements_minimumprice").value.length > 0 ? HttpManager.Document.GetObject("__cip_requirements_minimumprice").value : -1 ) );
	aparams.push( "maxprice=" + ( HttpManager.Document.GetObject("__cip_requirements_maximumprice").value.length > 0 ? HttpManager.Document.GetObject("__cip_requirements_maximumprice").value : -1 ) );
	aparams.push( "listingtype=" + HttpManager.Document.GetObject("__cip_requirements_listingtype").value );
	aparams.push( "minbedrooms="+ ( HttpManager.Document.GetObject("__cip_requirements_minimumbedrooms").value.length > 0 ? HttpManager.Document.GetObject("__cip_requirements_minimumbedrooms").value : -1 ) );
	aparams.push( "areanames=" + escape(HttpManager.Document.GetObject("__cip_requirements_areaNames").value) );
	aparams.push( "areavalues=" + escape(HttpManager.Document.GetObject("__cip_requirements_areaValues").value) );
	aparams.push( "redirectionType=" + HttpManager.Document.GetObject("__cip_requirements_redirectionType").value );
	aparams.push( "formName=" + HttpManager.Document.GetObject("__cip_requirements_formName").value );
	aparams.push( "redirectionURL=" + escape(HttpManager.Document.GetObject("__cip_requirements_redirectionURL").value.replace("/", "")) );
	aparams.push( "oid=odialog_cippropertysearch" );
	return aparams.join("&");
}

function CIPInlineRegistration_IsRequired(){
	if ( EmailAlerts_Yes ){
		return ( EmailAlerts_Yes.checked || ( EmailAlerts_Yes.checked == false && EmailAlerts_No.checked == false ) );
	}else{
		return false;
	}
}

function CIPInlineRegistration_Validate(){
	if ( EmailAlerts_Yes.checked == false && EmailAlerts_No.checked == false ){
		CIPInlineRegistration_ShowEmailAlertBalloon();
		return false;
	}else if ( parseInt(HttpManager.Document.GetObject("__cip_requirements_maximumprice").value) <= 0 || HttpManager.Document.GetObject("__cip_requirements_maximumprice").value.length == 0 ){
		alert("For email alerts, please select a maximum price");
		return false;
	}else if ( parseInt(HttpManager.Document.GetObject("__cip_requirements_minimumprice").value) >= parseInt(HttpManager.Document.GetObject("__cip_requirements_maximumprice").value) ){
		alert("The minimum price selected cannot be greater than the maximum price selected");
		return false;
	}
	return true;
}


function CIPInlineRegistration_EmailSaveOptionsOnClick(){
	if (HttpManager.Document.GetObject("pnlCIPEmailAlert") ){
		HttpManager.Document.GetObject("pnlCIPEmailAlert").style.display = "none";
	}else{
		alert("Unable to find email alert balloon named pnlCIPEmailAlert");
	}
}

function CIPInlineRegistration_ShowEmailAlertBalloon(){
	if (HttpManager.Document.GetObject("pnlCIPEmailAlert") ){
		HttpManager.Document.GetObject("pnlCIPEmailAlert").style.display = "block";
	}else{
		alert("Unable to find email alert balloon named pnlCIPEmailAlert");
	}
}
