// JavaScript Document
//============================================================================================================
// Form Validation
//============================================================================================================
function trim(str) {     
	if(!str || typeof str != 'string')         
		return null;     
	return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' '); 
}

function validEmail(str) {
	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(str)) {
		return false;
	}else{
		return true;
	}	
}

function validUsername(str) {
	var strUsername = /^[a-zA-Z]{3,20}$/;
	if(!strUsername.test(str)) {
		return false;
	}else{
		return true;
	}	
}

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 == '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(!x['txtemail'].value || !strEmail.test(x['txtemail'].value)){
					writeError(x['txtemail'], _ErrMsg);
					if(!firstAlert) firstAlert = LABEL_InvalidEmail;
				}
			}
			/*if (x[i].name == 'txtConfirm')
			{
				if(x['txtConfirm'].value != x['txtPassword'].value){
					writeError(x['txtConfirm'],_ErrMsg);
					if(!firstError) firstError = LABEL_InvalidPasswordConfirm;
				}
			}
			if(x[i].name == 'txtPassword')
			{
				if(x['txtPassword'].value.length < 6)
					writeError(x['txtPassword'],'password must be longer than 6 characters !')
			}
			if(x[i].name == 'txtoldpass')
			{
				if(x['txtoldpass'].value.length < 6)
					writeError(x['txtoldpass'],'password must be longer than 6 characters !')
			}
			if(x[i].name == 'txtpassword')
			{
				if(x['txtpassword'].value.length < 6)
					writeError(x['txtpassword'],'password must be longer than 6 characters !')
			}
			if (x[i].name == 'txtconfirm')
			{
				if(x['txtconfirm'].value != x['txtpassword'].value)
					writeError(x['txtconfirm'],'confirm password is not valid !');
			}
			if (x[i].name == 'txtnewpass')
			{
				if(x['txtnewpass'].value.length < 6)
					writeError(x['txtnewpass'],'password must be longer than 6 characters !')
			}*/
			if (x[i].name == 'txtname')
			{
				if(!(x['txtname'].value)){
					writeError(x['txtname'], _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 == 'txttitle')
			{			
				if(!(x['txttitle'].value)){
					writeError(x['txttitle'], _ErrMsg);
					if(!firstAlert) firstAlert = LABEL_NoMessageTitle;
				}
			}
			if (x[i].name == 'txt_cusmsg')
			{			
				if(!(x['txt_cusmsg'].value)){
					writeError(x['txt_cusmsg'], _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 (!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 ) {
	try {
		validForm = true;
		firstError = null;
		errorstring = '';
		var _frm = document.getElementById(theForm);
		if(_frm==null){return false;}
		var x = document.forms[theForm].elements;
		for (var i=0;i<x.length;i++) {
			
			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 == '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(x['txtemail'].value))
					writeError(x['txtemail'],'  *');
			}
		}
		
		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 writeError(obj,message) {
	validForm = false;
	if (obj.hasError) return;
	if (W3CDOM) {
		obj.className += ' error';
		obj.onchange = removeError;
		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
//============================================================================================================

// JavaScript Document
function generalSearch(){
	try{
		var _frm = document.getElementById('frmsearch');
		_frm.action = 'result.aspx';
		_frm.submit();
	}catch(ex){}
}
//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 changeImg(_dest, _destLink, _destTitle, _arr, _arrLink, _arrTitle, _index, _interval) {
	try {
		var i, obj, objLink, objTitle;
		obj = document.getElementById(_dest);
		objLink = document.getElementById(_destLink);
		objTitle = document.getElementById(_destTitle);
		if((obj==null)||(objLink==null)||(objTitle==null)){return;}
		i = _index + 1;
		if((i>=_arr.length)||(i<0)){i=0;}
		obj.src = _arr[i];
		obj.alt = arrTitle[i];
		objLink.href = _arrLink[i];
		objTitle.innerHTML = arrTitle[i];
		setTimeout("changeImg('" + _dest + "','" + _destLink + "','" + _destTitle + "',arr,arrLink,arrTitle," + i + "," + _interval + ")", _interval)
	}catch(ex){}
}
function changeAdv(_dest, _arr, _index, _interval) {
	try{
		var i, obj;
		obj = document.getElementById(_dest);
		if(obj==null){return;}
		i = _index + 1;
		if((i>=_arr.length)||(i<0)){i=0;}
		obj.innerHTML = _arr[i];
		setTimeout("changeAdv('" + _dest + "',arrAdv," + i + "," + _interval + ")", _interval)
	}catch(ex){}
}
//============================================================================================================
// Ajax function
//============================================================================================================
//change language
function changelang(_lang) {
	try {
		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) + "&anticache=" + 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=')!=1){
					window.location.reload();   	
			   }
			   if(indicator!=null){indicator.style.display = 'none';indicator.innerHTML = "";}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
function submitLetter(_mail){
	try{
		return (false);
	}catch(ex){}
}
function viewCat(_oid, _cid, _page){
	try{
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')||(_cid==null)||(_cid=='')){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=viewcat&cat=" + window.encodeURIComponent(_cid) + "&page=" + window.encodeURIComponent(_page) + "&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;
					imagePreview();
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
function viewCatBySuppliers(_oid, _cid, _page){
	try{
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')||(_cid==null)||(_cid=='')){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=viewcatbysuppliers&sid=" + window.encodeURIComponent(_cid) + "&page=" + window.encodeURIComponent(_page) + "&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 setOrderBy(_oid, _cid, _order) {
	try {
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')||(_cid==null)||(_cid=='')){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		obj.innerHTML = '<img src="/images/data/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=orderby&cat=" + window.encodeURIComponent(_cid) + "&order=" + window.encodeURIComponent(_order) + "&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=')!=1){
					obj.innerHTML = HttpRequest.responseText;	
			   }
			   if(indicator!=null){indicator.style.display = 'none';indicator.innerHTML = "";}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
function changeSearchType(_oid, _type, _selectedValue){
	try {
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')||(_type=='')||(_type==null)){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		//obj.innerHTML = '<img src="/images/data/indicator.gif />"';
		var actionURL = "ajax/actions.aspx?type=getcat&cattype=" + window.encodeURIComponent(_type) + "&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=')!=1){
					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';indicator.innerHTML = "";}
		   }
		}
		HttpRequest.send(null);
		
//		search-news, search-price,search-supplier,search-clips
		document.getElementById('search-news').style.display = 'none';
		document.getElementById('search-price').style.display = 'none';
		document.getElementById('search-supplier').style.display = 'none';
		document.getElementById('search-clips').style.display = 'none';
		switch(_type){
			case "2":
				document.getElementById('search-supplier').style.display = 'block';
				break;
			case "3":
				document.getElementById('search-price').style.display = 'block';
				break;
			case "4":
				document.getElementById('search-clips').style.display = 'block';
				break;
			default:
				document.getElementById('search-news').style.display = 'block';
				break;
		}	
				
		return;
	}catch(ex){alert(ex);}
}
function faqPaging(_oid, _page) {
	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/data/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=faqpaging&page=" + window.encodeURIComponent(_page) + "&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=')!=1){
					obj.innerHTML = HttpRequest.responseText;
			   } else {
				   
			   }
			   if(indicator!=null){indicator.style.display = 'none';indicator.innerHTML = "";}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}

function Login(_form, _outObj) {
	try{
		var getStr = "type=login&antiCache=" + Math.random();
		var inputList = _form.getElementsByTagName("input");
		var outObj = document.getElementById(_outObj);
		var indicatorObj = document.getElementById('processing')
		
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		
		if (!HttpRequest) return;		
		if((_form==null)||(_form=='')){return;}
		if((_outObj==null)||(_outObj=='')){return;}		
			
		if(!outObj){return;}
		
		for (i=0; i<inputList.length; i++) {
			 if (inputList[i].type == "text" || inputList[i].type == "password" || inputList[i].type == "hidden") {
				   getStr += "&" + inputList[i].id + "=" + encodeURI(inputList[i].value);
			 }   
		  }
		
		indicatorObj.innerHTML = '<img src="/images/data/indicator.gif" />';
		var actionURL = "ajax/actions.aspx";		
		
		//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=')!=1){
					outObj.innerHTML = HttpRequest.responseText;	
			   }
			   //if(indicator!=null){indicator.style.display = 'none';indicator.innerHTML = "";}
		   }
		}
		//HttpRequest.send(null);
		HttpRequest.open('POST', actionURL, true);
		HttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		HttpRequest.setRequestHeader("Content-length", getStr.length);
		HttpRequest.setRequestHeader("Connection", "close");
		HttpRequest.send(getStr);
		return;
	}catch(ex){}
}

function LoadLoginBlock(_oid) {
	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/data/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=loadloginblock&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=')!=1){
					obj.innerHTML = HttpRequest.responseText;	
			   }
			   if(indicator!=null){indicator.style.display = 'none';indicator.innerHTML = "";}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}

function Logout(_oid) {
	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/data/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=logout&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=')!=1){
					obj.innerHTML = HttpRequest.responseText;	
			   }
			   if(indicator!=null){indicator.style.display = 'none';indicator.innerHTML = "";}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}

function CheckUsername(_strUser, _inObj, _outObj) {
	try{		
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_strUser==null)||(trim(' ' + _strUser)=='')){return;}
		if(validUsername(_strUser)==false){return;}
		if((_inObj==null)||(_inObj=='')){return;}
		if((_outObj==null)||(_outObj=='')){return;}
		
		var obj = document.getElementById(_outObj);		
		if(!obj){return;}
		obj.innerHTML = '<img src="/images/data/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=checkusername&username=" + encodeURI(_strUser) + "&anticache=" + 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=')!=1){
					obj.innerHTML = HttpRequest.responseText;
			   }
			   if(indicator!=null){indicator.style.display = 'none';indicator.innerHTML = "";}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}

