var currPhoto = 0;
var prevPhoto = 0;
var formSent = new Boolean(false);

/*
if (document.images) {

  var lmenuoverseasoff = new Image();
  lmenuoverseasoff.src = "images/lmenuoverseasoff.gif";
  var lmenuoverseason = new Image();
  lmenuoverseason.src = "images/lmenuoverseason.gif";

  var lmenuprentoff = new Image();
  lmenuprentoff.src = "images/lmenuprentoff.gif";
  var lmenuprenton = new Image();
  lmenuprenton.src = "images/lmenuprenton.gif";

  var lmenupsaleoff = new Image();
  lmenupsaleoff.src = "images/lmenupsaleoff.gif";
  var lmenupsaleon = new Image();
  lmenupsaleon.src = "images/lmenupsaleon.gif";

  var lmenulandlordoff = new Image();
  lmenulandlordoff.src = "images/lmenulandlordoff.gif";
  var lmenulandlordon = new Image();
  lmenulandlordon.src = "images/lmenulandlordon.gif";

  var lmenuinvestoff = new Image();
  lmenuinvestoff.src = "images/lmenuinvestoff.gif";
  var lmenuinveston = new Image();
  lmenuinveston.src = "images/lmenuinveston.gif";

  var lmenutenantoff = new Image();
  lmenutenantoff.src = "images/lmenutenantoff.gif";
  var lmenutenanton = new Image();
  lmenutenanton.src = "images/lmenutenanton.gif";

  var lmenudepositoff = new Image();
  lmenudepositoff.src = "images/lmenutenancydepositoff.gif";
  var lmenudepositon = new Image();
  lmenudepositon.src = "images/lmenutenancydepositon.gif";

  var lmenutenregoff = new Image();
  lmenutenregoff.src = "images/lmenutenregoff.gif";
  var lmenutenregon = new Image();
  lmenutenregon.src = "images/lmenutenregon.gif";

  var lmenuyourtenaccoff = new Image();
  lmenuyourtenaccoff.src = "images/lmenuyourtenaccoff.gif";
  var lmenuyourtenaccon = new Image();
  lmenuyourtenaccon.src = "images/lmenuyourtenaccon.gif";

  var lmenuaboutoff = new Image();
  lmenuaboutoff.src = "images/lmenuaboutoff.gif";
  var lmenuabouton = new Image();
  lmenuabouton.src = "images/lmenuabouton.gif";

  var lmenucontactoff = new Image();
  lmenucontactoff.src = "images/lmenucontactoff.gif";
  var lmenucontacton = new Image();
  lmenucontacton.src = "images/lmenucontacton.gif";

  var lmenuhomeoff = new Image();
  lmenuhomeoff.src = "images/lmenuhomeoff.gif";
  var lmenuhomeon = new Image();
  lmenuhomeon.src = "images/lmenuhomeon.gif";
}


function actMenuItem(imgName,defImg) {
  act(imgName);
  if(imgName != defImg)
  {
    inact(defImg);
  }
}

function inactMenuItem(imgName,defImg) {
  inact(imgName);
  act(defImg);
}

function act(imgName) {
  if (document.images)
    document.images[imgName].src = eval(imgName + "on.src");
}

function inact(imgName) {
  if (document.images)
    document.images[imgName].src = eval(imgName + "off.src");
}
*/

function rotatePhoto(clientid,direction,photoList)
{

	prevPhoto = currPhoto;

	if(direction == 'prev')
	{
		currPhoto = currPhoto - 1;
	}else
	{
		currPhoto = currPhoto + 1;
	}

	
	var photoArr = photoList.split(';');


	if(currPhoto == -1)
	{
		currPhoto = photoArr.length - 1;
	}


	if(photoArr[currPhoto] == null)
	{
		currPhoto = 0;
	}


	document.images.largePhoto.src = "http://www.10ninety.co.uk/" + clientid + "/publicPostScripts/resize.asp?File=propertyphotos/" + photoArr[currPhoto] + "&Width=250&Height=250&C=false&RS=true";


}







