

function storeProp(currentProp) {

	// Modify the cookie

	if (currentProp.substring(0,1)=="*")

		currentProp = currentProp.substring(1);

	if (currentProp.length == 0 || currentProp == "DEL"){

		document.cookie = "PropList=; path=/; expires=Thursday, 01-Dec-02 12:00:01 GMT"

	}else{

		document.cookie = "PropList=" + currentProp + "; path=/;"

	}



}

function addProperty(PMSID, PName, PLocation, PType, PBeds, PBaths){

	

	if(PMSID.length > 0){							// URLencodes bad characters includes spaces

		var pID = escape(PMSID);

	}else{

		var pID = escape("N/A");

	}

	if(PName.length > 0){	

		var pName = escape(PName);	

	}else{														

		var pName = escape("N/A");

	}

	if(PLocation.length > 0){

		var pLocation = escape(PLocation);

	}else{

		var pLocation = escape("N/A");

	}

	if(PType.length > 0){

		var pType = escape(PType);

	}else{

		var pType = escape("N/A");

	}

	if(PBeds.length > 0){

		var pBeds = escape(PBeds);

	}else{

		var pBeds = escape("N/A");

	}

	if(PBaths.length > 0){

		var pBaths = escape(PBaths);

	}else{

		var pBaths = escape("N/A");

	}

	var props = getCart();							// Get the current Props stored in Cookie

	var currentProps;								// Initialize

	

	

	// See if property is already on list

	var propStart = props.indexOf( "^^" + pID + "^" + pName);

//alert("Cookie: " + props);

//alert("propStart: "+ propStart);

	if (propStart == -1){

		currentProps = "^^" + pID + "^" + pName + "^" + pLocation + "^" + pType + "^" + pBeds + "^" + pBaths;



		if (props.length + currentProps.length > 3000){

			alert("Your list is full.\nPlease submit your current list of Properties");

			currentProps="";

			//return false;

		}else{

			storeProp(props + currentProps);

			alert("Property ADDED");

			//return true;

		}

	}else{ 														// already exists

		alert ("You have already added this property!");

		//return false;

	}
}

function getCart() {

	var retstr = "*"											// dummy value to placate Nav 2

	var xstart = document.cookie.indexOf( "PropList=" )+0		// and force numeric

	if ( xstart > -1 ) {										// cookie exists 

		xstart += 9             								// set index of beginning of value

		if ( xstart < document.cookie.length ) {				// avoid blank cookies

			xend = document.cookie.indexOf(";", xstart)  		// set index of end of cookie value

	        if ( xend == -1 ) 

				xend = document.cookie.length

	        retstr = document.cookie.substring( xstart, xend )

		}

 	}

//	alert ("retstr: "+retstr);

	return retstr 
}

function removeProp(delProp){

	if(delProp == "All"){

		if(confirm("You are about to REMOVE ALL PROPERTIES.\nIf this is correct press OK, otherwise press CANCEL.")){

		var props = "DEL";

		storeProp(props);

		location.reload();

		}else{ return false }

	}else{

	var props = getCart();

	var propStart = props.indexOf("^^"+escape(delProp)+"^");

	var propEnd = props.indexOf("^^", propStart+2);

	if(propEnd == -1){

		propEnd = props.length;

	}

	delTxt=props.substring(propStart,propEnd);

	props = props.substring(0,propStart) + props.substring(propEnd,props.length);

	}

	storeProp(props);

	location.reload();

	return false;
}


// FOR COMPARISON PAGE



function deleteProp(){

	document.compare.submit();

}

function printProp(controller, prop){
		if(controller == "house"){
			var url = "book/house1835.html?print=Y&PMSUnitID="+prop+"&Instruct=Y";
			newWindow = window.open(url,"printpropcompare", "resizable=yes,toolbar=yes,menubar=yes,scrollbars=yes,height=600 width=620");
		
		}
		else{
			var url = "propprint0596.html?propList=" + document.compare.propList.value +"&Instruct=Y";
			newWindow = window.open(url,"printpropcompare", "resizable=yes,toolbar=yes,menubar=yes,scrollbars=yes,height=600 width=620");
		}
}

function back()
{
	var Mainform = document.forms[0];
	if (Mainform.Previous.value == "")
	{	
		alert("These are the first properties in the list.");
	}
	else
	{
		Mainform.Instruct.value = "N";
		Mainform.Next.value = Mainform.Current.value;
		Mainform.CurrentIndex.value = parseInt(Mainform.CurrentIndex.value) - 3 + ''
		Mainform.submit();
	}
}
	
function next()
{
	var Mainform = document.forms[0];
	if (Mainform.Next.value == "")
	{	
		alert("There are no more properties.");
	}
	else
	{
		Mainform.Instruct.value = "N";
		Mainform.Previous.value = Mainform.Current.value;
		Mainform.CurrentIndex.value = parseInt(Mainform.CurrentIndex.value) + 3 + ''
		Mainform.submit();
	}
}

function closeWindow(){
	window.close()
}

function printInstr(controller){
	if(controller == "house"){
		var Mainform = document.forms[0];
		if (window.print){
    		document.write('<a href="javascript:onClick=window.print()"><img src="images/comp_but_printb.gif" width="135" height="18" border="0" alt="Print This Page"></a>');
			if (Mainform.Instruct.value == "Y"){
				popUp('/book/printinstruct2.html?Button=Y','PropCompare', 'resizable=yes,toolbar=no,menubar=no,scrollbars=yes,height=250,width=425');
			}
		}else{
			if (Mainform.Instruct.value == "Y"){
				popUp('/book/printinstruct2.html?Button=N','PropCompare', 'resizable=yes,toolbar=no,menubar=no,scrollbars=yes,height=250,width=425');
			}
		}

	}else{
		var Mainform = document.forms[0];
		if (window.print){
    		document.write('<a href="javascript:onClick=window.print()"><img src="images/comp_but_printb.gif" width="135" height="18" border="0" alt="Print This Page"></a>');
			if (Mainform.Instruct.value == "Y"){
				popUp('/book/printinstruct.html?Button=Y','PropCompare', 'resizable=yes,toolbar=no,menubar=no,scrollbars=yes,height=250,width=425');
			}
		}else{
			if (Mainform.Instruct.value == "Y"){
				popUp('/book/printinstruct.html?Button=N','PropCompare', 'resizable=yes,toolbar=no,menubar=no,scrollbars=yes,height=250,width=425');
			}
		}
	}
}
