Array.prototype.exists = function(o) {
	for(var i = 0; i < this.length; i++)
	   if(this[i] === o)
	     return true;
	return false;
}

var pageMode = "add"; 
var pageName = "propertyIndex";
var userID = 0;
var partnerID = 0;
var allowNewLocation = false; // true | false
var allowUKNewLocation = false;
var allowNewLocation3 = false;
var showPromotedLocation = true;
var deepPromotedIncluded = true;
var groupLocationsByLabel = true;
var showTopLocationsWithPromoted = true;
var isUKProperty = false;
var newLocationParentID = 0;
var autoCompleteInterval = 400;
var autoCompleteInvervalForFifthLevel = 800;
var showUserLocationForFixedLevel = false;
var secondLevelFixedCountries = new Array(
	'Italy',
	'France',
	'Spain'
);
var secondLevelFixedRegions = new Array(
	'Florida'
);
var countiesWithFifthLevel = new Array(
	'Spain','Myanmar'
)
var ajaxIndicatorUrl = 'http://services.themovechannel.com/images/snake_transparent.gif'; 
var countriesRate = ("Afghanistan|GBP|1|26921|1|1|1:Albania|GBP|1|26922|1|1|1:Andorra|GBP|1|101069|1|1|1:Anguilla|GBP|1|26924|1|1|1:Argentina|ARS|0.16621|7923|0.2|0.166|6:Aruba|GBP|1|26927|1|1|1:Australia|AUD|0.457216|5654|0.5|0.457|2:Austria|EUR|0.780869|26928|0.8|0.781|1:Bahrain|BHD|1.333919|26930|1.3|1.334|1:Barbados|GBP|1|26931|1|1|1:Belgium|EUR|0.780869|26932|0.8|0.781|1:Belize|GBP|1|26933|1|1|1:Bolivia|GBP|1|26934|1|1|1:Botswana|GBP|1|7754|1|1|1:Brazil|BRL|0.295377|7840|0.3|0.295|3:Bulgaria|BGL|0.25|5665|0.2|0.25|4:Cambodia|GBP|1|26935|1|1|1:Canada|CAD|0.494326|5662|0.5|0.494|2:Cape Verde|GBP|1|8014|1|1|1:China|CNY|0.071207|26936|0.1|0.071|14:Colombia|COP|0.000266|26937|0|0|3759:Cook Islands|GBP|1|26938|1|1|1:Costa Rica|CRC|0.001|26939|0|0.001|1000:Croatia|GBP|1|5659|1|1|1:Cyprus|EUR|0.780869|5657|0.8|0.781|1:Czech Republic|CZK|0.030689|7999|0|0.031|33:Dominican Republic|GBP|1|26940|1|1|1:Ecuador|GBP|1|26941|1|1|1:Egypt|EGP|0.0912|26942|0.1|0.091|11:Estonia|EEK|0.0498|7902|0|0.05|20:Fiji|GBP|1|7970|1|1|1:Finland|EUR|0.780869|26943|0.8|0.781|1:France|EUR|0.780869|5663|0.8|0.781|1:French Polynesia|GBP|1|26944|1|1|1:Georgia|GBP|1|101742|1|1|1:Germany|EUR|0.780869|8017|0.8|0.781|1:Gibraltar|GBP|1|26945|1|1|1:Greece|EUR|0.780869|5666|0.8|0.781|1:Grenada|GBP|1|26946|1|1|1:Honduras|GBP|1|26947|1|1|1:Hungary|HUF|0.003041|7817|0|0.003|329:India|INR|0.012501|8018|0|0.013|80:Indonesia|IDR|0.000055|26948|0|0|18182:Ireland|EUR|0.780869|26949|0.8|0.781|1:Israel|BZD|0.2537|26950|0.2|0.254|4:Italy|EUR|0.780869|5660|0.8|0.781|1:Jamaica|GBP|1|26951|1|1|1:Jordan|JOD|0.7049|26952|0.7|0.705|1:Kenya|USD|0.501556|26953|0.5|0.502|2:Latvia|EUR|0.780869|8015|0.8|0.781|1:Lithuania|EUR|0.780869|26954|0.8|0.781|1:Malaysia|USD|0.501556|26955|0.5|0.502|2:Malta|GBP|1|5656|1|1|1:Martinique|GBP|1|26956|1|1|1:Mauritius|GBP|1|26957|1|1|1:Mexico|USD|0.501556|26958|0.5|0.502|2:Monaco|GBP|1|26959|1|1|1:Mongolia|GBP|1|26960|1|1|1:Montenegro|GBP|1|101631|1|1|1:Morocco|MAD|0.0679|7975|0.1|0.068|15:Myanmar|GBP|1|26877|1|1|1:Netherlands|GBP|1|26961|1|1|1:Netherlands Antilles|GBP|1|26962|1|1|1:New Zealand|NZD|0.400641|5664|0.4|0.401|2:Nicaragua|GBP|1|26963|1|1|1:Panama|PAB|0.4996|16003|0.5|0.5|2:Philippines|USD|0.501556|26964|0.5|0.502|2:Poland|EUR|0.780869|8016|0.8|0.781|1:Portugal|EUR|0.780869|5661|0.8|0.781|1:Qatar|USD|0.501556|26965|0.5|0.502|2:Romania|EUR|0.780869|7926|0.8|0.781|1:Saudi Arabia|SAR|0.133748|26966|0.1|0.134|7:Serbia and Montenegro|GBP|1|26967|1|1|1:Slovakia|SKK|0.0239|7990|0|0.024|42:Slovenia|GBP|1|26968|1|1|1:South Africa|ZAR|0.062305|6764|0.1|0.062|16:Spain|EUR|0.780869|5605|0.8|0.781|1:Sri Lanka|GBP|1|26969|1|1|1:St Kitts and Nevis|GBP|1|26970|1|1|1:St Lucia|GBP|1|26971|1|1|1:Sweden|SEK|0.082799|26973|0.1|0.083|12:Switzerland|CHF|0.496686|26974|0.5|0.497|2:Thailand|THB|0.015959|7872|0|0.016|63:Tonga|GBP|1|26975|1|1|1:Trinidad and Tobago|GBP|1|26976|1|1|1:Tunisia|EUR|0.780869|26977|0.8|0.781|1:Turkey|EUR|0.780869|5653|0.8|0.781|1:Turks and Caicos Islands|GBP|1|26978|1|1|1:UAE|GBP|1|8381|1|1|1:Ukraine|EUR|0.780869|26979|0.8|0.781|1:Uruguay|GBP|1|26981|1|1|1:USA|USD|0.501556|5658|0.5|0.502|2:Vanuatu|GBP|1|26982|1|1|1:Venezuela|USD|0.501556|8389|0.5|0.502|2:Vietnam|USD|0.501556|26983|0.5|0.502|2").split(":");
var currencyRates = ("GBP|1:USD|2:EUR|1").split(":");
var countries = ("Please Select Country|0:England|35283:Scotland|50505:Wales|50535:Northern Ireland|50558:-----------------|-1:Afghanistan|26921:Albania|26922:Andorra|101069:Anguilla|26924:Antigua and Barbuda|26925:Argentina|7923:Arquipelago dos Acores|26926:Aruba|26927" +
":Australia|5654:Austria|26928:Bahrain|26930:Barbados|26931:Belgium|26932:Belize|26933:Bolivia|26934:Botswana|7754:Brazil|7840:Bulgaria|5665" +
":Cambodia|26935:Canada|5662:Cape Verde|8014:Channel Islands|5655:China|26936:Colombia|26937:Cook Islands|26938:Costa Rica|26939:Croatia|5659" +
":Cyprus|5657:Czech Republic|7999:Dominican Republic|26940:Ecuador|26941:Egypt|26942:Estonia|7902:Fiji|7970:Finland|26943:France|5663:French Polynesia|26944" +
":Georgia|101742:Germany|8017:Gibraltar|26945:Greece|5666:Grenada|26946:Honduras|26947:Hungary|7817:India|8018:Indonesia|26948:Ireland|26949:Israel|26950" +
":Italy|5660:Jamaica|26951:Jordan|26952:Kenya|26953:Latvia|8015:Lithuania|26954:Malaysia|26955:Malta|5656:Martinique|26956:Mauritius|26957:Mexico|26958" +
":Monaco|26959:Mongolia|26960:Montenegro|101631:Morocco|7975:Myanmar|26877:Netherlands|26961:Netherlands Antilles|26962:New Zealand|5664:Nicaragua|26963:Panama|16003" +
":Philippines|26964:Poland|8016:Portugal|5661:Qatar|26965:Romania|7926:Saudi Arabia|26966:Serbia and Montenegro|26967:Slovakia|7990:Slovenia|26968:South Africa|6764" +
":Spain|5605:Sri Lanka|26969:St Kitts and Nevis|26970:St Lucia|26971:St Vincent and the Grenadines|26972:Sweden|26973:Switzerland|26974:Thailand|7872" +
":The Bahamas|26929:Tonga|26975:Trinidad and Tobago|26976:Tunisia|26977:Turkey|5653:Turks and Caicos Islands|26978:UAE|8381:Ukraine|26979:Uruguay|26981" +
":USA|5658:Vanuatu|26982:Venezuela|8389:Vietnam|26983:Virgin Islands (U.S.A.)|26984").split(":");
var UKCountries = ("Please Select Country|0:England|35283:Scotland|50505:Wales|50535:Northern Ireland|50558").split(":");
//var UKCountries = ("England|35283:Scotland|50505:Wales|50535:Northern Ireland|50558").split(":");