function setUpAdvertForm()
{
	changeAreaList('true');
	hideBeds();
}








function changeAreaList(allowAny){

      
	var elems,optionList,listStr,myRegExp,areaResponse,townSelect,areaSelect,optionParts,reselectAreaIndex,indexAddOn,propArea,areaSelIndex;

	elems = document.propadvert.elements;

	townSelect = elems["proptown"];
	areaSelect = elems["proparea"];

	propArea = new Number(elems["newPropArea"].value);

	areaResponse = DoCallback('getareas.asp','false',townSelect.options[townSelect.selectedIndex].value);

	listStr = areaResponse.responseText;

	if(allowAny == 'true' && townSelect.options[townSelect.selectedIndex].value == "")
	{
		areaSelect.length = 1;
		areaSelect.options[0].text = "Select a City/Region first";
		areaSelect.options[0].value = "";
		indexAddOn = 1;
	}else
	{
		areaSelect.length = 2;
		areaSelect.options[0].text = "Select an area";
		areaSelect.options[0].value = "";
		areaSelect.options[1].text = "--------------------";
		areaSelect.options[1].value = "";
		indexAddOn = 2;
	}
	

	if(townSelect.options[townSelect.selectedIndex].value != "")
	{
		optionList = listStr.split(";");

		for(i = 0;i < optionList.length;i++)
		{
			optionParts = optionList[i].split(":");

			areaSelect.length++;
			areaSelect.options[i + indexAddOn] = new Option(optionParts[1],optionParts[0]);

			if(optionParts[0] == propArea)
			{
				areaSelIndex = i + indexAddOn;
			}

		}

		areaSelect.selectedIndex = areaSelIndex;

	}

}







function changeSearchAreaList(){

	var elems,optionList,listStr,areaResponse,townSelect,areaSelect,optionParts,reselectAreaIndex,indexAddOn,propArea,areaSelIndex;

	elems = document.propsearch.elements;

	townSelect = elems["proptown"];
	areaSelect = elems["proparea"];

	areaResponse = DoCallback('getareas.asp','true',townSelect.options[townSelect.selectedIndex].value);

	listStr = areaResponse.responseText;


// alert (listStr);
	if(townSelect.options[townSelect.selectedIndex].value == "")
	{
		areaSelect.length = 1;
		areaSelect.options[0].text = "All";
		areaSelect.options[0].value = "";
		indexAddOn = 1;
	}else
	{
		areaSelect.length = 2;
		areaSelect.options[0].text = "All";
		areaSelect.options[0].value = "";
		areaSelect.options[1].text = "-----";
		areaSelect.options[1].value = "";
		indexAddOn = 2;
	}
	

	if(townSelect.options[townSelect.selectedIndex].value != "")
	{
		optionList = listStr.split(";");
		for(i = 1 ;i < optionList.length;i++)
		{
//			optionParts = optionList[i].split(";");
                        areaSelect.length++;			
//			areaSelect.options[i + indexAddOn] = new Option(optionParts[1],optionParts[0]);
			areaSelect.options[i + indexAddOn-1] = new Option(optionList[i],optionList[i]);

//alert ('value = ' + areaSelect.options[i+indexAddOn-1].value + 'text = ' + areaSelect.options[i+indexAddOn-1].text);

		}

	}

}







function DoCallback(url,search,townid){
   // url:    URL to invoke
   // params: string object to pass to the remote URL

   // Add some parameters to the query string
   var pageUrl = url + "?Town=" + townid + "&Search=" + search

   // Initialize the XmlHttp object
    try {
        //Mozilla Browsers
        xmlRequest = new XMLHttpRequest();
    } 
    catch (e) {
        try {
            //IE
            xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
        } 
        catch (e) {
            //Something else that won't work with this code...
            xmlRequest=false;
        }
    } 
    // Post our XmlRequest and get our desired string
    xmlRequest.open("GET", pageUrl, false);
    xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlRequest.send(null);

    // Return the XmlHttp object
    return xmlRequest;
}






