function utf8_encode ( argString ) {
	// Encodes an ISO-8859-1 string to UTF-8
	//
	// version: 908.406
	// discuss at: http://phpjs.org/functions/utf8_encode
	// +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   improved by: sowberry
	// +    tweaked by: Jack
	// +   bugfixed by: Onno Marsman
	// +   improved by: Yves Sucaet
	// +   bugfixed by: Onno Marsman
	// *     example 1: utf8_encode('Kevin van Zonneveld');
	// *     returns 1: 'Kevin van Zonneveld'
	var string = (argString+'').replace(/\r\n/g, "\n").replace(/\r/g, "\n");

	var utftext = "";
	var start, end;
	var stringl = 0;

	start = end = 0;
	stringl = string.length;
	for (var n = 0; n < stringl; n++) {
		var c1 = string.charCodeAt(n);
		var enc = null;

		if (c1 < 128) {
			end++;
		} else if (c1 > 127 && c1 < 2048) {
			enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
		} else {
			enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
		}
		if (enc !== null) {
			if (end > start) {
				utftext += string.substring(start, end);
			}
			utftext += enc;
			start = end = n+1;
		}
	}

	if (end > start) {
		utftext += string.substring(start, string.length);
	}

	return utftext;
}

function utf8_decode ( str_data ) {
	// Converts a UTF-8 encoded string to ISO-8859-1
	//
	// version: 905.3122
	// discuss at: http://phpjs.org/functions/utf8_decode
	// +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
	// +      input by: Aman Gupta
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   improved by: Norman "zEh" Fuchs
	// +   bugfixed by: hitwork
	// +   bugfixed by: Onno Marsman
	// +      input by: Brett Zamir (http://brett-zamir.me)
	// +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// *     example 1: utf8_decode('Kevin van Zonneveld');
	// *     returns 1: 'Kevin van Zonneveld'
	var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0;

	str_data += '';

	while ( i < str_data.length ) {
		c1 = str_data.charCodeAt(i);
		if (c1 < 128) {
			tmp_arr[ac++] = String.fromCharCode(c1);
			i++;
		} else if ((c1 > 191) && (c1 < 224)) {
			c2 = str_data.charCodeAt(i+1);
			tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
			i += 2;
		} else {
			c2 = str_data.charCodeAt(i+1);
			c3 = str_data.charCodeAt(i+2);
			tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
			i += 3;
		}
	}

	return tmp_arr.join('');
}

function base64_encode (data) {
	// Encodes string using MIME base64 algorithm
	//
	// version: 908.406
	// discuss at: http://phpjs.org/functions/base64_encode
	// +   original by: Tyler Akins (http://rumkin.com)
	// +   improved by: Bayron Guevara
	// +   improved by: Thunder.m
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   bugfixed by: Pellentesque Malesuada
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// -    depends on: utf8_encode
	// *     example 1: base64_encode('Kevin van Zonneveld');
	// *     returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='
	// mozilla has this native
	// - but breaks in 2.0.0.12!
	//if (typeof this.window['atob'] == 'function') {
	//    return atob(data);
	//}

	var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, enc="", tmp_arr = [];

	if (!data) {
		return data;
	}

	data = this.utf8_encode(data+'');

	do { // pack three octets into four hexets
		o1 = data.charCodeAt(i++);
		o2 = data.charCodeAt(i++);
		o3 = data.charCodeAt(i++);

		bits = o1<<16 | o2<<8 | o3;

		h1 = bits>>18 & 0x3f;
		h2 = bits>>12 & 0x3f;
		h3 = bits>>6 & 0x3f;
		h4 = bits & 0x3f;

		// use hexets to index into b64, and append result to encoded string
		tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
	} while (i < data.length);

	enc = tmp_arr.join('');

	switch (data.length % 3) {
		case 1:
		enc = enc.slice(0, -2) + '==';
		break;
		case 2:
		enc = enc.slice(0, -1) + '=';
		break;
	}

	return enc;
}