function CheckEmail(_strEmail, _inObj, _outObj) {
	try{		
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_strEmail==null)||(trim(' ' + _strEmail)=='')){return;}
		if(validEmail(_strEmail)==false){return;}
		if((_inObj==null)||(_inObj=='')){return;}
		if((_outObj==null)||(_outObj=='')){return;}
		
		var obj = document.getElementById(_outObj);		
		if(!obj){return;}
		obj.innerHTML = '<img src="/images/data/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=checkemail&email=" + encodeURI(_strEmail) + "&anticache=" + 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=')!=1){
					obj.innerHTML = HttpRequest.responseText;	
			   }
			   if(indicator!=null){indicator.style.display = 'none';indicator.innerHTML = "";}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}

function Login(_form, _outObj) {
	try{
		var getStr = "type=login&antiCache=" + Math.random();
		var inputList = _form.getElementsByTagName("input");
		var outObj = document.getElementById(_outObj);
		var indicatorObj = document.getElementById('processing')
		
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		
		if (!HttpRequest) return;		
		if((_form==null)||(_form=='')){return;}
		if((_outObj==null)||(_outObj=='')){return;}		
			
		if(!outObj){return;}
		
		for (i=0; i<inputList.length; i++) {
			 if (inputList[i].type == "text" || inputList[i].type == "password" || inputList[i].type == "hidden") {
				   getStr += "&" + inputList[i].id + "=" + encodeURI(inputList[i].value);
			 }   
		  }
		
		indicatorObj.innerHTML = '<img src="/images/data/indicator.gif" />';
		var actionURL = "ajax/actions.aspx";		
		
		//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=')!=1){
					outObj.innerHTML = HttpRequest.responseText;	
			   }
			   //if(indicator!=null){indicator.style.display = 'none';indicator.innerHTML = "";}
		   }
		}
		//HttpRequest.send(null);
		HttpRequest.open('POST', actionURL, true);
		HttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		HttpRequest.setRequestHeader("Content-length", getStr.length);
		HttpRequest.setRequestHeader("Connection", "close");
		HttpRequest.send(getStr);
		return;
	}catch(ex){}
}

