function PLPropertyActionHandler(ysnAdminSide, ID, action) {
	var f;
	if(ysnAdminSide)	f = document.frmPLPropertyList;
	else				f = document.frmDetails;

	if(ysnAdminSide) {
		if(action == "form")		f.ysnSave.value = 0;
		else						f.ysnSave.value = 1;
		f.strPage.value = "property" + action;
		f.lngPropertyID.value = ID;
		f.submit();
	}
	else {
		window.location = "/Properties.aspx?strPage=p" + action + "&PID=" + ID;
	}
}

function PLPropertyAction(el, ID, ysnAdminSide) {
	var action;

	if(el) {
		action = el.value;
		el.value = "choose";
	}
	else
		action = "form";

	switch(action) {
		case "form":
		case "publish":
		case "reject":
		case "submit":
		
		case "unpublish": {
			PLPropertyActionHandler(ysnAdminSide, ID, action);
			break;
		}
		case "delete": {
			if( confirm("Are you sure you want to delete this property?") ) {
				PLPropertyActionHandler(ysnAdminSide, ID, action);
				return;
			}
			break;
		}
		case "print": {
			window.open("/PropertyDetail.aspx?admin=1&PID=" + ID + "")
			break;
		}
		case "copy":
			var f;
			if(ysnAdminSide)	f = document.frmPLPropertyList;
			else				f = document.frmDetails;
			if(ysnAdminSide) {
				f.ysnSave.value = 1;
				f.strPage.value = "copy";
				f.lngPropertyID.value = ID;
				f.submit();
			}
			else {
				
				window.location = "/Properties.aspx?strPage=p" + "copy" + "&PID=" + ID;
			}
			break;
	}
}


function myPrint(){
	window.open('/common/modules/pl/printinfo.aspx','PrintImages','width=400,height=400, status, resizeable ');
}

function focusAndSelect(object)
{
	object.focus();
    object.select();
    return true;
}

function ProfileCancel(ysnAdminSide) {
	if (! confirm("You are about to discard any unsaved changes.  Proceed?") )
		return;
	
	if(ysnAdminSide) {
		gotoNavBarTab('Managers');
	}
	else {
			window.location = "Properties.aspx"
	}
}

function setContactInfo(ysnAdminSide){
    var theForm = (ysnAdminSide ? document.frmPLManager : document.aspnetForm);
    
	if(theForm.cinfo.checked) {
		theForm.cfname.value=theForm.fname.value;
		theForm.clname.value=theForm.lname.value;
		theForm.cadd1.value=theForm.add1.value;
		theForm.cadd2.value=theForm.add2.value;
		theForm.ccity.value=theForm.city.value;
		theForm.cstate.value=theForm.state.value;
		theForm.czip.value=theForm.zip.value;
		theForm.ccountry.value=theForm.country.value;
		theForm.cphone.value=theForm.phone.value;
		theForm.cfax.value=theForm.fax.value;
		theForm.cemail.value=theForm.email.value;
		theForm.txtContactURL.value=theForm.web.value;
	}
}

