var currPhoto = 0;
var prevPhoto = 0;

function rotatePhoto(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 = "resize.asp?File=propertyphotos/" + photoArr[currPhoto] + "&Width=250&Height=250&C=false";


}







var formSent;

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');

		if(confirmBox == true)
		{
			formSent = true;
			return true;
		}else
		{
			formSent = false;
			return false;
		}

	}

}








function validateUpdateDet()
{

		var confirmBox;

		if(formSent == true)
		{
			alert("Please wait... your update request is being processed");
			return false;
		}
	

		confirmBox = confirm('Press OK if you are sure you want to update these details');

		if(confirmBox == true)
		{
			formSent = true;
			return true;
		}else
		{
			formSent = false;
			return false;
		}


}







function validateSendOnce()
{
	if(formSent == true)
	{
		alert("Please wait... your request is being processed");
		return false;
	}else
	{
		formSent = true;
		return true;
	}
}






function setUpPropForm()
{
	hideBeds();
}








function hideBeds()
{
	var elems,proptypeSelect,bedSelect;

	elems = document.propertydet.elements;

	proptypeSelect = elems["propertytype"];
	bedSelect = elems["bedno"];

	if(proptypeSelect.options[proptypeSelect.selectedIndex].value == 'SING' || proptypeSelect.options[proptypeSelect.selectedIndex].value == 'DOUB' || proptypeSelect.options[proptypeSelect.selectedIndex].value == 'BED' || proptypeSelect.options[proptypeSelect.selectedIndex].value == 'ST')
	{
		bedSelect.disabled = true;
		bedSelect.selectedIndex = 2;
		bedSelect.options[bedSelect.selectedIndex].value = 1;
	}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 newImageWindow(theurl,thewidth,theheight){

	newWin = window.open(theurl,'newWindow','width=' + thewidth + ',height=' + theheight + ',toolbar=no,location=no,scrollbars=yes,resizable=yes');

}

function changeCategoryList(allowAny){

	var elems,optionList,listStr,areaResponse,catSelect,subCatSelect,optionParts,reselectAreaIndex,indexAddOn;

	elems = document.propertydet.elements;

	catSelect = elems["category"];
	subCatSelect = elems["subcategory"];


	areaResponse = DoCategoryCallback('getcategories.asp',catSelect.options[catSelect.selectedIndex].value);

	listStr = areaResponse.responseText;
	
	if(listStr.length < 1)
	{
		subCatSelect.length = 1;
		subCatSelect.options[0].text = "No subcategories added for category";
		subCatSelect.options[0].value = "";
		indexAddOn = 1;
	}
	else
	{

		if(allowAny == 'true')
		{
			subCatSelect.length = 1;
			subCatSelect.options[0].text = "Any";
			subCatSelect.options[0].value = "";
			indexAddOn = 1;
		}else
		{
			subCatSelect.length = 1;
			subCatSelect.options[0].text = "Please select a Sub Category (optional)";
			subCatSelect.options[0].value = "";
			indexAddOn = 1;
		}


		optionList = listStr.split(";");

		for(i = 0;i < optionList.length;i++)
		{
			optionParts = optionList[i].split(":");
			subCatSelect.length++;
			subCatSelect.options[i + indexAddOn] = new Option(optionParts[1],optionParts[0]);
	
		}

		/*if(catSelect.options[catSelect.selectedIndex].value == elems["prevTownId"].value)
		{
			subCatSelect.selectedIndex = reselectAreaIndex;
		}*/
	}

}



function DoCategoryCallback(url,catid){
   // url:    URL to invoke
   // params: string object to pass to the remote URL

   // Add some parameters to the query string
   var pageUrl = url + "?Cat=" + catid

   // 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 changePayTypesList(allowAny){

	var elems,optionList,listStr,areaResponse,catSelect,subCatSelect,optionParts,reselectAreaIndex,indexAddOn,tmpStr;

	elems = document.stepone.elements;

	catSelect = elems["type_id"];
	subCatSelect = elems["ptype_id"];


	areaResponse = DoAdvertCallback('getpaytypes.asp',catSelect.options[catSelect.selectedIndex].value);

	listStr = areaResponse.responseText;
		
	
	if(listStr.length < 1)
	{
		subCatSelect.length = 1;
		subCatSelect.options[0].text = "No Payment Options added for Advert Type";
		subCatSelect.options[0].value = "";
		indexAddOn = 1;
	}
	else
	{

		if(allowAny == 'true')
		{
			subCatSelect.length = 1;
			subCatSelect.options[0].text = "Any";
			subCatSelect.options[0].value = "";
			indexAddOn = 1;
		}else
		{
			subCatSelect.length = 1;
			subCatSelect.options[0].text = "Please select a Payment Option";
			subCatSelect.options[0].value = "";
			indexAddOn = 1;
		}


		optionList = listStr.split(";");

		for(i = 0;i < optionList.length;i++)
		{
			
			optionParts = optionList[i].split(":");
			subCatSelect.length++;
			tmpStr = optionParts[1].replace("*","£");
			subCatSelect.options[i + indexAddOn] = new Option(tmpStr,optionParts[0]);
	
		}

		/*if(catSelect.options[catSelect.selectedIndex].value == elems["prevTownId"].value)
		{
			subCatSelect.selectedIndex = reselectAreaIndex;
		}*/
	}

}



function DoAdvertCallback(url,catid){
   // url:    URL to invoke
   // params: string object to pass to the remote URL

   // Add some parameters to the query string
   var pageUrl = url + "?type_id=" + catid

   // 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;
}