//============================================================================================================
// Common functions
//============================================================================================================
dataURL = "/";
baseURL = "/";
function getElementsByName (tag, name) {    
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}
//function trimtext(_text) { return _text.replace(/^\s+|\s+$/, '').substr(0, _text.replace(/^\s+|\s+$/, '').length); };
function trimtext(_text) {
	var tmp=_text;
	while((tmp.substr(0,1)==' ')&&(tmp.length>0)){
		tmp = tmp.substr(1, tmp.length);
	}
	while((tmp.substr(tmp.length-1,1)==' ')&&(tmp.length>0)){
		tmp = tmp.substr(0,tmp.length-1);
	}
	return(tmp)
}
function isNumber(ss){
	var passw = ss;
	var ValidChars = '0123456789.';
	var IsNumber=true;
	var Char='';
	
	for (i = 0; passw.length > i && IsNumber == true; i++) 
	{ 
		Char = passw.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) { IsNumber = false; }
	}
	try{
		var ii = parseInt(ss, 10);
		if(ii=='NaN'){return(false)};
	}catch(ex){
		return(false);
	}
	if (IsNumber){ return(true);} else {return(false);}
}
function isPositiveNumber(ss) {
	try {if (isNumber(ss)) {return((ss>0)?true:false);} else {return(false);}}catch(ex){return(false);}
}
function checkNumberValue(e) {
  	var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    //if (target.value == target.defaultText) { target.value = ''; }
	if (isNumber(target.value)==false){target.value='0';}
}

/* 
 * Cross-browser event handling, by Scott Andrew
 */
function addEventScott(element, eventType, lamdaFunction, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(eventType, lamdaFunction, useCapture);
        return(true);
    } else if (element.attachEvent) {
        var r = element.attachEvent('on' + eventType, lamdaFunction);
        return(r);
    } else {
        return(false);
    }
}

function get_value(_frm){
	var getStr = "";
	var frm = document.getElementById(_frm);
	var inputs = frm.getElementsByTagName("input");
	if(!frm){return;}
	
	for (i=0; i<inputs.length; i++) {
		if(inputs[i].name!='' && inputs[i].name!='undefined') {
			switch(inputs[i].type){
				case "text":
					getStr += "&" + inputs[i].name + "=" + window.encodeURIComponent(inputs[i].value);
					break;
				case "password": 
					getStr += "&" + inputs[i].name + "=" + window.encodeURIComponent(inputs[i].value);
					break;
				case "hidden":
					getStr += "&" + inputs[i].name + "=" + window.encodeURIComponent(inputs[i].value);
					break;
				case "checkbox":
					if(inputs[i].checked) {
						getStr += "&" + inputs[i].name + "=" + window.encodeURIComponent(inputs[i].value);
					}else{
						getStr += ""; //"&" + inputs[i].name + "="
					}
					break;
				case "radio":
					if(inputs[i].checked) {
						getStr += "&" + inputs[i].name + "=" + window.encodeURIComponent(inputs[i].value);
					}else{
						getStr += "";// + inputs[i].name + "="
					}
					break;
				default:
					break;
			}
		}
	}
	inputs = frm.getElementsByTagName("textarea");
	if(!inputs.length) {
		getStr += "&" + inputs.name + "=" + window.encodeURIComponent(inputs.value);
	}else{
		for (i=0; i<inputs.length; i++) {
			getStr += "&" + inputs[i].name + "=" + window.encodeURIComponent(inputs[i].value);
		}
	}
	inputs = frm.getElementsByTagName("select");
	if(!inputs.length) {
		getStr += "&" + inputs.name + "=" + window.encodeURIComponent(inputs.value);
	}else{
		for (i=0; i<inputs.length; i++) {
			getStr += "&" + inputs[i].name + "=" + window.encodeURIComponent(inputs[i].value);
		}
	}
	return getStr;
}
function sendmail(_title, _body){
	window.location = "mailto:your-friend@email.com?subject=" + encodeURIComponent(_title) + '&body=' + window.encodeURIComponent(_body);
}