function InsertNewRegister(_form, _outObj) {
	try{
		var getStr = "type=register&antiCache=" + Math.random();
		var inputList = _form.getElementsByTagName("input");
		var outObj = document.getElementById(_outObj);
		//var outObj2 = document.getElementById(_outObj2);
		var indicatorObj = document.getElementById('processing')
		
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		
		if (!HttpRequest) return;		
		if((_form==null)||(trim(' ' + _form)=='')){return;}
		if((_outObj==null)||(trim(' ' + _outObj)=='')){return;}
		//if((_outObj2==null)||(trim(' ' + _outObj2)=='')){return;}
			
		if(!outObj){return;}
		//if(!outObj2){return;}
		
		for (i=0; i<inputList.length; i++) {
			 if (inputList[i].type == "text" || inputList[i].type == "password" || inputList[i].type == "hidden") {
				   getStr += "&" + inputList[i].id + "=" + encodeURI(inputList[i].value);
			 }   
		  }
		
		//indicatorObj.innerHTML = '<img src="/images/data/indicator.gif" />';
		var actionURL = "ajax/actions.aspx";		
		
		//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=')!=1){
					outObj.innerHTML = HttpRequest.responseText;
					//outObj.className = "msg warning";
					//outObj2.innerHTML = HttpRequest.responseText;
					//outObj2.className = "msg warning";
			   }
			   //if(indicator!=null){indicator.style.display = 'none';indicator.innerHTML = "";}
		   }
		}
		//HttpRequest.send(null);
		HttpRequest.open('POST', actionURL, true);
		HttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		HttpRequest.setRequestHeader("Content-length", getStr.length);
		HttpRequest.setRequestHeader("Connection", "close");
		HttpRequest.send(getStr);
		return;
	}catch(ex){}
}

