function getbyid(id) {
	return document.getElementById(id);
}

function refreshcode(){
	getbyid("Chcode").innerHTML = '<img class="vcodeimg" src="too-includes/code.php" />';
}

function InitAjax(){
	var ajax = false; 
	try { 
		ajax = new ActiveXObject("Msxml2.XMLHTTP"); 
	}catch(e){ 
		try { 
			ajax = new ActiveXObject("Microsoft.XMLHTTP"); 
		} catch (E) { 
			ajax = false; 
		} 
	}
	if (!ajax && typeof XMLHttpRequest!='undefined') { 
		ajax = new XMLHttpRequest(); 
	} 
	return ajax;
}

function get_custominput(catid,itemid){
	var url = "do.php?op=custom&type=info&catid="+catid+"&itemid="+itemid;
	var show = getbyid("_custom"); 
	var ajax = InitAjax();
	ajax.open("GET", url, true); 
	ajax.onreadystatechange = function() { 
		if (ajax.readyState == 4 && ajax.status == 200) { 
			show.innerHTML = ajax.responseText; 
		} 
	}
	ajax.send(null); 
}




function tabmenu (pre,id,num){
	for (var i = 1 ; i <= num ; i ++ ){
		var t = pre + i ;
		var tab = pre + 'tab_' + i ;
		if (i == id){
			getbyid(t).className = "set";
			getbyid(tab).style.display = "";
		}else{
			getbyid(t).className = "";
			getbyid(tab).style.display = "none";
		}
	}
}

function CheckForm(theForm){
	var obj = theForm || event.srcElement;
	var count = obj.elements.length;
	for(var i=0;i<count;i++){
		with(obj.elements[i]){
			var _datatype = getAttribute("datatype");
			var _msg = getAttribute("msg");
			var _value = getAttribute("value");
			if (_datatype == 'txt' && !IsEmpty(_value)){
				alert(_msg);
				obj.elements[i].focus();
				return false;
			}
			if (_datatype == 'email' && !IsMail(_value)){
				alert(_msg);
				obj.elements[i].focus();
				return false;
			}
		}
	}
}
function IsEmpty(str){
	if (str == '')
	return false;
	else
	return true;
}

function IsMail(mail){ 
	var patrn = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; 
	if (!patrn.test(mail)) 
	return false; 
	else 
	return true; 
}


function showthisimg(src,id,nums)
{
	for (var i = 0 ; i < nums ; i ++ ){
		var tab = 'ili_' + i ;
		if (i == id){
			getbyid(tab).className = "set";
		}else{
			getbyid(tab).className = "";
		}
	}
	//getbyid("showimg").src = src;	
}

function setsort(name, val)
{
	var str = randomChar(10);
	var url = 'setcookie.php?name='+name+'&val='+val+'&url='+url+'&str='+str;
	//var show = getbyid("_custom"); 
	var ajax = InitAjax();
	ajax.open("GET", url, true); 
	ajax.onreadystatechange = function() { 
		if (ajax.readyState == 4 && ajax.status == 200) { 
			//location.reload;
			window.location.href=window.location.href; 
		} 
	}
	ajax.send(null); 
	
}

function randomChar(l)
{
   var   x="0123456789qwertyuioplkjhgfdsazxcvbnm";
   var   tmp="";
   for(var i=0; i< l; i++)
   {
		tmp   +=   x.charAt(Math.ceil(Math.random()*100000000)%x.length);
   }
   return   tmp;
}
