var ajax = new sack();

function openWindow(url,name,width,height) {
	leftVal = ( screen.width-width) / 2;
	topVal = ( screen.height-height ) / 2;
	newWindow = window.open(url, name,'width='+width+',height='+height+',left='+leftVal+',top='+topVal+'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no');
	newWindow.moveTo(leftVal,topVal);
}
function ajax_onload(text){
	var e = document.getElementById('aload'); 
	if(text==null){
		text='Loading ..';
	}
	e.innerHTML = text;
	e.style.display ="block";
}
function ajax_oncomplete(){
	var e = document.getElementById('aload'); 
	e.style.display ='none';
}

function debug_ajax(){
	var e = document.getElementById('center'); 
	e.innerHTML = ajax.response;

}

function convert_currency_complete(){
	var e = document.getElementById('currency_result'); 
	var string = ajax.response;
	e.value = string;	
}

function IsNumeric(sText){
	var ValidChars = "0123456789.,";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++){ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1){
			IsNumber = false;
		}
	}
	return IsNumber;
}

function convert_currency(session){
	var amount = document.getElementById('currency_amt'); 
	var from = document.getElementById('currency_from'); 
	var to = document.getElementById('currency_to'); 
	if(IsNumeric(amount.value) && (amount.value!='')){
		ajax.resetData();
		ajax.setVar("amount", amount.value); 
		ajax.setVar("from", from.value); 
		ajax.setVar("to", to.value); 
		ajax.requestFile = "/ajax/currency.php?tsid="+session;
		ajax.method = 'POST';
		ajax.onLoading = ajax_onload('Calculating ..');
		ajax.onLoaded = ajax_oncomplete; 
		ajax.onCompletion = convert_currency_complete;
		ajax.runAJAX();
	}else{
		alert("Please input valid amount to calculate..!!");
	}
}

function ajaxLoadDetails(){
	var obj = document.getElementById('fp_email');
	emailID = obj.value;
	if(emailID.length > 0){
		var sajax = new sack();
		sajax.requestFile = ajaxEnqLoadUrl;
		sajax.setVar("AJAX_LOAD", "Loader");
		sajax.setVar("email", emailID);
		sajax.onLoading = function(){
			var e = document.getElementById('aload_enq'); 
			e.style.display ="block";
		};
		sajax.onCompletion = function(){ 
			var e = document.getElementById('aload_enq'); 
			e.style.display ="none";
			sajax.runResponse();
		};
		sajax.runAJAX();
	}
}

function acsfpenq(enqid){
	var sajax = new sack();
	sajax.requestFile = csfenqurl;
	sajax.setVar("AJAX_LOAD", "Loader");
	sajax.setVar("enqid", enqid);
	sajax.onLoading = function(){
		ajax_onload();
	};
	sajax.onCompletion = function(){ 
		ajax_oncomplete();
		var e = document.getElementById('enquiry_detail'); 
		e.innerHTML = sajax.response;
		Fat.fade_element('enquiry_detail',null,700,'#FF3333');
		window.location.hash="edetail"; 
	};
	sajax.runAJAX();
}

function setSelectOption(id,value){
	var obj = document.getElementById(id);
	for(i=0;i<obj.options.length;i++){
		if(obj.options[i].value == value){
			obj.selectedIndex = i;
		}
	}

}

function set_convertor_currency(samount){
	var amount = document.getElementById('currency_amt'); 
	var from = document.getElementById('currency_from'); 
	amount.value=samount;
	from.selectedIndex=0;
	amount.focus();
}

function property_search_complete(){
	var e = document.getElementById('center'); 
	var string = ajax.response;
	if(string!='norecord'){
		e.innerHTML = string;
		initLightbox();
		Fat.fade_element('ajax-psearch',null,700,'#FF3333');	
	}else{
		alert('No property found matching your search criteria..!!!')
	}
}