function ForgotPassword(_form, _outObj) {
	try{
		var getStr = "type=forgotpassword&antiCache=" + Math.random();
		var inputList = _form.getElementsByTagName("input");
		var outObj = document.getElementById(_outObj);
		var indicatorObj = document.getElementById('processing')
		
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		
		if (!HttpRequest) return;		
		if((_form==null)||(trim(' ' + _form)=='')){return;}
		if((_outObj==null)||(trim(' ' + _outObj)=='')){return;}
			
		if(!outObj){return;}
		
		for (i=0; i<inputList.length; i++) {
			 if (inputList[i].type == "text" || inputList[i].type == "password" || inputList[i].type == "hidden") {
				   getStr += "&" + inputList[i].id + "=" + encodeURI(inputList[i].value);
			 }   
		  }
		
		//indicatorObj.innerHTML = '<img src="/images/data/indicator.gif" />';
		var actionURL = "ajax/actions.aspx";		
		
		//window.location = actionURL;
		//return;
		//var indicator = document.getElementById('processDiv');
//		if(indicator!=null){
//			indicator.style.display = 'block';
//		}
		
		HttpRequest.onreadystatechange = function()
		{
		   if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
		   {
			    if(HttpRequest.responseText.indexOf('err=')!=1){
					outObj.innerHTML = HttpRequest.responseText;
					//outObj.className = "msg warning";					
			   }
			   //if(indicator!=null){indicator.style.display = 'none';indicator.innerHTML = "";}
		   }
		}
		//HttpRequest.send(null);
		HttpRequest.open('POST', actionURL, true);
		HttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		HttpRequest.setRequestHeader("Content-length", getStr.length);
		HttpRequest.setRequestHeader("Connection", "close");
		HttpRequest.send(getStr);
		return;
	}catch(ex){}	
}