//============================================================================================================
// Form Validation
//============================================================================================================
var W3CDOM = (document.getElementsByTagName && document.createElement);
function validate_ex(theForm, _ErrMsg, arrNotRequired) {
	validForm = true;
	firstError = null;
	errorstring = '';
	var firstAlert = null;
	var x = document.forms[theForm].elements;
	var arr = ','+arrNotRequired.toString()+ ',';
	for (var i=0;i<x.length;i++) {
		if (arr.indexOf(','+x[i].name+',')==-1) {
			str = "".concat(x[i].type);
			//alert(x[i].type);
			if ((str.toString() == "undefined") || (str.toString() == "button") || (str.toString() == "hidden"))
				continue;
			//if (!x[i].value)
//			{
//				var str="";
//				str = "".concat(x[i].type);
//				if ((str.toString() != "undefined") && (str.toString() != "button") && (str.toString() != "hidden"))
//				{
//					writeError(x[i], _ErrMsg);
//					if (firstError ==null) firstError = x[i];
//				}
//			}

			if (x[i].name == 'txt_email')
			{	
				if (x[i].value == '') {
					writeError(x['txt_email'], _ErrMsg);
					if(!firstAlert) firstAlert = LABEL_NoEmail;
				}else{
					var strEmail = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
					if(!strEmail.test(x['txt_email'].value)){
						writeError(x['txt_email'], _ErrMsg);
						if(!firstAlert) firstAlert = LABEL_InvalidEmail;
					}
				}
			}
			if(x[i].name == 'txt_oldpass')
			{
				if(!(x['txt_oldpass'].value)) {
					writeError(x['txt_oldpass'], _ErrMsg);
					if(!firstAlert) firstAlert = LABEL_NoPassword;
				}
			}
			if(x[i].name == 'txt_pass')
			{
				if(!(x['txt_pass'].value)) {
					writeError(x['txt_pass'], _ErrMsg);
					if(!firstAlert) firstAlert = LABEL_NoPassword;
				}
			}
			if (x[i].name == 'txt_cfr_pass')
			{
				if(x['txt_cfr_pass'].value != x['txt_pass'].value || x['txt_cfr_pass'].value == ''){
					writeError(x['txt_cfr_pass'], _ErrMsg);
					if(!firstAlert) firstAlert = LABEL_InvalidPasswordConfirm;
				}
			}
			
			if (x[i].name == 'txt_name')
			{			
				if(!(x['txt_name'].value)){
					writeError(x['txt_name'], _ErrMsg);
					if(!firstAlert) firstAlert = LABEL_NoCustomerName;
				}
			}			
			if (x[i].name == 'txt_phone')
			{			
				if(!(x['txt_phone'].value)){
					writeError(x['txt_phone'], _ErrMsg);
					if(!firstAlert) firstAlert = LABEL_NoCustomerPhone;
				}
			}
			if (x[i].name == 'txt_title')
			{			
				if(!(x['txt_title'].value)){
					writeError(x['txt_title'], _ErrMsg);
					if(!firstAlert) firstAlert = LABEL_NoMessageTitle;
				}
			}
			if (x[i].name == 'txt_message')
			{			
				if(!(x['txt_message'].value)){
					writeError(x['txt_message'], _ErrMsg);
					if(!firstAlert) firstAlert = LABEL_NoMessageContent;
				}
			}
			if (x[i].name == "txt_seccode")
			{			
				if(!(x['txt_seccode'].value)){
					writeError(x['txt_seccode'], _ErrMsg);
					if(!firstAlert) firstAlert = LABEL_NoSecurityCode;
				}
			}
			if (x[i].name == "txt_address")
			{			
				if(!(x['txt_address'].value)){
					writeError(x['txt_address'], _ErrMsg);
					if(!firstAlert) firstAlert = LABEL_NoAddress;
				}
			}
			if (x[i].name == "txt_cell")
			{			
				if(!(x['txt_cell'].value)){
					writeError(x['txt_cell'], _ErrMsg);
					if(!firstAlert) firstAlert = LABEL_NoCellPhone;
				}
			}
		}
	}
	if (!W3CDOM)
		alert(errorstring);
	if (firstError)
		firstError.focus();
	if (firstAlert)
		alert(firstAlert);	
	if (validForm)
		return true;
		
	return false; // I return false anyway to prevent actual form submission. Don't do this at home!
}
function validate(theForm, _ErrMsg, arrNotRequired) {
	try {
		validForm = true;
		firstError = null;
		errorstring = '';
		var _frm = document.getElementById(theForm);
		if(_frm==null){return false;}
		var x = _frm.elements;
		var arr = ','+arrNotRequired.toString()+ ',';
		for (var i=0;i<x.length;i++) {
			if (arr.indexOf(','+x[i].name+',')==-1) {
				if (!x[i].value)
				{
					var str="";
					str = "".concat(x[i].type);
					if ((str.toString() != "undefined") || (str.toString() != "button") || (str.toString() != "hidden"))
					{
						writeError(x[i], _ErrMsg);
						if (firstError ==null)
						firstError = x[i];				
					}
				}
				if (x[i].name == 'txt_email')
				{			
					var strEmail = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
					if(!strEmail.test(x['txt_email'].value))
						writeError(x['txt_email'], _ErrMsg);
				}
			}
		}
		
		if (!W3CDOM)
			alert(errorstring);
		if (firstError)
			firstError.focus();
		if (validForm)
			return true;
			
		return false; // I return false anyway to prevent actual form submission. Don't do this at home!
		
	}catch(ex){return(false);}
}
function revalidate() {
		var noerror = true;
		if (!this.value)
		{
			var str="";
			str = "".concat(this.type);
			if ((str.toString() != "undefined") || (str.toString() != "button") || (str.toString() != "hidden"))
			{
				noerror = false;			
			}
		}
		if (this.name == 'txtEmail')
		{			
			var strEmail = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
			if(!strEmail.test(this.value))
				noerror = false
		}
		if(noerror){
			this.className = this.className.substring(0,this.className.lastIndexOf(' '));
			//this.parentNode.removeChild(this.hasError);
			this.hasError = null;
			this.onchange = null;
		}			
}
function writeError(obj,message) {
	validForm = false;
	if (obj.hasError) return;
	if (W3CDOM) {
		if(obj.type == "textarea") {
			obj.className = 'error';
		} else {
			obj.className += ' error';
		}
		obj.onchange = revalidate;
		var sp = document.createElement('span');
		sp.className = 'error';
		sp.appendChild(document.createTextNode(message));
		//obj.parentNode.appendChild(sp);
		obj.hasError = sp;
	}
	else {
		errorstring += obj.name + ': ' + message + '\n';
		obj.hasError = true;
	}
	if (!firstError)
		firstError = obj;
}

