function getbyid(id) {
	return document.getElementById(id);
}

function refreshcode(siteurl){
	getbyid("Chcode").innerHTML = '<img class="vcodeimg" src="'+siteurl+'/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 get_subcity(upid){
	var url = "do.php?op=subcity&upid="+upid;
	var show = getbyid("_subcity"); 
	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 checkall(form) {
	for(var i = 0;i < form.elements.length; i++) {
		var e = form.elements[i];
		if (e.name != 'chkall' && e.disabled != true && e.type == 'checkbox') {
			e.checked = form.chkall.checked;
		}
	}
}

function selectfile(form,obj,url,width,height) 
{
	var objname= form.obj;
	var obj = eval('document.'+objname);
	//showModalDialog ;dialogTop:1px;dialogLeft:1px
	result = window.showModalDialog(url+'?objname='+objname,null,'help:no;status:no;scroll:no;dialogWidth='+width+'px;dialogHeight='+height+'px');
	if(result!=null){form.obj.value=result;}
}

function gomu(){
	window.location=document.getElementById("menu").value
}
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 smptabs(divid,now){

	var tabsdiv = getbyid(divid);
	var lis=tabsdiv.getElementsByTagName("li");

	for(var i=0;i<lis.length;i++){
		var s = lis[i].getElementsByTagName("div");
		var p = lis[i].getElementsByTagName("p");
		
		
		if (now == i){
			s[0].style.display = "";
		}else{
			s[0].style.display = "none";
 			void function (i) {
				p[0].onmouseover = function () {smptabs(divid,i);};
			}(i);
			
		}
	}
}

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 upimage(id) 
{
	result = window.showModalDialog('too-plugins/upimage/upimage.php',null,'help:no;status:no;scroll:no;dialogWidth=400px;dialogHeight=260px');
	if(result!=null){
		getbyid(id).value=result;
	}
}

function upvideo(id) 
{
	result = window.showModalDialog('too-plugins/swfupload/up.php',null,'help:no;status:no;scroll:no;dialogWidth=460px;dialogHeight=260px');
	if(result!=null){
		getbyid(id).value=result;
	}
}