var uagent=navigator.userAgent.toLowerCase();
var win = window;
var n = 0;
var isIE, isGecko, isOpera, isSafari, isKonqueror, isWin, isMac, uaVers;
	isIE=(uagent.indexOf("msie")!=-1 && document.all);
	t2g2_bIsIE5=(uagent.indexOf("msie")!=-1 && document.all);
	isGecko = (uagent.indexOf("gecko") != -1);
	isOpera = (uagent.indexOf("opera") !=-1); 
	isSafari = (uagent.indexOf("safari") != -1);
	isKonqueror = (uagent.indexOf("konqueror") != -1);
	isWin    =  ( (uagent.indexOf("win") != -1) || (uagent.indexOf("16bit") !=- 1) );
	isMac    = ( (uagent.indexOf("mac") != -1) || (navigator.vendor == "Apple Computer, Inc.") );
	uaVers   = parseInt(navigator.appVersion);
function get_cookie( name ) {
	cname =  name + '=';
	cpos  = document.cookie.indexOf( cname );
	if ( cpos != -1 ) {
		cstart = cpos + cname.length;
		cend   = document.cookie.indexOf(";", cstart);
		if (cend == -1) {
			cend = document.cookie.length;
		}
		return unescape( document.cookie.substring(cstart, cend) );
	}
	return null;
}
function set_cookie( name, value, cookiedate ) {
	expire = "";
	domain = "";
	path   = "/";
	if ( cookiedate ) {
		expire = "; expires=Wed, 1 Jan 2020 00:00:00 GMT";
	}
	document.cookie =  name + "=" + value + "; path=" + path + expire + domain + ';';
}
function multi_page_jump( url_bit, totalposts, perpage ) {
	pages = 1;
	cur_pp = "current page";
	curpage  = 1;
	if ( totalposts % perpage == 0 ) {
		pages = totalposts / perpage;
	} else 	{
		pages = Math.ceil( totalposts / perpage );
	}
	msg = "Please enter a page number, the largest number of pages:" + pages;
	if ( cur_pp > 0 ) {
		curpage = cur_pp / perpage;
		curpage = curpage -1;
	}
	show_page = 1;
	if ( curpage < pages ) {
		show_page = curpage + 1;
	}
	if ( curpage >= pages ) {
		show_page = curpage - 1;
	} else 	{
 		show_page = curpage + 1;
 	}
	userPage = prompt( msg, show_page );
	if ( userPage > 0  ) {
		if ( userPage < 1 ) {
			userPage = 1;
		}
		if ( userPage > pages ) { 
			userPage = pages;
		}
		if ( userPage == 1 ) {
			start = 0;
		} else {
			start = (userPage - 1) * perpage;
		}
		window.location = url_bit + "&page=" + start;
	}
}

function my_getbyid(id) {
	itm = null;
	if (document.getElementById) {
		itm = document.getElementById(id);
	} else if (document.all)	{
		itm = document.all[id];
	} else if (document.layers) {
		itm = document.layers[id];
	}
	return itm;
}

function PopUp(url, name, width,height,center,resize,scroll,posleft,postop) {
	showx = "";
	showy = "";
	if (posleft != 0) { X = posleft }
	if (postop  != 0) { Y = postop  }
	if (!scroll) { scroll = 1 }
	if (!resize) { resize = 1 }
	if ((parseInt (navigator.appVersion) >= 4 ) && (center)) {
		X = (screen.width  - width ) / 2;
		Y = (screen.height - height) / 2;
	}
	if ( X > 0 )	{ showx = ',left='+X; }
	if ( Y > 0 )	{ showy = ',top='+Y; }
	if (scroll != 0) { scroll = 1 }
	var Win = window.open( url, name, 'width='+width+',height='+height+ showx + showy + ',resizable='+resize+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no');
}
function stacksize(thearray) {
	for (i = 0 ; i < thearray.length; i++ ) {
		if ( (thearray[i] == "") || (thearray[i] == null) || (thearray == 'undefined') ) return i;
	}
	return thearray.length;
}
function pushstack(thearray, newval) {
	arraysize = stacksize(thearray);
	thearray[arraysize] = newval;
}
function popstack(thearray) {
	arraysize = stacksize(thearray);
	theval = thearray[arraysize - 1];
	delete thearray[arraysize - 1];
	return theval;
}
function CheckAll(fmobj) {
	for (var i=0;i<fmobj.elements.length;i++) {
		var e = fmobj.elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox') && (!e.disabled)) {
			e.checked = fmobj.allbox.checked;
		}
	}
}
function HighlightAll(str) {
    if (document.all){
        var rng = document.body.createTextRange();
        rng.moveToElementText(str);
        rng.scrollIntoView();
        rng.select();
        rng.execCommand("Copy");
        rng.collapse(false);
		setTimeout("window.status=''",1800)
    }
}
function redirlocate(object) {
	if(object.options[object.selectedIndex].value != '') {
		window.location = (object.options[object.selectedIndex].value);
	}
}