function ChangePassword(_form, _outObj) {
	try{
		var getStr = "type=changepassword&antiCache=" + Math.random();
		var inputList = _form.getElementsByTagName("input");
		var outObj = document.getElementById(_outObj);
		var indicatorObj = document.getElementById('processing')
		
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		
		if (!HttpRequest) return;		
		if((_form==null)||(trim(' ' + _form)=='')){return;}
		if((_outObj==null)||(trim(' ' + _outObj)=='')){return;}
			
		if(!outObj){return;}
		
		for (i=0; i<inputList.length; i++) {
			 if (inputList[i].type == "text" || inputList[i].type == "password" || inputList[i].type == "hidden") {
				   getStr += "&" + inputList[i].id + "=" + encodeURI(inputList[i].value);
			 }   
		  }
		
		//indicatorObj.innerHTML = '<img src="/images/data/indicator.gif" />';
		var actionURL = "ajax/actions.aspx";		
		
		//window.location = actionURL;
		//return;
		//var indicator = document.getElementById('processDiv');
//		if(indicator!=null){
//			indicator.style.display = 'block';
//		}
		
		HttpRequest.onreadystatechange = function()
		{
		   if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
		   {
			    if(HttpRequest.responseText.indexOf('err=')!=1){
					outObj.innerHTML = HttpRequest.responseText;
					//outObj.className = "msg warning";					
			   }
			   //if(indicator!=null){indicator.style.display = 'none';indicator.innerHTML = "";}
		   }
		}
		//HttpRequest.send(null);
		HttpRequest.open('POST', actionURL, true);
		HttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		HttpRequest.setRequestHeader("Content-length", getStr.length);
		HttpRequest.setRequestHeader("Connection", "close");
		HttpRequest.send(getStr);
		return;
	}catch(ex){}	
}

