﻿var lang = new Array();
var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);

function $$(id) {
  	//return document.getElementById(id);
    if(document.getElementById && document.getElementById(id)) {
		return document.getElementById(id);
    } else if (document.all && document.all(id)) {
		return document.all(id);
    } else if (document.layers && document.layers[id]) {
		return document.layers[id];
    } else {
		return false;
    } 
}
function doane(event) {
	e = event ? event : window.event;
	if(is_ie) {
		e.returnValue = false;
		e.cancelBubble = true;
	} else if(e) {
		e.stopPropagation();
		e.preventDefault();
	}
}

function addfavorite(url,name) {
   if (document.all) {
      window.external.addFavorite(url,name);
   } else if (window.sidebar) {
      window.sidebar.addPanel(name, url, "");
   }
}

function $_GET(name) {
	var getArray = {};
	var get = location.search;
	gets = get.substr(1).split('&');
	for (i in gets) {
		t = gets[i].split('=');
		getArray[t[0]] = t[1];
	}
	return getArray[name];
}
//show hide
function tabhide(id,is_cookie){
	$('#'+id).toggle();
}

//show by cookie
function isshowByCookie(id){
	if($('#'+id)[0].style.display=='none'){
		$.cookie(id,1);
		$('#'+id).show();
	}else{
		$.cookie(id,null);
		$('#'+id).hide();			
	}
}
function rowindex(tr){
	if (is_ie){
		return tr.rowIndex;
	}else{
		table = tr.parentNode.parentNode;
		for (i = 0; i < table.rows.length; i ++ ){
		  	if (table.rows[i] == tr){
				return i;
		  	}
		}
	}
}

//鍒嗙珯鏍囩椤靛垏鎹�
function showdiv(num,id_name,class_name,count){
	for(var id = 1;id<=count;id++){  
		var ss = id_name+id;  
		var nss= id_name+"_"+id;
		if(id==num){ 
			$$(ss).style.display ="block";
			$$(nss).className ='';
		}else{
			$$(ss).style.display ="none";
			$$(nss).className ="";
		}
	}
}
/*
 * 鎵撳紑绐楀彛
 */
//鏅€氱獥鍙�
 function OpenWindow(dialogName,title, pageUrl, width, height, parentWindow, resizable) {
	var iTop  = (screen.height - height) / 2 ;
	var iLeft = (screen.width  - width)  / 2 ;
	
	if (!width) {
		width = screen.width;
	}
	if (!height) {
		height = screen.height;
	}
	if (!resizable) {
		resizable = true;
	}


	var sOption  = "location=no,menubar=no,scrollbars=auto,toolbar=no,dependent=yes,'',minimizable=no,modal=yes,alwaysRaised=yes" +
		",resizable="  + ( resizable ? 'yes' : 'no' ) +
		",width="  + width +
		",height=" + height +
		",top="  + iTop +
		",left=" + iLeft ;

	if ( !parentWindow )
		parentWindow = window ;
	
	var oWindow = parentWindow.open( pageUrl, 'Dialog_' + dialogName, sOption, true );
	
	if ( !oWindow )
	{
		alert('绐楀彛琚嫤鎴紝璇峰叧闂箍鍛婃嫤鎴伐鍏凤紒') ;
		return ;
	}
		
	oWindow.moveTo( iLeft, iTop ) ;
	oWindow.resizeTo( width, height ) ;
	oWindow.focus();
}


//鎺у埗缂栬緫楂樺害
var addH=1;
function addHeight(id) {
	if (!document.getElementById(id)) return flase;
	var comment = document.getElementById(id);
	var nowH = parseInt(comment.style.height);
	if (nowH < 200) {	
		nowH+=138;
		comment.style.height=nowH+"px";
//		addH++;
//		if (addH > 3){ 
//			addH=1;
//		} else {
//			window.setTimeout("addHeight()","10");
//		}
	}else{  //鎵ц鍑忓皬
		minHeight(id);
	}
}

function minHeight(id) {
	if (!document.getElementById(id)) return flase;
	var comment = document.getElementById(id);
	var nowH = parseInt(comment.style.height);
	if (nowH > 200) {
		nowH-=138;
		comment.style.height=nowH+"px";
//		addH++;
//		if (addH > 25){ 
//			addH=1;
//		} else {
//			window.setTimeout("minHeight()","10");
//		}
	}
}


listTolist = function(fromid,toid,isAll) {
	if(isAll == true) {	//鍏ㄩ儴绉诲姩
		$("#"+fromid+" option").each(function() {
			//灏嗘簮list涓殑option娣诲姞鍒扮洰鏍噇ist,褰撶洰鏍噇ist涓凡鏈夎option鏃朵笉鍋氫换浣曟搷浣�.
			$(this).appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));
		});
		$("#"+fromid).empty();	//娓呯┖婧恖ist
	}
	else if(isAll == false) {
		$("#"+fromid+" option:selected").each(function() {
			//灏嗘簮list涓殑option娣诲姞鍒扮洰鏍噇ist,褰撶洰鏍噇ist涓凡鏈夎option鏃朵笉鍋氫换浣曟搷浣�.
			$(this).appendTo($("#"+toid+":not(:has(option[value="+$(this).val()+"]))"));
			//鐩爣list涓凡缁忓瓨鍦ㄧ殑option骞舵病鏈夌Щ鍔�,浠嶆棫鍦ㄦ簮list涓�,灏嗗叾娓呯┖.
			if($("#"+fromid+" option[value="+$(this).val()+"]").length > 0) {
				$("#"+fromid).get(0)
				.removeChild($("#"+fromid+" option[value="+$(this).val()+"]").get(0));
			}
		});
	}
}