function calculate_byte( sTargetStr ) { 
	var sTmpStr, sTmpChar; 
	var nOriginLen = 0; 
	var nStrLength = 0; 

	sTmpStr = new String(sTargetStr); 
	nOriginLen = sTmpStr.length; 

		for ( var i=0 ; i < nOriginLen ; i++ ) { 
		sTmpChar = sTmpStr.charAt(i); 
			if (escape(sTmpChar).length > 4) { 
			nStrLength += 2; 
			} else if (sTmpChar!='\r') { 
			nStrLength ++; 
			} 
		} 
	return nStrLength; 
} 
function pop_win(theUrl, winName, theWidth, theHeight)
{
	if (winName == '') { winName = 'Preview'; }
	if (theHeight == '') { theHeight = 400; }
	if (theWidth == '') { theWidth = 400; }
	window.open(theUrl,winName,'width='+theWidth+',height='+theHeight+',resizable=yes,scrollbars=yes');
}

function expandmenu()
{
	saved = new Array();
	joined = new Array();
	clean = new Array();
	if ( tmp = get_cookie('cpcollapseprefs') ) {
		saved = tmp.split(",");
	}
	joined = menu_ids.split(",");
	for( c = 0 ; c < joined.length; c++ ) {
		clean[clean.length] = joined[c];
	}
	set_cookie( 'cpcollapseprefs', clean.join(','), 1 );
	window.location=window.location;
}
function collapsemenu()
{
	set_cookie( 'cpcollapseprefs', '', 1 );
	window.location=window.location;
}

function checkcol(IDnumber,status)
{
	var f = document.cpform;
	str_part = '';
	if (IDnumber == 1) { str_part = 'read' }
	if (IDnumber == 2) { str_part = 'repl' }
	if (IDnumber == 3) { str_part = 'star' }
	if (IDnumber == 4) { str_part = 'uplo' }
	if (IDnumber == 5) { str_part = 'show' }
	for (var i = 0 ; i < f.elements.length; i++) {
		var e = f.elements[i];
		if ( e.type == 'checkbox' ) {
			s = e.name;
			a = s.substring(0, 4);
			if (a == str_part) {
				if ( status == 1 ) {
					e.checked = true;
				} else {
					e.checked = false;
				}
			}
		}
	}
}

function checkrow(IDnumber,status)
{
	var f = document.cpform;
	str_part = '';
	if ( status == 1 ) {
		mystat = 'true';
	} else {
		mystat = 'false';
	}
	eval( 'f.read_'+IDnumber+'.checked='+mystat );
	eval( 'f.reply_'+IDnumber+'.checked='+mystat );
	eval( 'f.start_'+IDnumber+'.checked='+mystat );
	eval( 'f.upload_'+IDnumber+'.checked='+mystat );
	eval( 'f.show_'+IDnumber+'.checked='+mystat );
}

function updatepreview()
{
	var formobj  = document.cpform;
	var dd_weekday  = new Array();
	dd_weekday[0]   = '周日';
	dd_weekday[1]   = '周一';
	dd_weekday[2]   = '周二';
	dd_weekday[3]   = '周三';
	dd_weekday[4]   = '周四';
	dd_weekday[5]   = '周五';
	dd_weekday[6]   = '周六';
	var output       = '';
	chosen_min   = formobj.minute.options[formobj.minute.selectedIndex].value;
	chosen_hour  = formobj.hour.options[formobj.hour.selectedIndex].value;
	chosen_weekday  = formobj.weekday.options[formobj.weekday.selectedIndex].value;
	chosen_monthday  = formobj.monthday.options[formobj.monthday.selectedIndex].value;
	var output_min   = '';
	var output_hour  = '';
	var output_day   = '';
	var timeset      = 0;
	if ( chosen_monthday == -1 && chosen_weekday == -1 ) {
		output_day = '';
	}
	if ( chosen_monthday != -1 ) {
		output_day = '在每月 '+chosen_monthday+' 号，';
	}
	if ( chosen_monthday == -1 && chosen_weekday != -1 ) {
		output_day = '于' + dd_weekday[ chosen_weekday ]+'.';
	}
	if ( chosen_hour != -1 && chosen_min != -1 ) {
		output_hour = '在 '+chosen_hour+':'+formatnumber(chosen_min)+' 的时候运行';
	} else {
		if ( chosen_hour == -1 ) {
			if ( chosen_min == 0 ) {
				output_hour = '每小时运行一次';
			} else {
				if ( output_day == '' ) {
					if ( chosen_min == -1 ) {
						output_min = '每分钟运行一次';
					} else {
						output_min = '每隔 '+chosen_min+' 分钟运行一次。';
					}
				} else {
					output_min = '第一个 '+formatnumber(chosen_min)+' 分钟的时候执行';
				}
			}
		} else {
			if ( output_day != '' ) {
				output_hour = '到 ' + chosen_hour + ':00' + ' 运行';
			} else {
				output_hour = '每隔 ' + chosen_hour + ' 小时运行';
			}
		}
	}
	output = output_day + ' ' + output_hour + ' ' + output_min;
	formobj.showcron.value = output;
}
							