var defaultCurrencies = ("Currency|Currency:GBP|GBP:USD|USD:EURO|EUR").split(":");

var Utils = {
	name:"Utility Object",
	trimString:function(str) {
		if (str!=undefined)
		{
			str = this != window? this : str;
			return str.replace(/^\s+/g, '').replace(/\s+$/g, '');}
		else{return '';}
	},
	AddOptionsToDropDown:function(ary,dropdown){
		$j(ary).each(function(index){
			cols = ary[index].split('|');
			var optn = document.createElement("option");
			
			optn.text = cols[0];
			optn.value = cols[1];
			if(showPromotedLocation){
				$j(optn).attr("data",ary[index]);
			}
			$j(dropdown)[0].options.add(optn);
		});
	},
	ClearDropDown: function(obj){
		if(obj.id!=undefined){
			$j('.locationGroup',obj).remove(); }
		if ($j(obj).val()!=null){ 			
			$j(obj).html(''); }
	},
	DropDownSelectByText: function(obj,selectValue){
		var foundItem = false;
	    for (var j = 0; j < obj.options.length; j++) {
			//$("display").innerHTML += list.keys[j] + "<br/>"; //getValue(keys[j]) + "<br/>"; //AjaxPro.toJSON(res.value);
	        if (obj.options[j].text == selectValue){
				obj.options[j].selected = true; 
				foundItem = true;
			}
	    } 
		return foundItem;
	},
	DropDownSelect:function(obj,selectValue){
	        for (var j = 0; j < obj.options.length; j++) {
	                //$("display").innerHTML += list.keys[j] + "<br/>"; //getValue(keys[j]) + "<br/>"; //AjaxPro.toJSON(res.value);
	                if (obj.options[j].value == selectValue)
	                { //alert(selectValue); 
						obj.options[j].selected = true; 
					}
	        } 
	},
	AddOptionToDropDown:function(value,text,dropdown){
		var optn = document.createElement("option");
		optn.text = text;
		optn.value = value;
		$j(dropdown)[0].options.add(optn);
	},
	getCurrencyCode:function(countryName){
		var code = 0;
		$j(countriesRate).each(function(index){
			var data = countriesRate[index].split("|");
			if (countryName == data[0]){
				//alert(data);
				code = data[1];
			}
		});
		return code;
	},
	getCurrencyRate:function(countryName){
		var rate = 1;
		$j(countriesRate).each(function(index){
			var data = countriesRate[index].split("|");
			if (countryName == data[0]){
				//alert(data);
				rate = data[6];
			}
		});
		return rate;
	},
	getCurrencyRateByCurrency:function(currencyCode){
		var rate = 1;
		$j(currencyRates).each(function(index){
			var data = currencyRates[index].split("|");
			//alert(data);
			if (currencyCode == data[0]){
				rate = data[1];
			}
		});
		return rate;
	}
}