function addToCart(_pid){
	try{
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		var obj = document.getElementById('cartqty');
		//if(!obj){return;}
		if(obj!=null) obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=addcart&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){
					if(obj!=null){obj.innerHTML = HttpRequest.responseText;	}
					alert(LABEL_AddCartSuccess);
					showCart()
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}

function showCart(){
	try{
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		var obj = document.getElementById('shoppingcart');
		if(!obj){return;}
		//if(obj!=null) obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=showcart&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){
					if(obj!=null){obj.innerHTML = HttpRequest.responseText;	}
					var inputs = document.getElementsByName('input', 'txtqty');
					for (var i=0;i<inputs.length;i++){
						addEventScott(inputs[i], 'blur', checkNumberValue, false);
					}
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}

function removeCart(_pid){
	try{
//		if (window.confirm(LABEL_AreYouSureRemove)==false){
//			return(false);
//		}
        if (window.confirm(LABEL_AreYouSureRemove)==false){
		return(false);
		}
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		var obj = document.getElementById('cartqty');
		//if(!obj){return;}
		if(obj!=null) obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=removecart&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){
					if(obj!=null){obj.innerHTML = HttpRequest.responseText;	}
					showCart()
					//alert(LABEL_RemoveCartSuccess);
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}

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 changeLang(_lang) {
	try {
		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){
					window.location.reload();   	
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}

function confirmOrder() {
	try{
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		var obj = document.getElementById('shoppingcart');
		//if(!obj){return;}
		if(obj!=null) obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=confirmorder&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){
					if(obj!=null) {
						obj.innerHTML = HttpRequest.responseText;
					}
			   }else{
				   if(HttpRequest.responseText.indexOf('err=NoProduct')==0){
					   alert(EmptyCartError);
				   }
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}	
}

function updateCart() {
	try {
		var inputs = document.getElementsByName('txtqty');
		var _id, _qty;
		_id = '';
		for (var i=0;i<inputs.length;i++){
			if(_id==''){
				_id = inputs[i].alt;
				_qty = inputs[i].value;
			}else{
				_id = _id + ',' + inputs[i].alt;
				_qty = _qty + ',' + inputs[i].value;
			}
		}
		if(_id=='')return(false);
		
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		var obj = document.getElementById('shoppingcart');
		//if(!obj){return;}
		if(obj!=null) obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=updatecart&id=" + window.encodeURIComponent(_id) + "&qty=" + window.encodeURIComponent(_qty) + "&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){
					showCart();
					alert(LABEL_UpdateCartSuccess);
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){alert(ex.tostring + "BBB");}	
}

function sendOrder() {
	try {
		var _bCookie = '0';
		var _frm = document.getElementById('frmMemberInfo');
		if (_frm==null) return(false);
		var arrNotRequired = 'txtMobile,txtNote';
		if (validate("frmMemberInfo", " *", arrNotRequired)==true) {
			if (window.confirm(LABEL_SaveCookie)){
				_bCookie = '1';
			}else{
				_bCookie = '-1';
			}
		}
		
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		var errDiv = document.getElementById('errorDiv');
		if(errDiv!=null) errDiv.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var obj = document.getElementById('shoppingcart');
		//if(!obj){return;}
		//if(obj!=null) obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=sendorder&name=" + window.encodeURIComponent(_frm.txtFullname.value) + "&add=" + window.encodeURIComponent(_frm.txtAddress.value) + "&city=" + window.encodeURIComponent(_frm.txtCity.value) + "&phone=" + window.encodeURIComponent(_frm.txtTelephone.value) + "&mobile=" + window.encodeURIComponent(_frm.txtMobile.value) + "&email=" + window.encodeURIComponent(_frm.txtEmail.value) + "&note=" + window.encodeURIComponent(_frm.txtNote.value) + "&cookie=" + window.encodeURIComponent(_bCookie) + "&rd=" + Math.random();
		alert("b");
		//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){
				    if(HttpRequest.responseText.indexOf('<!--cart error-->')>0){
						//error
						if(errDiv!=null){
							errDiv.className = 'errordiv';
							errDiv.innerHTML = HttpRequest.responseText;
						}
					}else{
						//success
						if(obj!=null) {
							obj.innerHTML = HttpRequest.responseText;
						}
					}
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}

function generalSearch(){
	try{
		var _frm = document.getElementById('frmsearch');
		_frm.action = 'result.aspx';
		_frm.submit();
	}catch(ex){}
}
/*function changeSearchType(_oid, _type, _selectedValue){
	try {
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')||(_type=='')||(_type==null)){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		//obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=getcat&cattype=" + window.encodeURIComponent(_type) + "&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){}
}*/
function searchPaging(_oid, _keywords, _searchtype, _searchcat, _page) {
	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=searchpaging&keywords=" + window.encodeURIComponent(_keywords) + "&stype=" + window.encodeURIComponent(_searchtype) + "&scat=" + window.encodeURIComponent(_searchcat) + "&page=" + window.encodeURIComponent(_page) + "&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){}
}
//============================================================================================================
// END Ajax function
//============================================================================================================

// Homepage
function ValidForm() {	
	var obj = document.getElementById('txtcheckin')
	if(obj.value == ''){
		alert('invalid date !');
		obj.focus();
		return false;
	}
	if(isDate(obj.value) == false){
		alert('invalid date !')
		obj.focus();
		return false;
	}
	if(CompareToToday(obj.value) < 0 ){
		alert('invalid date !')
		obj.focus();
		return false;
	}
	var obj = document.getElementById('txtcheckout')
	if(obj.value == ''){
		alert('invalid date !');
		obj.focus();
		return false;
	}
	if(isDate(obj.value) == false){
		alert('invalid date !')
		obj.focus();
		return false;
	}
	if(CompareToToday(obj.value) < 0 ){
		alert('invalid date !')
		obj.focus();
		return false;
	}
	if(CompareDate(document.getElementById('txtcheckin').value, obj.value) > 0) {
		alert('invalid date !')
		obj.focus();
		return false;
	}
	document.getElementById('frmbooking').submit();
	//document.getElementById('txtcheckin').form.submit();
	return true;
}

var dateSelector, dateSelector2;
function loadCalendar() {
	dateSelector = new calendar1(document.getElementById('frmbooking').elements['txtcheckin']);
	dateSelector.year_scroll = true;
	dateSelector.time_comp = false;
	
	dateSelector2 = new calendar1(document.getElementById('frmbooking').elements['txtcheckout']);
	dateSelector2.year_scroll = true;
	dateSelector2.time_comp = false;
}