function formatnumber(num)
{
	if ( num == -1 ) {
		return '00';
	}
	if ( num < 10 ) {
		return '0'+num;
	} else {
		return num;
	}
}

function findInPage(tmpl, str)
{
	var txt, i, found;
	if (str == '') {
		return false;
	}
	if (isGecko) {
		if (!win.find(str, false, true)) {
			while(win.find(str, false, true)) {
				n++;
			}
		} else {
			n++;
		}
		if (n == 0) {
			alert('未找到要搜索的字符');
		}
	}
	if (isIE) {
		txt = tmpl.createTextRange();
		for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
			txt.moveStart('character', 1);
			txt.moveEnd('textedit');
		}
		if (found) {
			txt.moveStart('character', -1);
			txt.findText(str);
			txt.select();
			txt.scrollIntoView(true);
			n++;
		} else {
			if (n > 0) {
				n = 0;
				findInPage(tmpl, str);
			}
			else { alert('未找到要搜索的字符'); }
		}
	}
	return false;
}
var postmaxchars = "20000";
var postminchars = "4";
function getMessageLength() {
	mxeGet();
	return calculate_byte(mxeTxH.value); 
}
function checklength() {
	if (postmaxchars != 0) message = "最大允许的长度为 "+postmaxchars+" 个字符。";
	else message = "";
	var messageLength = getMessageLength();
	alert("现在你已经输入了 "+messageLength+" 个字符。" + message);
}
function calculate_byte( sTargetStr ) { 
	var sTmpStr, sTmpChar; 
	var nOriginLen = 0; 
	var nStrLength = 0; 

	sTmpStr = new String(sTargetStr); 
	nOriginLen = sTmpStr.length; 

		for ( var i=0 ; i < nOriginLen ; i++ ) { 
		sTmpChar = sTmpStr.charAt(i); 
			if (escape(sTmpChar).length > 4) { 
			nStrLength += 2; 
			} else if (sTmpChar!='\r') { 
			nStrLength ++; 
			} 
		} 
	return nStrLength; 
}
function submit_form(){
	var subform = document.subform;
	mxeGet();
	var length = calculate_byte(mxeTxH.value);
	if (length < 4 && length > 20000) {
		alert("输入内容字数不符。");
		return false;
	}
}

function ChangeLan(id)
{
	my_getbyid("bai_tour").className = "";
	my_getbyid("bai_hotel").className = "";
	my_getbyid("bai_"+id).className = "bj_lan";
	my_getbyid("search_type").value = id;
}

function GoLinks(url)
{
	//window.open(url);
	window.location.href(url);
}

function PostSearch()
{
	var Search_key = my_getbyid("search_key").value;
	var Search_type = my_getbyid("search_type").value;
	if(Search_type == 'tour'){
		if(Search_key){
			var url = web_host+"/lines.php?action=search&model=1&keyword="+Search_key;
			window.location.href(url);
		}
	}else if(Search_type == 'hotel'){
		var url = web_host+"/hotel.php?action=search_hotel&hotelname="+Search_key;
		window.location.href(url);
	}
}

function ChangClass(id,classname)
{
	var area = my_getbyid(id);
	area.className = classname;
}

function ShowDiv(id,other)
{
	var otheID = other.split(",");
	for (var i in otheID){
		my_getbyid(otheID[i]).style.display = "none";
	}
	my_getbyid(id).style.display = "block";
}

function switchMenu(modcontent,modk) 
{
	for(i=1; i <5; i++) {
		if (i==modk) {
			document.getElementById(modcontent+i).className="nav_submenu";
		}else{
			document.getElementById(modcontent+i).className="nav_submenu_no";
		}
	}
}

function switchSearch(modcontent,modk) {    
    for(i=1; i<5;i++){
        if (i==modk) {
            document.getElementById(modcontent+'_'+i).className="tab_searched";
            document.getElementById('con_'+modcontent+'_'+i).className="search_main_1";
        }else{
            document.getElementById(modcontent+'_'+i).className="tab_search";
            document.getElementById('con_'+modcontent+'_'+i).className="search_main_2";
        }
    }    
}

function switchOut(mod,order,num) {
     for(i=1; i<num+1;i++){
        
        if (i==order) {
           document.getElementById(mod+'_nav_'+i).className="out_select";
           document.getElementById(mod+'_tab_'+i).style.display="block";

        }else{ 
           document.getElementById(mod+'_nav_'+i).className="out_selected";
           document.getElementById(mod+'_tab_'+i).style.display="none";     
        }
    }     
}