function property_search(session){
	var type = document.getElementById('ps_unit_type'); 
	var bed = document.getElementById('ps_unit_bedroom'); 
	var bath = document.getElementById('ps_unit_bathroom'); 
	var area = document.getElementById('ps_unit_area'); 
	var price = document.getElementById('ps_unit_price'); 

	ajax.resetData();
	ajax.setVar("type",type.options[type.selectedIndex].value); 
	ajax.setVar("bed",bed.options[bed.selectedIndex].value); 
	ajax.setVar("bath",0); 
	ajax.setVar("area",area.options[area.selectedIndex].value); 
	ajax.setVar("price",price.options[price.selectedIndex].value); 
	ajax.setVar("page",1); 
	ajax.requestFile = "/ajax/property_search.php?tsid="+session;
	ajax.method = 'POST';
	ajax.onLoading = ajax_onload('Searching ..');
	ajax.onLoaded = ajax_oncomplete; 
	ajax.onCompletion = property_search_complete;
	ajax.runAJAX();
}

function loadInteracePannels() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	if(myWidth > 1000){	
		var contentWidth = myWidth - 350;
		document.getElementById('head').style.width = (myWidth - 5) +'px';
		document.getElementById('content').style.width = (myWidth - 5) +'px';
		document.getElementById('center').style.width = (contentWidth-2) +'px';
		
	}
}

function _tfm(path,id){
	var p_width=600;
	var p_height=500;
	var p_left=(p_width - screen.width) / 2;
	var p_top=(p_height - screen.height) / 2;
	var target_object = document.getElementById(id);
	if(target_object.value!=''){
		var p_url='/member/fmanager.php?d=' + path +'&e='+id+'&v='+escape(target_object.value);
	}else{
		var p_url='/member/fmanager.php?d=' + path + '&e='+id;
	}
	var p_win = window.open(p_url,'image_manager',
		'width=' + p_width + ', height=' + p_height + ', ' +
		'left=' + p_left + ', top=' + p_top + ', ' +
		'location=no, menubar=no, ' +
		'status=no, toolbar=no, scrollbars=no, resizable=no');
	p_win.resizeTo(p_width, p_height);
	p_win.moveTo(p_left, p_top);
	p_win.focus();
}

function _tfmc(id){
	var obj = document.getElementById(id);
	obj.value = '';
	var obj_holder = document.getElementById('div_'+id);
	obj_holder.innerHTML ='';	
}


function loadTableFormatClassJs(){
	if(document.getElementsByTagName){
		var el = document.getElementsByTagName('TR');
		var reminder = 0;
		for(var i=0; i<el.length; i++){
			if(el[i].className =='head'){
				if(reminder==1){reminder=0;}else{reminder=1;}
			}
			if( el[i].className !='head' && el[i].parentNode.parentNode.className.indexOf("tableformat") != -1){
				if(i%2 == reminder){
					el[i].className = "on";
					el[i].oldClassName = "on";
					el[i].onmouseout  = function(){
						this.className = "on";
					}
				}else{
					el[i].className = "off";
					el[i].oldClassName = "off";
					el[i].onmouseout  = function(){
						this.className = "off";
					}
				}
				el[i].clicked=false;
				el[i].onmouseover = function(){
					if(this.className == this.oldClassName){
						this.className = "hover";
					}
				}
				el[i].onclick = function(){
					if(this.clicked){
						this.className = this.oldClassName;
						this.clicked=false;
						this.onmouseout = function(){
							this.className = this.oldClassName
						};
						this.mouseover = function(){
							if(this.className == this.oldClassName){
								this.className = "hover";
							}
						}
					}else{
						this.className = 'click';
						this.clicked=true;
						this.onmouseout = function(){
							this.className = "click";
							return true
						};
						this.onmouseover = function(){
							if(this.clicked) {
								this.className = "clickhover";
							} else {
								this.className = "hover";
							}
						}
					}
				}
			}
		}
	}
}

function onWindowLoadEvents(){
	//loadInteracePannels();
	loadTableFormatClassJs();
	Fat.fade_all();
	initLightbox();
	init_ibox();
}
//window.onresize=loadInteracePannels;
window.onload=onWindowLoadEvents;