function CheckOwnerValues(ysnAdminSide) {
    var theForm = (ysnAdminSide ? document.frmPLManager : document.aspnetForm);
	theForm.passwd.value = TrimString(theForm.passwd.value);
	theForm.passwdconfirm.value = TrimString(theForm.passwdconfirm.value);

	if(FieldIsEmpty(theForm.fname.value)) {
		theForm.fname.focus();
		alert("Please enter a first name.");
		return;
	}
	if(FieldIsEmpty(theForm.lname.value)) {
		theForm.lname.focus();
		alert("Please enter a last name.");
		return;
	}
	if(!emailValidate(theForm.email.value)) {
		theForm.email.focus();
		alert("Please enter a valid email address.");
		return;
	}
	if(theForm.login && FieldIsEmpty(theForm.login.value)) {
		theForm.lname.focus();
		alert("Please enter a username.");
		return;
	}
	if(theForm.passwd.value.length < 5) {
		theForm.passwd.focus();
		alert("Passwords must be 5 characters or longer.");
		return;
	}
	if(theForm.passwd.value != theForm.passwdconfirm.value) {
		theForm.passwd.focus();
		alert("The password and confirm password do not match.");
		return;
	}
	if(FieldIsEmpty(theForm.company.value)) {
		theForm.cfname.focus();
		alert("Please enter a company name.");
		return;
	}
		if(FieldIsEmpty(theForm.add1.value)) {
		theForm.cfname.focus();
		alert("Please enter address.");
		return;
	}
	if(FieldIsEmpty(theForm.city.value)) {
		theForm.cfname.focus();
		alert("Please enter a city.");
		return;
	}
	if(theForm.state.value == 'zz') {
		theForm.cfname.focus();
		alert("Please choose a state.");
		return;
	}
	if(FieldIsEmpty(theForm.zip.value)) {
		theForm.cfname.focus();
		alert("Please enter a zip code.");
		return;
	}
	if(!FieldIsEmpty(theForm.zip.value) && !isZipCode(theForm.zip.value, intCountryCode)) {
		theForm.zip.focus();
		alert("Please enter a valid account zip code.");
		return;
	}
	if(FieldIsEmpty(theForm.cfname.value)) {
		theForm.cfname.focus();
		alert("Please enter a contact first name.");
		return;
	}
	if(FieldIsEmpty(theForm.clname.value)) {
		theForm.clname.focus();
		alert("Please enter a contact last name.");
		return;
	}
	if(!FieldIsEmpty(theForm.czip.value) && !isZipCode(theForm.czip.value, intCountryCode)) {
		theForm.czip.focus();
		alert("Please enter a valid contact zip code.");
		return;
	}
	if(!FieldIsEmpty(theForm.cemail.value) && !emailValidate(theForm.cemail.value)) {
		theForm.cemail.focus();
		alert("Please enter a valid contact email address.");
		return;
	}
	
	if(ysnAdminSide) {
		theForm.ysnSave.value = 1;
		theForm.strPage.value = "ownersave";
	}
	theForm.submit();
}

function verifyField(frmitem, size, type){
	if (type=='System.Int32')
		return checkNumbers(frmitem);
	else {
		if (frmitem.value.length > size && size > -1) {
			alert("Please limit your answer to "+size+ " characters.\nYou are currently using "+frmitem.value.length+" characters.");
			focusAndSelect(frmitem);
			return false;
		}
	}
	return true;
}
function dropdownsave(frmitem){ 
	verifyField(frmitem,50,200);
	frmitem.form.save.value="Save";
	try{
		for(i=0;i<frmitem.form.ID.length;i++){
			frmitem.form.ID[i].checked=false;
		}
	}
	catch(exception){}
}

function focusAndSelect(object)
{
	if (object.focus)
		object.focus();
	
	if (object.select)
		object.select();
	
	return true;
}

//front end - search screen
function viewProperty(PID){
	newloc = "/PropertyDetail.aspx?PID="+PID;
	window.open(newloc,"Propertys","height=450, width=630,scrollbars, resize, menubar");
}
function viewImage(ID,SID,PID){
	newloc ="imageview.aspx?ID="+ID+"&SID="+SID+"&PID="+PID;
	window.open(newloc,"preview");
}
function gotoPage(x){
	document.frmDetails.page.value=x;
	document.frmDetails.submit();
}
function sortResults(txt){
	document.frmDetails.sort.value=txt;
	//document.frmDetails.strPage.value="";
	document.frmDetails.submit();
}

function checkNumbers(formitem){
	if (isNaN(formitem.value)) {
		alert('This field can only contain numbers.');
		focusAndSelect(formitem);
		return false;
	}
	if(formitem.value.length>formitem.maxsize) {
		alert('This field can only contain numbers.');
		focusAndSelect(formitem);
		return false;
	}
	return true;
}

function CBOtherChange(ysnChecked)
{
	document.getElementById("txtOtherReason").disabled = !ysnChecked;
}

