// 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;
	}	
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

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
//============================================================================================================

//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();
		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;		
					$("#slider").easySlider();
					$('#gallery a').lightBox(); 
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}

function viewgallery(_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=gallery&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;
					
					$('#gallery a').lightBox(); 
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}

function viewnews(_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=news&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;
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		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;
//		}	alert(ex);
				
		return;
	}catch(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{alert("AAAAAAAAAAAA");
		var getStr = "type=login&antiCache=" + Math.random();
		var inputList = _form.getElementsByTagName("input");
		var outObj = document.getElementById(_outObj);
		var indicatorObj = document.getElementById('processing')
		alert("AAAAAAAAAAAA");
		alert(inputList);
		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 Logout1(_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 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 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 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 getStr = "type=language&lang=" + _lang + "&rd=" + Math.random(); 
		var actionURL = "../ajax/actions.aspx";				
		
		$.ajax({
			type: "POST",
			url: actionURL,
			data: getStr,
			success: function(msg){
				if (msg.indexOf('err=')!=0) {
					//window.location.reload();
					window.location = 'default.aspx';
				}
			}
		});
		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 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;
					obj.innerHTML = HttpRequest.responseText;
					$('.pitem .img').Tooltip({
						track: true,
						opacity: 1,
						fixPNG: true,
						top: -15,
						showBody: "@",
						left: 5
					});	
			   }
			   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('frmcard').elements['txtdate']);
	dateSelector.year_scroll = true;
	dateSelector.time_comp = false;
//	
//	dateSelector2 = new calendar1(document.getElementById('frmbooking').elements['txtcheckout']);
//	dateSelector2.year_scroll = true;
//	dateSelector2.time_comp = false;
}
//Suntech
function viewCats(_oid, _cid, _page, _inum){
	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) + "&inum=" + window.encodeURIComponent(_inum) + "&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;
					$('.pitem .img').Tooltip({
						track: true,
						opacity: 1,
						fixPNG: true,
						top: -15,
						showBody: "@",
						left: 5
					});
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
function viewprovider(obj) {
	var index = obj.selectedIndex;
	if (obj.options[index].value != "0") {
		window.location = obj.options[index].value;
	}
}
function Logout() {
	try {	    
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		var actionURL = "ajax/actions.aspx?type=logout";
		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 = '/category.aspx';   	
			   }
			   if(indicator!=null){indicator.style.display = 'none';indicator.innerHTML = "";}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
// Specific functions

function viewTabPage(_oid, _pid, _fid){
	try{
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')){return;}
		window.location = "/faq.aspx?fcat="+_pid+"&page="+_fid+ "&rd=" + Math.random();		  
		return;
	}catch(ex){alert(ex.tostring);}
}

function viewTab(_oid, _pid, _fid){
	try{
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')||(_pid==null)||(_pid=='')){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "/ajax/actions.aspx?type=viewtab&fcat=" + _pid + "&page=" + _fid + "&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){alert(ex.tostring);}
}
function getStatus(_obj){
	$('.support').each(function(i){
			var abc = $(this);
			var getStr = "type=onlinestatus&user=" + $(this).attr('id') + "&rd=" + Math.random(); 
			var actionURL = "/ajax/actions.aspx";		
			$.ajax({
				type: "POST",
				url: actionURL,
				data: getStr,
				success: function(msg){
					if (msg.indexOf('err=')!=0) {
						//window.location.reload(); 
						if(msg=='00'){
							abc.addClass('offline');
						}else{
							abc.addClass('online');
						}
					}
				}
			});
	});
}

//Bocci Load Product Price -------------------------------------------------------------
function viewprice(_oid, _pid, _catid, _fea, _ifea) {
	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=price&pid=" + window.encodeURIComponent(_pid) + "&cat=" + window.encodeURIComponent(_catid).value + "&fea=" + window.encodeURIComponent(_fea) + "&ifea=" + document.getElementById(_ifea) + "&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 getPrice(_oid, _ifea, _curFeature, _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);
		//var obj = document.getElementById('price');
		
		if(!obj){return;}
		
		obj.innerHTML = '<img src="/images/assets/indicator.gif" />';

		var actionURL = "ajax/actions.aspx?type=viewprice&pid=" + window.encodeURIComponent(_pid) + "&fea=" + window.encodeURIComponent(_curFeature) + "&ifea=" + window.encodeURIComponent(_ifea) + "&rd=" + Math.random();
		//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){
                    obj.innerHTML = HttpRequest.responseText;
                    //window.location = "/home.aspx";   	
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}

function updateCart(_pid, _fea, _qty) {
	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=updatecart&pid=" + window.encodeURIComponent(_pid) + "&fea=" + window.encodeURIComponent(_fea) + "&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){
			        if(_qty/1 == _qty){
			            if (_qty > 9999){alert("Update Cart Fail - (Quantity > 9999)!Contact with us for Quantity this product!");}
			            //else{//alert("Update Cart Success!");}
				       }
				     //else{
				        //alert("Must is number for quantity!");
				     //}
				       obj.innerHTML = HttpRequest.responseText;
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){alert(ex.tostring + "BBB");}	
}
function updateCart1(_pid, _fea, _qty) {
	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=updatecart1&pid=" + window.encodeURIComponent(_pid) + "&fea=" + window.encodeURIComponent(_fea) + "&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){
			        if(_qty/1 == _qty){
			            if (_qty > 9999){alert("Update Cart Fail - (Quantity > 9999)!Contact with us for Quantity this product!");}
			            //else{//alert("Update Cart Success!");}
				       }
				     //else{
				        //alert("Must is number for quantity!");
				     //}
				       obj.innerHTML = HttpRequest.responseText;
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){alert(ex.tostring + "BBB");}	
}