function hideBeds()
{
	var elems,proptypeSelect,bedSelect;

	elems = document.propadvert.elements;

	proptypeSelect = elems["proptype"];
	bedSelect = elems["beds"];

	if(proptypeSelect.options[proptypeSelect.selectedIndex].value == "4" || proptypeSelect.options[proptypeSelect.selectedIndex].value == "5" || proptypeSelect.options[proptypeSelect.selectedIndex].value == "6")
	{
		bedSelect.disabled = true;
	}else
	{
		bedSelect.disabled = false;
	}
}







function newWindow(PicId,Id,IdName,Table,ImageField,Path){

	newWin = window.open('uploadPhoto.asp?PicId=' + PicId + '&Id=' + Id + '&IdName=' + IdName + '&Table=' + Table + '&ImageField=' + ImageField + '&Path=' + Path,'newItemWindow','width=420,height=280,toolbar=no,location=no,scrollbars=no')

}







function previewAdvert(PropId){

	newWin = window.open('previewAdvert.asp?Id=' + PropId,'advertWindow','width=570,height=550,toolbar=no,location=no,scrollbars=yes')

}





function printProperty(PropId,preview,propind){

	newWin = window.open('propertydet-printable.asp?Id=' + PropId + '&Prev=' + preview + '&propind=' + propind,'printWindow','width=725,height=550,toolbar=no,location=no,scrollbars=yes')

}


function validateDelete()
{
	if(document.activeElement.name == 'Delete')
	{

		var confirmBox;

		if(formSent == true)
		{
			alert("Please wait... your deletion request is being processed");
			return false;
		}
	

		confirmBox = confirm('Press OK if you are sure you want to delete this item. N.B. If you are a single tenant or the only tenant currently in your group, then your account will be permanently deleted (you may re-register at any time).');

		if(confirmBox == true)
		{
			return true;
		}else
		{
			return false;
		}

	}

}






function validateMailingList()

{

	var elems,err,errList,errMsg,ptypeErr;	

	if(formSent == true)
	{
		alert("Please wait... your mailing list request is being processed");
		return false;
	}
	

	err = 0;
	ptypeErr = 0;
	errList = "";
	errMsg = "";


	elems = document.mailinglist.elements;

	for(i = 0;i < elems.length;i++)
	{
		switch (elems[i].name)
		{
			case "Titlea" :

				if(elems[i].value == "")
				{
					err = 1;
					errList = errList + "Title" + String.fromCharCode(10);
				}
				break;

			case "ForeNamea" :

				if(elems[i].value == "")
				{
					err = 1;
					errList = errList + "Forname" + String.fromCharCode(10);
				}
				break;

			case "Surname" :

				if(elems[i].value == "")
				{
					err = 1;
					errList = errList + "Surname" + String.fromCharCode(10);
				}
				break;

			case "address" :

				if(elems[i].value == "")
				{
					err = 1;
					errList = errList + "Address" + String.fromCharCode(10);
				}
				break;

			case "towna" :

				if(elems[i].value == "")
				{
					err = 1;
					errList = errList + "Town" + String.fromCharCode(10);
				}
				break;

			case "countya" :

				if(elems[i].value == "")
				{
					err = 1;
					errList = errList + "County" + String.fromCharCode(10);
				}
				break;

			case "postcodea" :

				if(elems[i].value == "")
				{
					err = 1;
					errList = errList + "Postcode" + String.fromCharCode(10);
				}
				break;

			case "telno" :

				if(elems[i].value == "")
				{
					err = 1;
					errList = errList + "Tel no" + String.fromCharCode(10);
				}
				break;

			case "evetelnoa" :

				if(elems[i].value == "")
				{
					err = 1;
					errList = errList + "Evening Tel no" + String.fromCharCode(10);
				}
				break;

			case "proptypea" :

				if(elems[i].checked)
				{
					ptypeErr++;
				}
				break;

			default :
				break;
		}
	}




	if(err == 1)
	{
		errMsg = "Please fill in the following fields :" + String.fromCharCode(10) + String.fromCharCode(10);
		alert(errMsg + errList);
		formSent = false;
		return false;
	}else
	{
		formSent = true;
		return true;
	}

}
function changePriceList(){

   changeminPriceList();

   changemaxPriceList();


}