var pageSetting = {
	mode:pageMode,
	name:pageName,
	userID:userID,
	country:"",
	region:"",
	location1:"",
	location2:"",
	location3:"",
	locationID:0,
	isUserLoggedIn:false,
	isAdmin:false,
	currency:"GBP",
	partnerID:partnerID,
	baseURL:"http://www.themovechannel.com/",
	pageGUID:"",
	selectedCountry:"",
	selectedRegion:"",
	selectedLocation1:"",
	selectedLocation2:"",
	selectedLocation3:"",
	selectedCountryID:0,
	selectedRegionID:0,
	selectedLocation1ID:0,
	selectedLocation2ID:0,
	selectedLocation3ID:0
}

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        //document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
		document.cookie = [name, '=', value, expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


function FeatureFilterClick(PostLink,FeatureId)
{
	var FeatureID,FeatureIDs; 
	FeatureID = document.searchBox.searchBox_featureID.value; 
	FeatureIDs = document.searchBox.searchBox_featureIDs.value; 
	if (FeatureID =='' || FeatureID =='0')  	 
		document.searchBox.searchBox_featureID.value = FeatureId; 
	else 
		document.searchBox.searchBox_featureIDs.value = FeatureIDs + ','+FeatureId; 	
	//alert(PostLink);
	PostLink = PostLink.replace(/~/g,'/');
	//alert(PostLink);
	//return false;
	document.searchBox.action=PostLink; 
	document.searchBox.submit();
	return false;
}

function RemoveFeatureClick(PostLink,FeatureId,FeatureIds)
{
	javascript:document.searchBox.searchBox_action.value=''; 
	document.searchBox.searchBox_featureID.value = FeatureId; 
	document.searchBox.searchBox_featureIDs.value = FeatureIds;
	PostLink = PostLink.replace(/~/g,'/');	
	document.searchBox.action=PostLink; 
	document.searchBox.submit();
	return false;
}

function SubmitPageToUrl(url)
{
	url = url.replace(/~/g,'/');	
	document.searchBox.action=url; 
	document.searchBox.submit();
	return false;
}


function TypeFilterClick(PostLink,TypeId)
{
	var MainTypeID,SubTypeIDs; 
	MainTypeID = document.searchBox.searchBox_categoryID.value; 
	SubTypeIDs = document.searchBox.searchBox_subCategoryIDs.value; 
	if (MainTypeID =='' || MainTypeID =='0' )  	
		document.searchBox.searchBox_categoryID.value = TypeId; 
	else  	
		document.searchBox.searchBox_subCategoryIDs.value = SubTypeIDs + ','+TypeId; 
	PostLink = PostLink.replace(/~/g,'/');
	document.searchBox.action=PostLink; 
	document.searchBox.submit();
	return false;
}

function RemoveTypeClick(PostLink,TypeId)
{
	 var CategoryID = document.searchBox.searchBox_categoryID.value; 
	 var SubCategoryIDs = document.searchBox.searchBox_subCategoryIDs.value; 
	 if(TypeId == -1)
	 {		
		document.searchBox.searchBox_categoryID.value = ''; 
		document.searchBox.searchBox_subCategoryIDs.value = ''; 
		document.searchBox.searchBox_featureID.value = ''; 
		document.searchBox.searchBox_featureIDs.value = '';		
	 }else
	 {	
		if(CategoryID == TypeId)
			document.searchBox.searchBox_categoryID.value = '';
		document.searchBox.searchBox_subCategoryIDs.value = '';
	 }
	PostLink = PostLink.replace(/~/g,'/');
	document.searchBox.action=PostLink; 
	document.searchBox.submit();
	return false;
}