function propertySearch() {
    var submitForm = document.frmDetails;
    var displayForm = document.aspnetForm;

    //displayForm.search.disabled = true;
    if(displayForm.propertyneighborhooddropdown!=null)
    	submitForm.propertyneighborhooddropdown.value = displayForm.propertyneighborhooddropdown.value;
    if (displayForm.propertytypedropdown != null)
    	submitForm.propertytypedropdown.value = displayForm.propertytypedropdown.value;
    if (displayForm.propertyIntersectingStreet != null)
    	submitForm.propertyIntersectingStreet.value = displayForm.propertyIntersectingStreet.value;
    if (displayForm.acreage != null)
    	submitForm.acreage.value = displayForm.acreage.value;
    if (displayForm.propertyStreet != null)
    	submitForm.propertyStreet.value = displayForm.propertyStreet.value;
    if (displayForm.totalsquarefootage != null)
    	submitForm.totalsquarefootage.value = displayForm.totalsquarefootage.value;
    if (displayForm.propertycity != null)
    	submitForm.propertycity.value = displayForm.propertycity.value;
    if (displayForm.saleorlease != null)
    	submitForm.saleorlease.value = displayForm.saleorlease.value;
    if (displayForm.propertycounty != null)
    	submitForm.propertycounty.value = displayForm.propertycounty.value;
    if (displayForm.propertyState != null)
    	submitForm.propertyState.value = displayForm.propertyState.value;
    if (displayForm.propertyZip != null)
    	submitForm.propertyZip.value = displayForm.propertyZip.value;
    
    if (displayForm.ysnImages.checked)
        submitForm.ysnImages.value = displayForm.ysnImages.value;
    submitForm.submit();
}

function PLReasonSave()
{
	if(	!document.getElementById("ysnChangeBroker").checked &&
		!document.getElementById("ysnLeasedSold").checked &&
		!document.getElementById("ysnOffMarket").checked &&
		!document.getElementById("ysnOther").checked )
		{
			alert("Please indicate the reason this property is no longer available.");
			return;
		}

	if(document.getElementById("ysnOther").checked && FieldIsEmpty(document.getElementById("txtOtherReason").value))
	{
		alert("If 'other' is selected, please enter the description.");
		document.getElementById("txtOtherReason").focus();
		return;
	}

	document.getElementById("btnPLReasonSave").disabled = true;
	document.getElementById("btnPLReasonCancel").disabled = true;

	var displayForm = document.aspnetForm;
	var submitForm = document.frmPLManager;
	if (displayForm.ysnChangeBroker.checked)
	    submitForm.ysnChangeBroker.value = displayForm.ysnChangeBroker.value;
	if (displayForm.ysnLeasedSold.checked)
	    submitForm.ysnLeasedSold.value = displayForm.ysnLeasedSold.value;
	if (displayForm.ysnOffMarket.checked)
	    submitForm.ysnOffMarket.value = displayForm.ysnOffMarket.value;
	if (displayForm.ysnOther.checked)
	    submitForm.ysnOther.value = displayForm.ysnOther.value;
	submitForm.txtOtherReason.value = displayForm.txtOtherReason.value;
	submitForm.submit();
}

function setenddate(lngDefaultDaysToExpire)
{
	document.getElementById("txtdtienddate").value = '';
	var objDate = new dateValidator();
	objDate.ysnAllowEqualDates = true;
	objDate.ysnCent = true;
	objDate.setStartDate (document.getElementById("txtdtistartdate").value);
	objDate.setEndDate(document.getElementById("txtdtistartdate").value);
	
	if(!objDate.dateOrderValidate())
	{
		alert(objDate.error);
		return;
	}
	else
	{
		if (document.getElementById("txtdtistartdate").value != '')
		{
			var startdate = new Date(document.getElementById("txtdtistartdate").value);
			startdate.setDate(startdate.getDate()+lngDefaultDaysToExpire);
			
			var day = startdate.getDate();
			if (day<10)
				day = "0"+day;
			
			var month = startdate.getMonth() + 1;
			if (month<10)
				month = "0"+month;
			
			var year = startdate.getFullYear();
			document.getElementById("txtdtienddate").value = month + '/'+day + '/'+ year;
		}
	}
}