//鎸夐挳鎿嶄綔鏄惁

function enable(){
	$('a.bt_batch').linkbutton({disabled:false});
}

function disable(){
	$('a.bt_batch').linkbutton({disabled:true});
}

//璁剧疆鏄剧ず鎸夐挳鍙搷浣�
checkboxOnclick = function(){
	$("input[type='checkbox']").click(function(){ //璁剧疆鎸夐挳鍙搷浣�
		var flag = false;									   
		$("input[type='checkbox']").each(function(){ 
			if($(this).attr("checked")){
				flag = true;
			}			  
		});
		return flag?enable():disable();
	});	
}

//鏈€澶у寲銆佽繕鍘�
function fullscreen(id){
	$("#top_head_bar",parent.document.body).toggle();
	$("#mydisk_left_frame",parent.document.body).toggle();
	//$("#fullscreen").attr('icon','icon-arrow_in');
}

//鍗虫椂鎻愪氦鏁版嵁
function convertToInput(containerId, link) {
	//console.log(link);
	var text_content;
	if(is_ie){ //
		text_content = link.innerHTML;
	}else{
		text_content = link.text;
	}
	var str   = link.id.split('_');
	var size_id = str[1];
//	var fieldsAry=Array('timestart','timeend');
//	var field = containerId.split('_');
//	if(in_array(field[0],fieldsAry)){
//		if(!text_content.indexOf('-')){
//			alert('-');	
//		}else{
//			//alert(text_content);	
//		}	
//	}
	//return;
	$('#' + containerId).html("<input type='text' id='now_select' size='"+size_id+"'  value='" + text_content + "' onBlur='saveNewValue(\"" + containerId + "\", this.value,\"" + link.id + "\");' />");
	$('#now_select').focus();
}


//淇濆瓨鍗虫椂鎻愪氦澶勭悊
function saveNewValue(containerId, val,link) {
	var str   = link.split('_');
	var mo   = str[0];
	if(mo==null) return false;
	$('#' + containerId).html("<a href='javascript:void(0);'  id=\"" + link + "\" onClick='convertToInput(\"" + containerId + "\", this);' >" + val + "</a>");
	$.ajax({
		type: "POST",
		url: '?mo='+mo+'&do=ajaxEdit&n='+Math.random(),
		data:  {'id':containerId,'value':val},//$.getForms('addItem')
		//dataType:'json',
//			timeout: 1000,
//			error: function(){ alert('AJAX call timed out'); },	
		success: function (json) {
			//if (json.msg=='ok') {	
				//alert(json);
			//}
		} 
	});			
}

//蹇€熸洿鏀圭姸鎬�

function change(id,val,mo,dos){
	if(mo==null) return false;
	if(dos==null) dos = 'change';
	var str   = id.split('-');
	var key   = str[0];
	var object_id = str[1];
	var items = changeResponse(val,id);
	$.getJSON('?mo='+mo+'&do='+dos+'&&id='+object_id+'&key='+key+'&item='+items+'&n='+Math.random() );
	return;					
}

function changeResponse(result,id,val){	
	if ($('#'+id).attr('src').indexOf('ok')!=-1){
		result =val?val:2;		
		$('#'+id).attr('src',URL_ROOT+'themes/default/images/admin/icons/no.png');		
	}else{
		result =val?val:1;
		$('#'+id).attr('src',URL_ROOT+'themes/default/images/admin/icons/ok.png');
	}
	return result;
}
//replace
function check(id){
	var replaceAry ="[#_%&'\",;:=!^*$@)(?><]";
	var isalert=false;
	var val = $('#'+str)[0].value;	 
	for(i=1;i<replaceAry.length+1;i++){
		if(val.indexOf(replaceAry.substring(i-1,i))>-1){
			isalert=true;
			break;
	    }
	}
    if(isalert){
	    $('#'+str)[0].value = '';
	    $('#'+str)[0].focus();
		//alert(1);
		return false;
    }
    return true;
}
function checkRate(input) {   
	var re =  /^[1-9]+[0-9]*]*$/; //鍒ゆ柇姝ｆ暣鏁�  //鍒ゆ柇瀛楃涓叉槸鍚︿负鏁板瓧/^[0-9]+.?[0-9]*$/       
	if (!re.test(input.rate.value)) {   
		alert('鐣彿銈掑叆鍔涖仐銇︺亸銇犮仌銇�(銈便兗銈�:12)');   
		input.rate.focus();   
		return false;   
	}   
} 
//back
function goback(){
	var ref = document.referrer;	
	if(ref.indexOf('main')==-1){
		document.location.href= ref;
	}
}


function in_array(needle, haystack) {
	if(typeof needle == 'string' || typeof needle == 'number') {
		for(var i in haystack) {
			if(haystack[i] == needle) {
					return true;
			}
		}
	}
	return false;
}

function setcopy(text, alertmsg){
	if(is_ie) {
		clipboardData.setData('Text', text);
		alert(alertmsg);
	} else if(prompt('Press Ctrl+C Copy to Clipboard', text)) {
		alert(alertmsg);
	}
}

function isUndefined(variable) {
	return typeof variable == 'undefined' ? true : false;
}
function trim(str) {
	return (str + '').replace(/(\s+)$/g, '').replace(/^\s+/g, '');
}