function changeminPriceList(){

	var elems,propind,priceList,optionList,listStr,pArr;

	elems = document.propsearch.elements
	elems["minprice"].length = 1;
	elems["minprice"].options[0].text = "No min";
	elems["minprice"].options[0].value = "No min";

	if(elems["propind"][0].checked)
	{
		propind = elems["propind"][0].value;
	}else
	{
		propind = elems["propind"][1].value;
	}


	if(propind == "L")
	{
		listStr = new String(elems["RentPriceList"].value);
		optionList = listStr.split(";");
	}else
	{
		listStr = new String(elems["SalesPriceList"].value);
		optionList = listStr.split(";");
	}


	for(i = 0;i < optionList.length;i++)
	{
		elems["minprice"].length++;
		pArr = optionList[i].split("-");
		if(pArr[1] == "")
		{
			elems["minprice"].options[i + 1] = new Option("£" + pArr[0] + "+",optionList[i]);
		}else
		{
			elems["minprice"].options[i + 1] = new Option("£" + optionList[i],optionList[i]);
		}
	}

        changeTownList(propind);
}

function changemaxPriceList(){

	var elems,propind,priceList,optionList,listStr,pArr;

	elems = document.propsearch.elements
	elems["maxprice"].length = 1;
	elems["maxprice"].options[0].text = "No min";
	elems["maxprice"].options[0].value = "No min";

	if(elems["propind"][0].checked)
	{
		propind = elems["propind"][0].value;
	}else
	{
		propind = elems["propind"][1].value;
	}


	if(propind == "L")
	{
		listStr = new String(elems["RentPriceList"].value);
		optionList = listStr.split(";");
	}else
	{
		listStr = new String(elems["SalesPriceList"].value);
		optionList = listStr.split(";");
	}


	for(i = 0;i < optionList.length;i++)
	{
		elems["maxprice"].length++;
		pArr = optionList[i].split("-");
		if(pArr[1] == "")
		{
			elems["maxprice"].options[i + 1] = new Option("£" + pArr[0] + "+",optionList[i]);
		}else
		{
			elems["maxprice"].options[i + 1] = new Option("£" + optionList[i],optionList[i]);
		}
	}

}

function changeTownList(proptype){

	var elems,propind,priceList,optionList,listStr;

	elems = document.propsearch.elements
	elems["proptown"].length = 1;
	elems["proptown"].options[0].text = "All";
	elems["proptown"].options[0].value = "All";

	if(proptype == "L")
	{
		listStr = new String(elems["RentTownList"].value);
		optionList = listStr.split(";");
	}else
	{
		listStr = new String(elems["SalesTownList"].value);
		optionList = listStr.split(";");
//alert (listStr)
	}


	for(i = 0;i < optionList.length;i++)
	{
		elems["proptown"].length++;
		elems["proptown"].options[i + 1] = new Option(optionList[i],optionList[i]);
	}

}

function changemlPriceList(){

	var elems,proptype,priceList,optionList,listStr,pArr;

	elems = document.mailinglist.elements
	elems["Price"].length = 0;

	if(elems["proptype"][0].checked)
	{
		proptype = elems["proptype"][0].value;
	}else
	{
		proptype = elems["proptype"][1].value;
	}

	if(proptype == "L")
	{
		listStr = new String(elems["RentPriceList"].value);
		optionList = listStr.split(";");
	}else
	{
		listStr = new String(elems["SalesPriceList"].value);
		optionList = listStr.split(";");
	}


	for(i = 0;i < optionList.length;i++)
	{
		elems["Price"].length++;
		pArr = optionList[i].split("-");
		if(pArr[1] == "")
		{
			elems["Price"].options[i] = new Option(pArr[0] + "+",optionList[i]);
		}else
		{
			elems["Price"].options[i] = new Option(optionList[i],optionList[i]);
		}
	}

}