function removeError() {
	this.className = this.className.substring(0,this.className.lastIndexOf(' '));
	//this.parentNode.removeChild(this.hasError);
	this.hasError = null;
	this.onchange = null;
}
function removeNodeError(_nodeId){
	var obj = document.getElementById(_nodeId);
	try{
		obj.className = obj.className.substring(0,obj.className.lastIndexOf(' '));
		//obj.parentNode.removeChild(obj.hasError);
		obj.hasError = null;
		obj.onchange = null;
	}
	catch(ex){
		
	}
}
//============================================================================================================
// END Form Validation
//============================================================================================================

//============================================================================================================
// Ajax function
//============================================================================================================
//change language
function changelang(_lang) {
	try {
	//	if(_lang==lang) return;
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_lang==null)||(_lang=='')){return;}
		var actionURL = "ajax/actions.aspx?type=language&lang=" + window.encodeURIComponent(_lang) + "&rd=" + Math.random();
		var indicator = document.getElementById('processDiv');
		if(indicator!=null){
			indicator.style.display = 'block';
		}
		HttpRequest.open("GET",actionURL);
		HttpRequest.onreadystatechange = function()
		{
		   if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
		   {
			  if(HttpRequest.responseText.indexOf('err=')!=0){
				 var loc = window.location.toString();   	
				 if(loc.indexOf('cat=')>0 || loc.indexOf('pid=')>0 || loc.indexOf('nid=')>0){
					 window.location = '/';
				 }else{
					 window.location.reload();
		         }
			  }
			  if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){alert(ex);}
}
function load_district(_oid, _pid, _selectedValue){
	try {
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')||(_pid=='')||(_pid==null)){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		//obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=district&pid=" + window.encodeURIComponent(_pid) + "&rd=" + Math.random();
		//window.location = actionURL;
		//return;
		var indicator = document.getElementById('processDiv');
		if(indicator!=null){
			indicator.style.display = 'block';
		}
		HttpRequest.open("GET",actionURL);
		HttpRequest.onreadystatechange = function()
		{
		   if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
		   {
			   if(HttpRequest.responseText.indexOf('err=')!=0){
					var xml = HttpRequest.responseXML;
					while (obj.length > 1){
						obj.remove(1);
					}
					//var root = xml.documentElement;
					var root = xml.getElementsByTagName("option")
					if (root.length > 0){
						for(var i=0;i<root.length;i++){
							var oOption = document.createElement("OPTION");
							oOption.value = root[i].getAttribute("id");
							oOption.text = root[i].getAttribute("name");
							if(_selectedValue==oOption.value){
								oOption.selected = true;
							}
							obj.options[i+1] = oOption;
						}
					}
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
var rd = Math.random();
function show_detail(_oid, _pid){
	try{
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		//obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=showdetail&pid=" + window.encodeURIComponent(_pid) + "&rd=" + rd;
		//window.location = actionURL;
		//return;
		var indicator = document.getElementById('processDiv');
		if(indicator!=null){
			indicator.style.display = 'block';
		}
		HttpRequest.open("GET",actionURL);
		HttpRequest.onreadystatechange = function()
		{
		   if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
		   {
			   if(HttpRequest.responseText.indexOf('err=')!=0){
					obj.innerHTML = HttpRequest.responseText;							
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
	//	HttpRequest.send(null);
		return;
	}catch(ex){}
}

function show_tab(_oid, _cid){
	try{
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		obj.innerHTML = '<p class="loading"><img src="' + baseURL + 'images/assets/loading.gif" /></p>';
		var actionURL = "ajax/actions.aspx?type=showtab&cid=" + window.encodeURIComponent(_cid) + "&rd=" + Math.random();
		//window.location = actionURL;
		//return;
		var indicator = document.getElementById('processDiv');
		if(indicator!=null){
			indicator.style.display = 'block';
		}
		HttpRequest.open("GET",actionURL);
		HttpRequest.onreadystatechange = function()
		{
		   if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
		   {
			   if(HttpRequest.responseText.indexOf('err=')!=0){
					obj.innerHTML = HttpRequest.responseText;							
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}	
}

function productTabs(_oid,catID){
try{
	
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		obj.innerHTML = '<p class="loading"><img src="' + dataURL + 'images/assets/loading.gif" /></p>';
				var actionURL = baseURL + "Ajax/actions.aspx?type=producttabs&mycat=" + window.encodeURIComponent(catID) + "&anticache=" + Math.random();		
		//window.location = actionURL;
		var indicator = document.getElementById('processDiv');
		if(indicator!=null){
			indicator.style.display = 'block';
		}
		HttpRequest.open("GET",actionURL);
		HttpRequest.onreadystatechange = function()
		{
		   if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
		   {
			   if(HttpRequest.responseText.indexOf('err=')!=0){
					obj.innerHTML = HttpRequest.responseText;								
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){alert(ex);}	
}



function do_search(_oid, _frm, _page){
	try{
		var getStr = "type=search";
		var obj = document.getElementById(_oid);
		var frm = document.getElementById(_frm);
		
		$("#indicator").css("display", 'block');
		
		if(!frm){return;}
		if(!obj){return;}
		obj.innerHTML = "<p class='loading'><img src='" + baseURL + "images/assets/loading.gif' alt='Loading' /></p>";
				
		//getStr += get_value(_frm);
		getStr += "&page=" + _page;
		getStr += "&rd=" + Math.random(); 
		
		var actionURL = baseURL + "ajax/actions.aspx";		
		$.ajax({
			type: "POST",
			url: actionURL,
			data: getStr,
			success: function(msg){
				if(msg.indexOf('err=')!=0){
					obj.innerHTML = msg;	
					$('.match span').tooltip({
						delay: 0, 
						showURL: false, 
						showBody: " - "
					});
					$(".match").each(function(i){
						$(this).css("width", $(this).attr('title') + "px");
						$(this).removeAttr('title');
					});
				}
				$("#indicator").css("display", 'none');
			}
		});
	
		return;
	}catch(ex){alert(ex);}
}

function load_price(_oid, _pid, _cid) {
	try{
		var getStr = "type=loadprice";
		var obj = document.getElementById(_oid);
	
		$("#indicator").css("display", 'block');
		
		if(!obj){return;}
		getStr += "&cat=" + window.encodeURIComponent(_cid) + "&pid=" + window.encodeURIComponent(_pid);
		getStr += "&rd=" + Math.random(); 
		var actionURL = baseURL + "ajax/actions.aspx";		
		//alert(getStr);
		$.ajax({
			type: "POST",
			url: actionURL,
			data: getStr,
			success: function(msg){
				if(msg.indexOf('err=')!=0){
					obj.innerHTML = msg;	
					$("#price_box table.tblprice caption a").click(function(event){
						event.preventDefault();	
						load_price("price_box", $(this).attr("rel"), $(this).attr("title"));
					});
				}
				$("#indicator").css("display", 'none');
			}
		});

		
		return;

	}catch(ex){}
}
function send_request(_frm, _type){
	try{
		var getStr = "type=" + _type;
	
		$("#indicator").css("display", 'block');
		var frm = document.getElementById(_frm);
		if(!frm){return;}
		//alert(inputs.length);
		getStr += get_value(_frm);
		getStr += "&rd=" + Math.random(); 
		var actionURL = baseURL + "ajax/actions.aspx";		
		
		$.ajax({
			type: "POST",
			url: actionURL,
			data: getStr,
			success: function(msg){
				$("#indicator").css("display", 'none');
				if(msg.indexOf('err=')!=0){
					if(_type == 'login'){
						window.location = msg;
					}else{
						window.location = 'success.aspx?type=' + _type;
					}
				}else{
					switch(msg.replace(/err=/, "")){
						case "code":
							alert(LABEL_InvalidSecCode);
							break;
						case "noname":
							alert(LABEL_NoCustomerName);
							break;
						case "noemail":
							alert(LABEL_NoEmail);
							break;
						case "nophone":
							alert(LABEL_NoCustomerPhone);
							break;
						case "notitle":
							alert(LABEL_NoMessageTitle);
							break;
						case "nocontent":
							alert(LABEL_NoMessageContent);
							break;
						case "invalidemail":
							alert(LABEL_InvalidEmail);
							break;
						case "invalidcode":
							$("#sec_img").attr("src", baseURL + "code.aspx?rd=" + Math.random());
							alert(LABEL_InvalidSecCode);
							break;
						case "nopassword":
							alert(LABEL_NoPassword);
							break;
						case "mailexist":
							alert(LABEL_MailExisted);
							break;
						case "wrongpassword":
							alert(LABEL_WrongPassword);
							break;
						case "usernotfound":
							alert(LABEL_UserNotFound);
							break;
						case "confirmfailure":
							alert(LABEL_InvalidPasswordConfirm);
							break;
						default:
							alert(LABEL_UnspecificError);
							break;
					}
				}
			}
		});

		
		return;

	}catch(ex){}
}
function change_image(_img){
	try{
		var getStr = "type=changeimage";
		var img = document.getElementById(_img);
		$("#indicator").css("display", 'block');	
		if(!img){return;}
		
		getStr += "&rd=" + Math.random(); 
		var actionURL = baseURL + "ajax/actions.aspx";		
		
		$.ajax({
			type: "POST",
			url: actionURL,
			data: getStr,
			success: function(msg){
				if(msg.indexOf('err=')!=0){
					img.src = baseURL + "code.aspx?rd=" + Math.random();
				}
				$("#indicator").css("display", 'none');
			}
		});
		
		return;
	}catch(ex){}
}
function load_product(_oid, _cid, _order, _page){
	try{
		var getStr = "type=productcate";
		var obj = document.getElementById(_oid);
				
		$("#indicator").css("display", 'block');
		
		if(!obj){return;}
		obj.innerHTML = "<p class='loading'><img src='" + baseURL + "images/assets/loading.gif' alt='Loading' /></p>"
		
		getStr += "&cat=" + _cid + "&order=" + _order + "&page=" + _page;
		getStr += "&rd=" + Math.random(); 
		var actionURL = baseURL + "ajax/actions.aspx";		
		
		$.ajax({
			type: "POST",
			url: actionURL,
			data: getStr,
			success: function(msg){
				if(msg.indexOf('err=')!=0){
					obj.innerHTML = msg;	
				}
				$("#indicator").css("display", 'none');
			}
		});
		return;
	}catch(ex){}
}
function load_news(_oid, _cid, _page){
	try{
		var getStr = "type=newscate";
		var obj = document.getElementById(_oid);
				
		$("#indicator").css("display", 'block');		
		if(!obj){return;}
		obj.innerHTML = "<p class='loading'><img src='" + baseURL + "images/assets/loading.gif' alt='Loading' /></p>"

		getStr += "&cat=" + _cid + "&page=" + _page;
		getStr += "&rd=" + Math.random(); 
		var actionURL = baseURL + "ajax/actions.aspx";		
		
		$.ajax({
			type: "POST",
			url: actionURL,
			data: getStr,
			success: function(msg){
				if(msg.indexOf('err=')!=0){
					obj.innerHTML = msg;	
				}
				$("#indicator").css("display", 'none');
			}
		});
		return;
	}catch(ex){}
}
function logout(){
	try{
		var getStr = "type=logout";
				
		$("#indicator").css("display", 'block');		
		
		getStr += "&rd=" + Math.random(); 
		var actionURL = baseURL + "ajax/actions.aspx";		
		
		$.ajax({
			type: "POST",
			url: actionURL,
			data: getStr,
			success: function(msg){
				if(msg.indexOf('err=')!=0){
					window.location.reload();
				}
				$("#indicator").css("display", 'none');
			}
		});
		return;
	}catch(ex){}
}
function show_contact(){
	try{
		var getStr = "type=showcontact";
		var current = $("#product-contact .slimtab li[class='active']");
		var contact_type = current.attr("title");
		if(contact_type == 'undefined') return;
		var pid = current.attr("value");
		if(pid == 'undefined') return;
		
		$("#indicator").css("display", 'block');		
		
		getStr += "&pid=" + window.encodeURIComponent(pid) + "&ct=" + window.encodeURIComponent(contact_type);
		getStr += "&rd=" + Math.random(); 
		var actionURL = baseURL + "ajax/actions.aspx";		
		
		$.ajax({
			type: "POST",
			url: actionURL,
			data: getStr,
			success: function(msg){
				if(msg.indexOf('err=')!=0){
					//window.location.reload();
					$("#contact-info").html(msg);
					if(contact_type=='map') {
						initMap();
					}
				}else{
					$("#contact-info").html('');
				}
				$("#indicator").css("display", 'none');
			}
		});
		return;
	}catch(ex){}
}
function load_range(_value,_selectedValue){
	try{
		var getStr = "type=loadrange";	
		$("#indicator").css("display", 'block');		
		
		getStr += "&currency=" + window.encodeURIComponent(_value);
		getStr += "&rd=" + Math.random(); 
		var actionURL = baseURL + "ajax/actions.aspx";		
		
		$.ajax({
			type: "POST",
			url: actionURL,
			data: getStr,
			dataType: "xml",
			success: function(msg){
				//try{
					var xml = msg;
					var obj = document.getElementById('slt_price_range');
					while (obj.length > 1){
						obj.remove(1);
					}
					//var root = xml.documentElement;
					var root = xml.getElementsByTagName("option")
					if (root.length > 0){
						for(var i=0;i<root.length;i++){
							var oOption = document.createElement("OPTION");
							oOption.value = root[i].getAttribute("id");
							oOption.text = root[i].getAttribute("name");
							if(_selectedValue==oOption.value){
								oOption.selected = true;
							}
							obj.options[i+1] = oOption;
						}
					}
				//}catch(ex){}
				$("#indicator").css("display", 'none');
			}
		});
		return;
	}catch(ex){alert(ex.message);}
}
function show_news(_oid, _cid, _indicator){
	try{
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		
		//obj.innerHTML = '<p class="loading"><img src="' + baseURL + 'images/assets/loading.gif" /></p>';		
		var actionURL = "ajax/actions.aspx?type=shownews&cid=" + window.encodeURIComponent(_cid) + "&rd=" + Math.random();
		//window.location = actionURL;
		//return;
		
	//	var indicator = document.getElementById(_indicator);
		//if(indicator!=null){
//			indicator.style.display = 'inline';
		//}
		HttpRequest.open("GET",actionURL);
		HttpRequest.onreadystatechange = function()
		{
		   if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
		   {
			   if(HttpRequest.responseText.indexOf('err=')!=0){
					obj.innerHTML = HttpRequest.responseText;	
					$(".news-tab a").click(function(event){
						event.preventDefault();
						show_news('bottom-news', $(this).attr('name'), "bost-news-ind");
					});
			   }
		   }
		}
		HttpRequest.send(null);
		

		return;

	}catch(ex){}
}
//============================================================================================================
// END Ajax function
//============================================================================================================
function do_filter(_cid, _id, _type){
	try{
		var loc = baseURL + "result.aspx?current=" + window.encodeURIComponent(_cid) + "";
		switch(_type){
			case "landtype":
				loc += "&slt_landtype=" + _id;
				break;
			case "supplier":
				loc += "&slt_supplier=" + _id;
				break;
			case "province":
				loc += "&slt_city=" + _id;
				break;
			default:
				return;
		}
		window.location = loc;
		return;
	}catch(ex){}
}
function process_enter(_frm, _btn){
	try{
		$('#'+_frm+' :input').each(function(i){
			$(this).keydown(function(event){
				if (event.keyCode == 13)
					$("#"+_btn).click();
			});
		});
	}catch(ex){}
}
//============================================================================================================
//scroll by jQuery
//============================================================================================================
jQuery.getPos = function (e)
{
	var l = 0;
	var t  = 0;
	var w = jQuery.intval(jQuery.css(e,'width'));
	var h = jQuery.intval(jQuery.css(e,'height'));
	var wb = e.offsetWidth;
	var hb = e.offsetHeight;
	while (e.offsetParent){
		l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
		t += e.offsetTop  + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
		e = e.offsetParent;
	}
	l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
	t  += e.offsetTop  + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
	return {x:l, y:t, w:w, h:h, wb:wb, hb:hb};
};
jQuery.getClient = function(e)
{
	if (e) {
		w = e.clientWidth;
		h = e.clientHeight;
	} else {
		w = (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth;
		h = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;
	}
	return {w:w,h:h};
};
jQuery.getScroll = function (e) 
{
	if (e) {
		t = e.scrollTop;
		l = e.scrollLeft;
		w = e.scrollWidth;
		h = e.scrollHeight;
	} else  {
		if (document.documentElement && document.documentElement.scrollTop) {
			t = document.documentElement.scrollTop;
			l = document.documentElement.scrollLeft;
			w = document.documentElement.scrollWidth;
			h = document.documentElement.scrollHeight;
		} else if (document.body) {
			t = document.body.scrollTop;
			l = document.body.scrollLeft;
			w = document.body.scrollWidth;
			h = document.body.scrollHeight;
		}
	}
	return { t: t, l: l, w: w, h: h };
};

jQuery.intval = function (v)
{
	v = parseInt(v);
	return isNaN(v) ? 0 : v;
};

jQuery.fn.ScrollTo = function(s) {
	o = jQuery.speed(s);
	return this.each(function(){
		new jQuery.fx.ScrollTo(this, o);
	});
};

jQuery.fx.ScrollTo = function (e, o)
{
	var z = this;
	z.o = o;
	z.e = e;
	z.p = jQuery.getPos(e);
	z.s = jQuery.getScroll();
	z.clear = function(){clearInterval(z.timer);z.timer=null};
	z.t=(new Date).getTime();
	z.step = function(){
		var t = (new Date).getTime();
		var p = (t - z.t) / z.o.duration;
		if (t >= z.o.duration+z.t) {
			z.clear();
			setTimeout(function(){z.scroll(z.p.y, z.p.x)},13);
		} else {
			st = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.y-z.s.t) + z.s.t;
			sl = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.x-z.s.l) + z.s.l;
			z.scroll(st, sl);
		}
	};
	z.scroll = function (t, l){window.scrollTo(l, t)};
	z.timer=setInterval(function(){z.step();},13);
};