function base64_decode (data) {
	// Decodes string using MIME base64 algorithm
	//
	// version: 908.406
	// discuss at: http://phpjs.org/functions/base64_decode
	// +   original by: Tyler Akins (http://rumkin.com)
	// +   improved by: Thunder.m
	// +      input by: Aman Gupta
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   bugfixed by: Onno Marsman
	// +   bugfixed by: Pellentesque Malesuada
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +      input by: Brett Zamir (http://brett-zamir.me)
	// +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// -    depends on: utf8_decode
	// *     example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==');
	// *     returns 1: 'Kevin van Zonneveld'
	// mozilla has this native
	// - but breaks in 2.0.0.12!
	//if (typeof this.window['btoa'] == 'function') {
	//    return btoa(data);
	//}

	var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = "", tmp_arr = [];

	if (!data) {
		return data;
	}

	data += '';

	do {  // unpack four hexets into three octets using index points in b64
		h1 = b64.indexOf(data.charAt(i++));
		h2 = b64.indexOf(data.charAt(i++));
		h3 = b64.indexOf(data.charAt(i++));
		h4 = b64.indexOf(data.charAt(i++));

		bits = h1<<18 | h2<<12 | h3<<6 | h4;

		o1 = bits>>16 & 0xff;
		o2 = bits>>8 & 0xff;
		o3 = bits & 0xff;

		if (h3 == 64) {
			tmp_arr[ac++] = String.fromCharCode(o1);
		} else if (h4 == 64) {
			tmp_arr[ac++] = String.fromCharCode(o1, o2);
		} else {
			tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
		}
	} while (i < data.length);

	dec = tmp_arr.join('');
	dec = this.utf8_decode(dec);

	return dec;
}

function str_replace (search, replace, subject, count) {
	// Replaces all occurrences of search in haystack with replace
	//
	// version: 909.322
	// discuss at: http://phpjs.org/functions/str_replace
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   improved by: Gabriel Paderni
	// +   improved by: Philip Peterson
	// +   improved by: Simon Willison (http://simonwillison.net)
	// +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
	// +   bugfixed by: Anton Ongson
	// +      input by: Onno Marsman
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +    tweaked by: Onno Marsman
	// +      input by: Brett Zamir (http://brett-zamir.me)
	// +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   input by: Oleg Eremeev
	// +   improved by: Brett Zamir (http://brett-zamir.me)
	// +   bugfixed by: Oleg Eremeev
	// %          note 1: The count parameter must be passed as a string in order
	// %          note 1:  to find a global variable in which the result will be given
	// *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
	// *     returns 1: 'Kevin.van.Zonneveld'
	// *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
	// *     returns 2: 'hemmo, mars'
	var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
	f = [].concat(search),
	r = [].concat(replace),
	s = subject,
	ra = r instanceof Array, sa = s instanceof Array;
	s = [].concat(s);
	if (count) {
		this.window[count] = 0;
	}

	for (i=0, sl=s.length; i < sl; i++) {
		if (s[i] === '') {
			continue;
		}
		for (j=0, fl=f.length; j < fl; j++) {
			temp = s[i]+'';
			repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
			s[i] = (temp).split(f[j]).join(repl);
			if (count && s[i] !== temp) {
				this.window[count] += (temp.length-s[i].length)/f[j].length;}
		}
	}
	return sa ? s : s[0];
}

// Validate
function Mid(str, start, len) {
	// Make sure start and len are within proper bounds
	if (start < 0 || len < 0) return "";

	var iEnd, iLen = String(str).length;
	if (start + len > iLen) {
		iEnd = iLen;
	} else {
		iEnd = start + len;
	}
	return String(str).substring(start,iEnd);
}

function inStr(strSearch, charSearchFor) {
	for (i=0; i < strSearch.length; i++) {
		if (charSearchFor == Mid(strSearch, i, 1)) {
			return i;
		}
	}
	return -1;
}

function validateNumeric(thi,dec,e) {
	var key;
	var keychar;

	if (window.event) {
		key = window.event.keyCode;
	} else if (e) {
		key = e.which;
	} else {
		return true;
	}

	keyCode = key;

	if (((thi.value).indexOf('.') > -1) && key == 46) {
		return false;
	}

	if (keyCode > 31 && (keyCode < 48 || keyCode > 57) && keyCode != 46)
	return false;

	var Pat = /^[0-9,]{1,}.{0,1}[0-9]{0,2}$/;

	strCheck = thi.value;
	//alert(strCheck.length);
	if(strCheck.length > 0) {
		var matchArray = strCheck.match(Pat); // is the format ok?

		if (matchArray == null) {
			thi.value = strCheck.substring(0,strCheck.length-1);
			return false;
		}
	}

	return true;
}

function validateNumber() {
	var key;
	var keychar;

	if (window.event) {
		key = window.event.keyCode;
	} else if (e) {
		key = e.which;
	} else {
		return true;
	}

	keyCode = key;

	if (((keyCode < 48) || (keyCode> 57))) {
		//event.returnValue = false;
		return false;
	}
}

// Spotlight & Detail
//jQuery(document).ready(function() {
//	// Initialise the first and second carousel by class selector.
//	// Note that they use both the same configuration options (none in this case).
//	jQuery('.carousel').jcarousel();
//});
jQuery(document).ready(function() {
	// Initialise the first and second carousel by class selector.
	// Note that they use both the same configuration options (none in this case).
	jQuery('.carousel').jcarousel({

		buttonNextCallback: mycarousel_buttonNextCallback

	});
});

var mycarousel_buttonNextCallback = function(carousel, button, enabled){
	if(!enabled)
	carousel.scroll(jQuery.jcarousel.intval(1) );
};
// Search & Spotlight

function onblurQuickSearch(o) {
	if (o.value == "") {
		o.value = "Ref No / Address / Location / Price / Contact";
	}
}

function onclickQuickSearch(o) {
	if (o.value == "Ref No / Address / Location / Price / Contact") {
		o.value = "";
	}
}

function submitSaleQuickSearch(o) {
	//var TabbedPanelsClassified = new Spry.Widget.TabbedPanels("TabbedPanelsClassified");
	//var curIndex = TabbedPanelsClassified.getCurrentTabIndex();

	//var category = eval('o.form.tabclassified'+curIndex+'.value');
	var category = getTabClassified();

	if (o.form.quick_search.value == 'Ref No / Address / Location / Price / Contact') {
		o.form.quick_search.value = '';
	}

	o.form.quick_search_filter.value = '1';
	o.form.quick_search_list_type.value = 'Sale';

	submitSearch(o, category);
}

function submitRentQuickSearch(o) {
	//var TabbedPanelsClassified = new Spry.Widget.TabbedPanels("TabbedPanelsClassified");
	//var curIndex = TabbedPanelsClassified.getCurrentTabIndex();

	//var category = eval('o.form.tabclassified'+curIndex+'.value');
	var category = getTabClassified();

	if (o.form.quick_search.value == 'Ref No / Address / Location / Price / Contact') {
		o.form.quick_search.value = '';
	}

	o.form.quick_search_filter.value = '1';
	o.form.quick_search_list_type.value = 'Rent';

	submitSearch(o, category);
}

function submitQuickSearch(o) {
	//var TabbedPanelsClassified = new Spry.Widget.TabbedPanels("TabbedPanelsClassified");
	//var curIndex = TabbedPanelsClassified.getCurrentTabIndex();

	//var category = eval('o.form.tabclassified'+curIndex+'.value');
	var category = getTabClassified();

	if (o.form.quick_search.value == 'Ref No / Address / Location / Price / Contact') {
		o.form.quick_search.value = '';
	}

	o.form.quick_search_filter.value = '1';
	o.form.quick_search_list_type.value = '';

	submitSearch(o, category);
}

function getTabClassified(){
	var classified = '';

	switch (tabClassifiedClick){
		case 1:
		classified = 'R';
		break;

		case 2:
		classified = 'C';
		break;

		case 3:
		classified = 'L';
		break;

		case 4:
		classified = 'S';
		break;

		case 5:
		classified = 'N';
		break;
	}
	return classified;
}


var minNum=1; var maxNum=3;
function checkListBoxSize(){
	oSelect=document.getElementById("category_id");
	var count=0;
	for(var i=0;i<oSelect.options.length;i++){
		if(oSelect.options[i].selected)
		count++;
		if(count>maxNum){
			alert("Can't select more than 3");
			return false;
		}
	}
	if(count<1){
		alert("Must select at least one item");
		return false;
	}
	return true;
}

function submitAdvanceSearch(o) {

	var classified_search = new String();
	var search_encode = new String();
	var search_field = new String("sale,rent,country,state,location,postcode,classified_category,classified_type,unit_type,tenure,sale_price_from,sale_price_to,rent_price_from,rent_price_to,sale_price_psf,rent_price_psf,no_of_storeys_from,no_of_storeys_to,bedrooms_from,bedrooms_to,bathrooms_from,bathrooms_to,parking_from,parking_to,built_up_from,built_up_x_to,built_up_to,built_up_uom,land_area_from,land_area_x_to,land_area_to,land_area_uom,others,only_with_images,only_with_video,only_with_audio");

	search_key = search_field.split(',');

	//classified_search = '&classified_category=' + category;
	for (i=0; i<search_key.length; i++) {
		field = search_key[i];
		//handle checkbox
		switch (field) {
			case "sale" :
			case "rent" :
			case "only_with_images" :
			case "only_with_video" :
			case "only_with_audio" :
			if (document.getElementById(search_key[i]).checked) {
				classified_search = classified_search + '&' + search_key[i] + '=' + document.getElementById(search_key[i]).value;
			}
			break;

			//handle miltiper
			case "others" :
			var count = 0;
			var tableBody = document.getElementById('others').tBodies[0];
			for (n=0; n<tableBody.rows.length-1; n++) {
				var tableRowColumn = tableBody.rows[n];
				for (x=0; x<4; x++){
					if (tableRowColumn.cells[x].childNodes[0]){
						if (tableRowColumn.cells[x].childNodes[0].checked){
							classified_search = classified_search + '&' + search_key[i] + '['+count+']=' + tableRowColumn.cells[x].childNodes[0].value;
							count++;
						}
					}
				}
			}
			break;

			default :
			classified_search = classified_search + '&' + search_key[i] + '=' + document.getElementById(search_key[i]).value;
		}
	}

	//	//quick_search
	//	if (o.form.quick_search.value == 'Ref No / Address / Location / Price / Contact') {
	//		o.form.quick_search.value = '';
	//	}
	//
	//	if (o.form.quick_search_filter.value == 0) {
	//		o.form.quick_search_list_type.value = '';
	//	}
	//
	//	classified_search = classified_search + '&quick_search=' + o.form.quick_search.value;
	//	classified_search = classified_search + '&quick_search_filter=' + o.form.quick_search_filter.value;
	//	classified_search = classified_search + '&quick_search_list_type=' + o.form.quick_search_list_type.value;

	search_encode = base64_encode(classified_search);

	itemid = o.form.Itemid.value;

	o.form.action='index.php?option=com_classified&task=search&view=classified&layout=search&Itemid='+itemid+'&search='+search_encode;
	//o.form.classified_category.value=category;
	o.form.submit();
}

function submitMyRSS(){
	
	var rss_code = document.adminForm.rss_code.value;
	var url = "index.php?option=com_classified&task=saveMyRSS&search=" + rss_code;
	var a = new Ajax(url,{
		method:"get",
		onComplete: function(response) {
			link = 'http://' + location.host + '/mobile/module/mobile/index3.php?search=' + rss_code;
			//link = 'http://www.theedgeproperty.com/mobile/module/mobile/index3.php?search=' + rss_code;
			window.open(link, "classified_rss");
		}
	}).request();
}

function submitMyEmail(){
	
	var email_code = document.adminForm.email_code.value;
	var url = "index.php?option=com_classified&task=saveMyEmail&search=" + email_code;
	var a = new Ajax(url,{
		method:"get",
		onComplete: function(response) {
			alert('Your subscription successfully! Thank you!');
		}
	}).request();
}

function submitReset(o, category){

	var classified_search = new String();
	var search_encode = new String();
	var search_field = new String("sale,rent,country,state,location,classified_type,price_from,price_to,bedrooms_from,bedrooms_to,bathrooms_from,bathrooms_to,keywords");

	classified_search = '&classified_category=' + category;
	
	search_key = search_field.split(',');
	for (i=0; i<search_key.length; i++) {
		field = search_key[i];
		//handle checkbox
		switch (field) {
			case "sale" :
			case "rent" :
			break;

			default :
			classified_search = classified_search + '&' + search_key[i] + '=';
		}
	}
	
	o.form.quick_search.value = '';
	o.form.quick_search_list_type.value = '';

	classified_search = classified_search + '&quick_search=' + o.form.quick_search.value;
	classified_search = classified_search + '&quick_search_filter=' + o.form.quick_search_filter.value;
	classified_search = classified_search + '&quick_search_list_type=' + o.form.quick_search_list_type.value;

	search_encode = base64_encode(classified_search);

	itemid = o.form.Itemid.value;

	o.form.action='index.php?option=com_classified&task=search&view=classified&layout=search&Itemid='+itemid+'&search='+search_encode;
	o.form.classified_category.value=category;
	o.form.sort.value='reset';
	o.form.submit();
}

function submitSearch(o, category) {

	var classified_search = new String();
	var search_encode = new String();
	var search_field = new String("sale,rent,country,state,location,classified_type,price_from,price_to,bedrooms_from,bedrooms_to,bathrooms_from,bathrooms_to,keywords");

	classified_search = '&classified_category=' + category;

	search_key = search_field.split(',');
	for (i=0; i<search_key.length; i++) {
		field = search_key[i];
		//handle checkbox
		switch (field) {
			case "sale" :
			if (document.getElementById(category+search_key[i]).checked) {
				classified_search = classified_search + '&' + search_key[i] + '=' + document.getElementById(category+search_key[i]).value;
			}
			break;

			case "rent" :
			if (document.getElementById(category+search_key[i]).checked) {
				classified_search = classified_search + '&' + search_key[i] + '=' + document.getElementById(category+search_key[i]).value;
			}
			break;

			default :
			classified_search = classified_search + '&' + search_key[i] + '=' + document.getElementById(category+search_key[i]).value;
		}
	}

	//quick_search
	if (o.form.quick_search.value == 'Ref No / Address / Location / Price / Contact') {
		o.form.quick_search.value = '';
	}

	if (o.form.quick_search_filter.value == 0) {
		o.form.quick_search_list_type.value = '';
	}

	classified_search = classified_search + '&quick_search=' + o.form.quick_search.value;
	classified_search = classified_search + '&quick_search_filter=' + o.form.quick_search_filter.value;
	classified_search = classified_search + '&quick_search_list_type=' + o.form.quick_search_list_type.value;

	search_encode = base64_encode(classified_search);

	itemid = o.form.Itemid.value;

	o.form.action='index.php?option=com_classified&task=search&view=classified&layout=search&Itemid='+itemid+'&search='+search_encode;
	o.form.classified_category.value=category;
	o.form.submit();
}

function submitSearch_v2(o, category) {

	var classified_search = new String();
	var search_encode = new String();
	var search_field = new String("sale,rent,state,location,classified_type,price_from,price_to,tenure,bedrooms_from,bedrooms_to,bathrooms_from,bathrooms_to");

	search_key = search_field.split(',');

	classified_search = '&classified_category=' + category;
	for (i=0; i<search_key.length; i++) {
		field = search_key[i];
		//handle checkbox
		switch (field) {
			case "sale" :
			if (document.getElementById(category+search_key[i]).checked) {
				classified_search = classified_search + '&' + search_key[i] + '=' + document.getElementById(category+search_key[i]).value;
			}
			break;

			case "rent" :
			if (document.getElementById(category+search_key[i]).checked) {
				classified_search = classified_search + '&' + search_key[i] + '=' + document.getElementById(category+search_key[i]).value;
			}
			break;

			//handle miltiper
			case "classified_type" :
			var count=0;
			var classified_type_multiple = document.getElementById(category+search_key[i]);
			for(var n=0;n<classified_type_multiple.options.length;n++){
				if(classified_type_multiple.options[n].selected){
					count++;
					classified_search = classified_search + '&' + search_key[i] + count + '=' + classified_type_multiple.options[n].value;
				}
			}
			break;

			default :
			classified_search = classified_search + '&' + search_key[i] + '=' + document.getElementById(category+search_key[i]).value;
		}
	}

	//quick_search
	if (o.form.quick_search.value == 'Ref No / Address / Location / Price / Contact') {
		o.form.quick_search.value = '';
	}

	if (o.form.quick_search_filter.value == 0) {
		o.form.quick_search_list_type.value = '';
	}

	classified_search = classified_search + '&quick_search=' + o.form.quick_search.value;
	classified_search = classified_search + '&quick_search_filter=' + o.form.quick_search_filter.value;
	classified_search = classified_search + '&quick_search_list_type=' + o.form.quick_search_list_type.value;

	search_encode = base64_encode(classified_search);

	itemid = o.form.Itemid.value;

	o.form.action='index.php?option=com_classified&task=search&view=classified&layout=search&Itemid='+itemid+'&search='+search_encode;
	o.form.classified_category.value=category;
	o.form.submit();
}

// Entry

function submitbutton(pressbutton) {
	var form = document.adminForm;

	switch (pressbutton) {
		case "apply" :
		case "save" :
			if (form.contact_first_name.value == "") {
				alert( form.err_contact_first_name.value );
			} else if (form.contact_last_name.value == "") {
				alert( form.err_contact_last_name.value );
				//} else if (form.contact_mobile.value == "" && form.contact_office.value == "") {
				//	alert( form.err_contact_mobile.value );
			} else if (form.classified_category_code.value == "0") {
				alert( form.err_classified_category_code.value );
			} else if (form.classified_type_code.value == "0") {
				alert( form.err_classified_type_code.value );
				//} else if (form.property_type.value == form.is_one.value) {
				//	alert( form.err_property_type.value );
			} else if (form.list_type.value == form.is_one.value) {
				alert( form.err_list_type.value );
				//} else if (form.no_of_bedrooms.value == form.is_one.value) {
				//	alert( form.err_no_of_bedrooms.value );
				//} else if (form.no_of_bathrooms.value == form.is_one.value) {
				//	alert( form.err_no_of_bathrooms.value );
				//} else if (form.no_of_parking.value == "") {
				//	alert( form.err_no_of_parking.value );
				//} else if (form.built_up.value == "") {
				//	alert( form.err_built_up.value );
				//} else if (form.built_up_from.value == "") {
				//	alert( form.err_built_up.value );
				//} else if (form.built_up_to.value == "") {
				//	alert( form.err_built_up.value );
				//} else if (form.land_area.value == "") {
				//	alert( form.err_land_area.value );
			} else if (form.tenure.value == form.is_one.value) {
				alert( form.err_tenure.value );
			} else if (form.address.value == "") {
				alert( form.err_address.value );
			} else if (form.state.value == form.is_one.value) {
				alert( form.err_state.value );
			} else if (form.location.value == "") {
				alert( form.err_location.value );
			} else {
				submitform( pressbutton );
				return;
			}
		break;

		case "preview" :
		document.previewForm.action='';
		document.previewForm.method='post';
		document.previewForm.target='_blank';
		document.previewForm.view.value='classified';
		document.previewForm.task.value='preview';
		document.previewForm.submit();
		break;

		case "import" :
		//document.importForm.action='';
		document.importForm.method='post';
		document.importForm.target='_self';
		document.importForm.view.value='backend';
		document.importForm.task.value='import';
		document.importForm.submit();
		break;

		case "export" :
		//document.exportForm.action='';
		document.exportForm.method='post';
		document.exportForm.target='_blank';
		document.exportForm.view.value='backend';
		document.exportForm.task.value='export';
		
		if (form.filter_classifiedcompany) {
			document.exportForm.cid.value=form.filter_classifiedcompany.value;
		}
		
		if (form.filter_classifiedcompanyuser) {
			document.exportForm.uid.value=form.filter_classifiedcompanyuser.value;
		}
		
		var count = document.exportForm.count.value;
		var rid = new String();
		for (i=0; i<count; i++) {
			checked = eval('form.cb'+i+'.checked');
			
			if (checked){
				value = eval('form.cb'+i+'.value');
				if (rid == '') {
					rid = value;
				}else{
					rid = rid + ',' + value;
				}
			}
		}
		document.exportForm.rid.value=rid;
		document.exportForm.submit();
		break;

		case "list" :
		document.adminForm.action='index.php?option=com_classified&view=backend&layout=list&task=list';
		document.adminForm.method='post';
		document.adminForm.target='_self';
		//document.adminForm.view.value='backend';
		document.adminForm.layout.value='list';
		document.adminForm.task.value='list';
		document.adminForm.submit();
		break;
		
		case "transfer" :
			if (form.classifiedtransferuser.value == "" || form.classifiedtransferuser.value == "0") {
				alert( form.err_classifiedtransferuser.value );
				form.classifiedtransferuser.focus();
			}else{
				document.adminForm.action='index.php?option=com_classified&view=backend&layout=list&task=list';
				document.adminForm.method='post';
				document.adminForm.target='_self';
				document.adminForm.layout.value='list';
				document.adminForm.task.value='transfer';
				document.adminForm.submit();
			}
		break;

		default:
		submitform( pressbutton );
		return;
	}
}

function submitPreview() {
	var view = document.adminForm.view.value;
	var task = document.adminForm.task.value;
	document.adminForm.action='';
	document.adminForm.method='post';
	document.adminForm.target='_blank';
	document.adminForm.view.value='classified';
	document.adminForm.task.value='preview';
	document.adminForm.submit();
	document.adminForm.target='_self';
	document.adminForm.view.value=view;
	document.adminForm.task.value=task;
}

//Preview & Detail

function alertTask(count, task, login) {
	if (login){
		var form = document.adminForm;

		eval('document.adminForm.alert'+count+'.checked=true');

		document.adminForm.task.value=task;

		submitform( );
	}else{
		requestLogin('Alert');
	}
}

function alertAllTask(count, task) {
	var form = document.adminForm;

	for (i=0; i<count; i++)
	{
		eval('document.adminForm.alert'+i+'.checked=true');
	}

	document.adminForm.task.value=task;

	submitform( );
}

function favoriteTask(count, task, login) {
	if (login){
		var form = document.adminForm;

		eval('document.adminForm.favorite'+count+'.checked=true');

		document.adminForm.task.value=task;

		submitform( );
	}else{
		requestLogin('Alert');
	}
}

function favoriteAllTask(count, task) {
	var form = document.adminForm;

	for (i=0; i<count; i++)
	{
		eval('document.adminForm.favorite'+i+'.checked=true');
	}

	document.adminForm.task.value=task;

	submitform( );
}

function myrssTask(count, task, login) {
	if (login){
		var form = document.adminForm;

		eval('document.adminForm.myrss'+count+'.checked=true');

		document.adminForm.task.value=task;

		submitform( );
	}else{
		requestLogin('MyRSS');
	}
}

function myemailTask(count, task, login) {
	if (login){
		var form = document.adminForm;

		eval('document.adminForm.myemail'+count+'.checked=true');

		document.adminForm.task.value=task;

		submitform( );
	}else{
		requestLogin('MyEmail');
	}
}

function ajxLoadObject(data, type) {
	var url = "index.php?option=com_classified&task=loadmultimedia&type="+escape(type)+"&data="+escape(data);
	var a = new Ajax(url,{
		method:"get",
		onComplete: function(response) {
			$("load-container").setHTML(response);
		}
	}).request();
}

function ajxSendEnquiry() {
	var data = document.getElementById('reference_no').value;
	var msg = document.getElementById('enquiry_message').value;
	var url = "index.php?option=com_classified&task=sendenquiry&data="+escape(data)+"&msg="+escape(msg);
	var a = new Ajax(url,{
		method:"get",
		onComplete: function(response) {
			if (response == 1) {
				document.getElementById('enquiry_message').value = '';
				alert('Your email enquiry has been sent. Thank you.!');
			} else {
				alert('Please try again later!');
			}
		}
	}).request();
}

function moreSpotlight(category) {
	var classified_search = new String();
	var search_encode = new String();

	classified_search = '&classified_category=' + category;

	classified_search = classified_search + '&quick_search=';

	search_encode = base64_encode(classified_search);

	itemid = document.searchForm.Itemid.value;

	document.searchForm.action='index.php?option=com_classified&task=search&view=classified&layout=search&Itemid='+itemid+'&search='+search_encode;
	document.searchForm.classified_category.value=category;
	document.searchForm.sort.value='reset';
	document.searchForm.submit();
}

function onchangeCategory(category, first) {
	var url = "index.php?option=com_classified&task=loadclassifiedtype&category="+escape(category.value)+'&first='+escape(first);
	var a = new Ajax(url,{
		method:"get",
		onComplete: function(response) {
			$("div_classified_type_code").setHTML(response);
		}
	}).request();
}

function onchangeListType(type) {
	switch (type.value) {
		case "Sale":
		document.getElementById("tr_sale_price").style.display="";
		document.getElementById("tr_sale_price_psf").style.display="";
		document.getElementById("tr_rent_price").style.display="none";
		document.getElementById("tr_rent_price_psf").style.display="none";
		break;

		case "Rent":
		document.getElementById("tr_sale_price").style.display="none";
		document.getElementById("tr_sale_price_psf").style.display="none";
		document.getElementById("tr_rent_price").style.display="";
		document.getElementById("tr_rent_price_psf").style.display="";
		break;

		case "Sale & Rent":
		document.getElementById("tr_sale_price").style.display="";
		document.getElementById("tr_sale_price_psf").style.display="";
		document.getElementById("tr_rent_price").style.display="";
		document.getElementById("tr_rent_price_psf").style.display="";
		break;
	}

	//document.getElementById("sale_price").value="0.00";
	//document.getElementById("sale_price_psf").value="0.00";
	//document.getElementById("rent_price").value="0.00";
	//document.getElementById("rent_price_psf").value="0.00";
}

function setMyAlert(count, task, login) {
	if (login){
		
	}else{
		requestLogin('Alert');
	}
}

function setMyAlertKeyword(count, category, type, state, location, address) {
	keyword = (prompt("Address Keyword", address))
	if (keyword == null) {
		return false;
	}else{
		var url = "index.php?option=com_classified&task=savemyalert&layout=myalert";
		url = url + "&classified_category_code="+escape(category);
		url = url + "&classified_type_code="+escape(type);
		url = url + "&state="+escape(state);
		url = url + "&location="+escape(location);
		url = url + "&address="+escape(keyword);
		var a = new Ajax(url,{
			method:"post",
			onComplete: function(response) {
				alert('My Alerts save successfully!');
				//document.getElementById('img_alert_'+count).src = "/edgeproperty/images/alert.gif";
				document.getElementById('img_alert_'+count).src = "/images/alert.gif";
			}
		}).request();
	}
}

function setAlert(count, task, login) {
	if (login){
		var numAlert = document.adminForm.num_alert.value;
		var imgFalse = 'alert_x.gif';
		var imgTrue = 'alert.gif';

		if (eval('document.adminForm.is_alert'+count+'.value') == 1)
		{
			imgCurrent = eval('document.adminForm.img_alert'+count+'.src');
			imgChange = str_replace(imgTrue, imgFalse, imgCurrent);
			recCurrent = eval('document.adminForm.rec_alert'+count+'.value');
			recChange = 0;
		} else {
			imgCurrent = eval('document.adminForm.img_alert'+count+'.src');
			imgChange = str_replace(imgFalse, imgTrue, imgCurrent);
			recCurrent = eval('document.adminForm.rec_alert'+count+'.value');
			recChange = 1;
		}

		for (i=0; i<numAlert; i++)
		{
			if (recCurrent == eval('document.adminForm.rec_alert'+i+'.value'))
			{
				eval('document.adminForm.is_alert'+i+'.value='+recChange);
				eval('document.adminForm.img_alert'+i+'.src="'+imgChange+'";');
			}
		}
	}else{
		requestLogin('Alert');
	}
}

function saveAlert(login) {
	if (login){
		var form = document.adminForm;

		document.adminForm.task.value='updatealert';

		submitform( );
	}else{
		requestLogin('Favorite');
	}
}

function setFavorite(count, task, login) {
	if (login){
		var imgFalse = 'watchlist_x.gif';
		var imgTrue = 'watchlist.gif';

		if (eval('document.adminForm.is_favorite'+count+'.value') == 1)
		{
			imgCurrent = eval('document.adminForm.img_favorite'+count+'.src');
			imgChange = str_replace(imgTrue, imgFalse, imgCurrent);
			recCurrent = eval('document.adminForm.rec_favorite'+count+'.value');
			recChange = 0;
		} else {
			imgCurrent = eval('document.adminForm.img_favorite'+count+'.src');
			imgChange = str_replace(imgFalse, imgTrue, imgCurrent);
			recCurrent = eval('document.adminForm.rec_favorite'+count+'.value');
			recChange = 1;
		}

		eval('document.adminForm.is_favorite'+count+'.value='+recChange);
		eval('document.adminForm.img_favorite'+count+'.src="'+imgChange+'";');
	}else{
		requestLogin('Favorite');
	}
}

function saveFavorite(login) {
	if (login){
		var form = document.adminForm;

		document.adminForm.task.value='updatefavorite';

		submitform( );
	}else{
		requestLogin('Favorite');
	}
}

function requestLogin(type){
	var message = '';

	switch (type){
		case "Sort" :
		message = 'You have to be logged in to Sort the listings using the selected column.';
		message = message + ' Please Login or Register. Registration is FREE. Thank you.';
		break;

		case "Alert" :
		case "Favorite" :
		message = 'You have to be logged in to set an Alert or bookmark a listing for your Watchlist.';
		message = message + ' Please login or Register. Registration is FREE. Thank you.';
		break;
		
		case "MyRSS" :
		message = 'You have to be logged in to subscribe My Search RSS.';
		message = message + ' Please login or Register. Registration is FREE. Thank you.';
		break;
		
		case "MyEmail" :
		message = 'You have to be logged in to subscribe My Search Email.';
		message = message + ' Please login or Register. Registration is FREE. Thank you.';
		break;
	}

	alert(message);
}

function textCounter(field, cntfield, maxlimit) {
	if (field.value.length > maxlimit) {
		// if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	} else {
		// otherwise, update 'characters left' counter
		cntfield.value = maxlimit - field.value.length;
	}
}

function deletePhoto(count, task) {
	el = document.getElementById('table_img_photo'+count).tBodies[0].rows;
	el[0].cells[0].childNodes[0].setAttribute("style","display:none");
	el[1].cells[1].childNodes[0].value = '';
	if (el[1].cells[1].childNodes[0].value == ''){
		el[1].cells[2].childNodes[0].setAttribute("style","display:none");
	}else{
		el[1].cells[2].childNodes[0].setAttribute("style","display:");
	}
	// fixed IE height when display:none
	document.getElementById('label_photo'+count).setAttribute("style","height:50px");
}

// not used
function deletePlan(count, task) {
	var form = document.adminForm;

	eval('document.adminForm.plan'+count+'.checked=true');

	document.adminForm.task.value=task;

	submitform( );
}

function urlPhoto(id){
	el = document.getElementById(id).tBodies[0].rows;
	el[1].cells[0].childNodes[0].setAttribute("style","display:none");
	el[1].cells[0].childNodes[1].setAttribute("style","display:");
	el[1].cells[1].childNodes[0].setAttribute("style","display:");
	el[1].cells[1].childNodes[1].setAttribute("style","display:none");
	if (el[1].cells[1].childNodes[0].value == ''){
		el[1].cells[2].childNodes[0].setAttribute("style","display:none");
	}else{
		el[1].cells[2].childNodes[0].setAttribute("style","display:");
	}
	el[1].cells[3].childNodes[0].setAttribute("style","display:none;font-size:10px");
	el[2].setAttribute("style","display:none");
}

function uploadPhoto(id){
	el = document.getElementById(id).tBodies[0].rows;
	el[1].cells[0].childNodes[0].setAttribute("style","display:");
	el[1].cells[0].childNodes[1].setAttribute("style","display:none");
	el[1].cells[1].childNodes[0].setAttribute("style","display:none");
	el[1].cells[1].childNodes[1].setAttribute("style","display:");
	if (el[1].cells[1].childNodes[0].value == ''){
		el[1].cells[2].childNodes[0].setAttribute("style","display:none");
	}else{
		el[1].cells[2].childNodes[0].setAttribute("style","display:");
	}
	el[1].cells[3].childNodes[0].setAttribute("style","display:;font-size:10px");
	el[2].setAttribute("style","display:");
}

function listItemPublished(id, task){
	if (task == 'publish'){
		listItemTask(id, task);
	}else{
		var message = "Warning. Unpublished listing will be automatically removed after 1 month.";
		message = message + " No other warning will be provided prior to removal. Thank you.";

		var answer = confirm(message);

		if (answer){
			listItemTask(id, task);
		}else{
			return false;
		}
	}
}

function clearClassifiedSearch() {
	try {
		document.getElementById('filter_search').value = '';
		document.getElementById('filter_state').value = '';
		document.getElementById('filter_classifiedcategory').value = '0';
		document.getElementById('filter_classifiedtype').value = '0';
		if (document.getElementById('filter_classifiedcompany')) {
			document.getElementById('filter_classifiedcompany').value = '0';
		}
		if (document.getElementById('filter_classifiedcompanyuser')) {
			document.getElementById('filter_classifiedcompanyuser').value = '0';
		}
	} catch (e) {
	}
	document.adminForm.submit();
}

function onchangeCountry(country, first) {
	var url = "index.php?option=com_classified&task=loadstate&country="+escape(country.value)+'&first='+escape(first);
	var a = new Ajax(url,{
		method:"get",
		onComplete: function(response) {
			$("div_state").setHTML(response);
		}
	}).request();
}

function onchangeSearchCountry(country, first, category) {
	var url = "index.php?option=com_classified&task=loadstate&country="+escape(country.value)+'&first='+escape(first)+'&category='+escape(category);
	var a = new Ajax(url,{
		method:"get",
		onComplete: function(response) {
			$("div_state"+category).setHTML(response);
		}
	}).request();
}

function onchangeSearchCategory(category, first, name) {
	var url = "index.php?option=com_classified&task=loadclassifiedtype&category="+escape(category.value)+'&first='+escape(first)+'&name='+escape(name);
	var a = new Ajax(url,{
		method:"get",
		onComplete: function(response) {
			$("div_classified_type_code").setHTML(response);
		}
	}).request();
}