function removeCart(_pid,_fea){
	try{
		if (window.confirm("Are You Sure Remove?")==false){
			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=removecart&pid=" + window.encodeURIComponent(_pid) + "&fea=" + window.encodeURIComponent(_fea) + "&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();
					obj.innerHTML = HttpRequest.responseText;
					//alert("Remove Cart Success");
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}

function addToCart(_oid,_pid,_fea,_pri){
	try{

        if (_pri/1 != _pri){
            //alert("No price for product! Add to cart fail!");
            return;
        } 
        
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
//		var obj = document.getElementById('cartqty');
        var obj = document.getElementById(_oid);
		//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) + "&fea=" + window.encodeURIComponent(_fea) + "&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;	}
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){alert(ex.message);}
}

function clearcart(){
	try{
//	    if (window.confirm("Are You Sure Clear?")==false){
//			return(false);
//		}
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		var actionURL = "ajax/actions.aspx?type=clearcart&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){
//                    alert("Remove your cart success!");
                    window.location = "/category.aspx";   	
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
function LoadLogin(_oid,_email,_pass) {
	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=" + window.encodeURIComponent(_email) + "&rd=" + window.encodeURIComponent(_pass) + "&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 upprocode(_pro){
	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=procode&pro=" + window.encodeURIComponent(_pro) + "&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();
					obj.innerHTML = HttpRequest.responseText;
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}

function upshipping(_ship){
	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=upshipping&ship=" + window.encodeURIComponent(_ship) + "&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;	}
					obj.innerHTML = HttpRequest.responseText;
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
function updateCartList(_list, _id){
	try {
         
        var Qlist = "";
        var txtText = "";
        for (i=0; i<_list; i++){           
            txtText = 'txtquanty' + i;
            Qlist += document.getElementById(txtText).value + ',';
        }

		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=updatecartlist&list=" + window.encodeURIComponent(Qlist) + "&iid=" + window.encodeURIComponent(_id) + "&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){
				       obj.innerHTML = HttpRequest.responseText;
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}

function sameinf() {
try {    
    /*var str = "";
    var obj = document.getElementById('chk_sameas');	
	var obj1 = document.getElementById('txt_billing_addr');
	if(obj.checked){
	    if (obj1.value != ''){
		    str += obj1.value + ",";
		}else{str += " " + ",";}
	}
	var obj1 = document.getElementById('txt_billing_addr_2')
	if(obj.checked){
		if (obj1.value != ''){
		    str += obj1.value + ",";
		}else{str += " " + ",";}
	}
	var obj1 = document.getElementById('txt_billing_city')
	if(obj.checked){
		if (obj1.value != ''){
		    str += obj1.value + ",";
		}else{str += " " + ",";}
	}
	var obj1 = document.getElementById('slt_billing_country')
	if(obj.checked){
		if (obj1.value != ''){
		    str += obj1.value + ",";
		}else{str += " " + ",";}
	}
	var obj1 = document.getElementById('slt_billing_province')
	if(obj.checked){
		if (obj1.value != ''){
		    str += obj1.value + ",";
		}else{str += " " + ",";}
	}
	var obj1 = document.getElementById('txt_billing_postal')
	if(obj.checked){
	    //if (obj1.value == null){obj1.value = '';}
		//str += obj1.value + ",";
		if (obj1.value != ''){
		    str += obj1.value + ",";
		}else{str += " " + ",";}
	}
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		var obj = document.getElementById('shipinf');
		//if(!obj){return;}
		if(obj!=null) obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=sameinf&str=" + str + "&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){
				       obj.innerHTML = HttpRequest.responseText;
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;*/
		$('#billinf input').each(function(i){
			if($('#chk_sameas').attr('checked'))
				$('#shipinf input[title='+$(this).attr('title')+']').val($(this).val());
		});
		$('#billinf select').each(function(event){
			loadstate1();
			if(!!$('#chk_sameas').attr('checked'))
				$('#shipinf select[title='+$(this).attr('title')+']').val($(this).val())
		});
	}catch(ex){}
}
function loadstate() {
try {    	
	    var scountry = document.getElementById('slt_billing_country').value;
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		var obj = document.getElementById('state');
		//if(!obj){return;}
		if(obj!=null) obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=loadstate&scoun=" + scountry + "&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){
				       obj.innerHTML = HttpRequest.responseText;
					  if(HttpRequest.responseText.indexOf('<p>')>0) 
					  	  obj.style.display='block';
					   else
					   		obj.style.display='none';
						$('#billinf select').each(function(event){
							if(!!$('#chk_sameas').attr('checked'))
								$('#shipinf select[title='+$(this).attr('title')+']').val($(this).val())
						});
						$('#billinf input').each(function(i){
							if($('#chk_sameas').attr('checked'))
								$('#shipinf input[title='+$(this).attr('title')+']').val($(this).val());
						});
						$('#billinf input').keyup(function(event){
							if(!!$('#chk_sameas').attr('checked'))
								$('#shipinf input[title='+$(this).attr('title')+']').val($(this).val())
						});
						$('#billinf select').change(function(event){
							if($(this).attr('id')=='slt_billing_country') loadstate();
							if($(this).attr('id')=='slt_shipping_country') loadstate1();
							if(!!$('#chk_sameas').attr('checked')){
								$('#shipinf select[title='+$(this).attr('title')+']').val($(this).val());
								if($(this).attr('id')=='slt_billing_country') loadstate1();
							}
						});
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}

function loadstate1() {
try {    	
	    var scountry = document.getElementById('slt_shipping_country').value;
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		var obj = document.getElementById('shipstate');
		//if(!obj){return;}
		if(obj!=null) obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=loadstate1&scoun=" + scountry + "&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){
				       obj.innerHTML = HttpRequest.responseText;
					   if(HttpRequest.responseText.indexOf('<p>')>0) 
					  	  obj.style.display='block';
					   else
					   		obj.style.display='none';
						$('#billinf select').each(function(event){
							if(!!$('#chk_sameas').attr('checked'))
								$('#shipinf select[title='+$(this).attr('title')+']').val($(this).val())
						});
						$('#billinf input').each(function(i){
							if($('#chk_sameas').attr('checked'))
								$('#shipinf input[title='+$(this).attr('title')+']').val($(this).val());
						});
						$('#billinf input').keyup(function(event){
							if(!!$('#chk_sameas').attr('checked'))
								$('#shipinf input[title='+$(this).attr('title')+']').val($(this).val())
						});
						$('#billinf select').change(function(event){
							if($(this).attr('id')=='slt_billing_country') loadstate();
							if($(this).attr('id')=='slt_shipping_country') loadstate1();
							if(!!$('#chk_sameas').attr('checked')){
								$('#shipinf select[title='+$(this).attr('title')+']').val($(this).val());
								if($(this).attr('id')=='slt_billing_country') loadstate1();
							}
						});
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
function loadproduct(_id){
	try {
         
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		var obj = document.getElementById('productajax');
		//if(!obj){return;}
		//if(obj!=null) obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=loadproduct&pid=" + window.encodeURIComponent(_id) + "&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){
				       obj.innerHTML = HttpRequest.responseText;
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
//** Animated Collapsible DIV v2.0- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com.
//** May 24th, 08'- Script rewritten and updated to 2.0.
//** June 4th, 08'- Version 2.01: Bug fix to work with jquery 1.2.6 (which changed the way attr() behaves).

var animatedcollapse={
divholders: {}, //structure: {div.id, div.attrs, div.$divref}
divgroups: {}, //structure: {groupname.count, groupname.lastactivedivid}
lastactiveingroup: {}, //structure: {lastactivediv.id}

show:function(divids){ //public method
	if (typeof divids=="object"){
		for (var i=0; i<divids.length; i++)
			this.showhide(divids[i], "show")
	}
	else
		this.showhide(divids, "show")
},

hide:function(divids){ //public method
	if (typeof divids=="object"){
		for (var i=0; i<divids.length; i++)
			this.showhide(divids[i], "hide")
	}
	else
		this.showhide(divids, "hide")
},

toggle:function(divid){ //public method
	this.showhide(divid, "toggle")
},

addDiv:function(divid, attrstring){ //public function
	this.divholders[divid]=({id: divid, $divref: null, attrs: attrstring})
	this.divholders[divid].getAttr=function(name){ //assign getAttr() function to each divholder object
		var attr=new RegExp(name+"=([^,]+)", "i") //get name/value config pair (ie: width=400px,)
		return (attr.test(this.attrs) && parseInt(RegExp.$1)!=0)? RegExp.$1 : null //return value portion (string), or 0 (false) if none found
	}
},

showhide:function(divid, action){
	var $divref=this.divholders[divid].$divref //reference collapsible DIV
	if (this.divholders[divid] && $divref.length==1){ //if DIV exists
		var targetgroup=this.divgroups[$divref.attr('groupname')] //find out which group DIV belongs to (if any)
		if ($divref.attr('groupname') && targetgroup.count>1 && (action=="show" || action=="toggle" && $divref.css('display')=='none')){ //If current DIV belongs to a group
			if (targetgroup.lastactivedivid && targetgroup.lastactivedivid!=divid) //if last active DIV is set
				this.slideengine(targetgroup.lastactivedivid, 'hide') //hide last active DIV within group first
				this.slideengine(divid, 'show')
			targetgroup.lastactivedivid=divid //remember last active DIV
		}
		else{
			this.slideengine(divid, action)
		}
	}
},

slideengine:function(divid, action){
	var $divref=this.divholders[divid].$divref
	if (this.divholders[divid] && $divref.length==1){ //if this DIV exists
		var animateSetting={height: action}
		if ($divref.attr('fade'))
			animateSetting.opacity=action
		$divref.animate(animateSetting, $divref.attr('speed')? parseInt($divref.attr('speed')) : 500)
		return false
	}
},

generatemap:function(){
	var map={}
	for (var i=0; i<arguments.length; i++){
		if (arguments[i][1]!=null){
			map[arguments[i][0]]=arguments[i][1]
		}
	}
	return map
},

init:function(){
	var ac=this
	jQuery(document).ready(function($){
		var persistopenids=ac.getCookie('acopendivids') //Get list of div ids that should be expanded due to persistence ('div1,div2,etc')
		var groupswithpersist=ac.getCookie('acgroupswithpersist') //Get list of group names that have 1 or more divs with "persist" attribute defined
		if (persistopenids!=null) //if cookie isn't null (is null if first time page loads, and cookie hasnt been set yet)
			persistopenids=(persistopenids=='nada')? [] : persistopenids.split(',') //if no divs are persisted, set to empty array, else, array of div ids
		groupswithpersist=(groupswithpersist==null || groupswithpersist=='nada')? [] : groupswithpersist.split(',') //Get list of groups with divs that are persisted
		jQuery.each(ac.divholders, function(){ //loop through each collapsible DIV object
			this.$divref=$('#'+this.id)
			if ((this.getAttr('persist') || jQuery.inArray(this.getAttr('group'), groupswithpersist)!=-1) && persistopenids!=null){
				var cssdisplay=(jQuery.inArray(this.id, persistopenids)!=-1)? 'block' : 'none'
			}
			else{
				var cssdisplay=this.getAttr('hide')? 'none' : null
			}
			this.$divref.css(ac.generatemap(['height', this.getAttr('height')], ['display', cssdisplay]))
			this.$divref.attr(ac.generatemap(['groupname', this.getAttr('group')], ['fade', this.getAttr('fade')], ['speed', this.getAttr('speed')]))
			if (this.getAttr('group')){ //if this DIV has the "group" attr defined
				var targetgroup=ac.divgroups[this.getAttr('group')] || (ac.divgroups[this.getAttr('group')]={}) //Get settings for this group, or if it no settings exist yet, create blank object to store them in
				targetgroup.count=(targetgroup.count||0)+1 //count # of DIVs within this group
				if (!targetgroup.lastactivedivid && this.$divref.css('display')!='none' || cssdisplay=="block") //if this DIV was open by default or should be open due to persistence								
					targetgroup.lastactivedivid=this.id //remember this DIV as the last "active" DIV (this DIV will be expanded)
				this.$divref.css({display:'none'}) //hide any DIV that's part of said group for now
			}
		}) //end divholders.each
		jQuery.each(ac.divgroups, function(){ //loop through each group
			if (this.lastactivedivid)
				ac.divholders[this.lastactivedivid].$divref.show() //and show last "active" DIV within each group (one that should be expanded)
		})
		var $allcontrols=$('*[rel]').filter('[@rel^="collapse-"], [@rel^="expand-"], [@rel^="toggle-"]') //get all elements on page with rel="collapse-", "expand-" and "toggle-"
		var controlidentifiers=/(collapse-)|(expand-)|(toggle-)/
		$allcontrols.each(function(){
			$(this).click(function(){
				var relattr=this.getAttribute('rel')
				var divid=relattr.replace(controlidentifiers, '')
				var doaction=(relattr.indexOf("collapse-")!=-1)? "hide" : (relattr.indexOf("expand-")!=-1)? "show" : "toggle"
				return ac.showhide(divid, doaction)
			}) //end control.click
		})// end control.each
		$(window).bind('unload', function(){
			ac.uninit()
		})
	}) //end doc.ready()
},

uninit:function(){
	var opendivids='', groupswithpersist=''
	jQuery.each(this.divholders, function(){
		if (this.$divref.css('display')!='none'){
			opendivids+=this.id+',' //store ids of DIVs that are expanded when page unloads: 'div1,div2,etc'
		}
		if (this.getAttr('group') && this.getAttr('persist'))
			groupswithpersist+=this.getAttr('group')+',' //store groups with which at least one DIV has persistance enabled: 'group1,group2,etc'
	})
	opendivids=(opendivids=='')? 'nada' : opendivids.replace(/,$/, '')
	groupswithpersist=(groupswithpersist=='')? 'nada' : groupswithpersist.replace(/,$/, '')
	this.setCookie('acopendivids', opendivids)
	this.setCookie('acgroupswithpersist', groupswithpersist)
},

getCookie:function(Name){ 
	var re=new RegExp(Name+"=[^;]*", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return null
},

setCookie:function(name, value, days){
	if (typeof days!="undefined"){ //if set persistent cookie
		var expireDate = new Date()
		expireDate.setDate(expireDate.getDate()+days)
		document.cookie = name+"="+value+"; path=/; expires="+expireDate.toGMTString()
	}
	else //else if this is a session only cookie
		document.cookie = name+"="+value+"; path=/"
}

}