/**********************************************************************
 * Author:  zshtom                                                    *
 * Email:   0304681@126.com                                           *
 * Page:    myjs.js                                                   *
 * Action:  通用js基于jquery1.1                                       *
 *********************************************************************/
/*
 */
function check_all(obj){
	$("input." + obj).each(function(i){
		this.checked = true;
	});
}
function check_no(obj){
	$("input." + obj).each(function(i){
		this.checked = false;
	});
}
function check_fan(obj){
	$("input." + obj).each(function(i){
		this.checked = this.checked == true ? false : true;
	});
}
function check_str(obj){
	str = new String();
	$("input." + obj).each(function(i){
		str = this.checked == true ? str + this.value + "," : str;
	});
	str = str.substr("0", str.lastIndexOf(","));
	return str;
}
//---------------------------------------------------------------------------------------------------//
/*
 */

function displaynone(obj){
	$("#" + obj).hide();
}
function display(obj){
	$("#" + obj).show();
}
function displayauto(obj){
	$("#" + obj).toggle();
}
//---------------------------------------------------------------------------------------------------//
/*
 */

function getPageScrollTop(){
	var yScrolltop;
	if (self.pageYOffset) {
		yScrolltop = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScrolltop = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScrolltop = document.body.scrollTop;
	}
	return yScrolltop;
}

function getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = new Array(w,h) 
	return arrayPageSize;
}

/*
function position(obj, width, height){
	var pagesize = getPageSize();	
	var arrayPageScroll = getPageScrollTop();
	$("body").append("<div id='windowparent' style=''></div>");
	$("#windowparent").css({top: "0px", left: "0px;"});	
	$("#"+obj).wrap(document.getElementById("windowparent"));
	$("#"+obj).css({width: width+"px", height: height+"px", left: ((pagesize[0]-width)/2)+"px", top: (arrayPageScroll + ((pagesize[1]-height)/2))+"px"});
	$("#windowparent").fadeIn(1000, function(){$("#"+obj).fadeIn()});
	
}
*/
function removeobj(obj){
	$("#"+obj).fadeOut(1000, function(){$("#"+obj).remove();});
}

//---------------------------------------------------------------------------------------------------//
/*
 */

function regreturn(msg){
	alert(msg);
}

function ajaxget(url, data, func, dtype){
	if(dtype == ''){
		dtype = "html";	
	}
	$.ajax({
		type: "get",
		url: url,
		data: data,
		dataType : dtype,
		beforeSend: function(){$("#ajaxload").show();},
		success: func,
		complete: function(){$("#ajaxload").hide();},
		error: function(){$("#ajaxerror").show();}
	});
}

function ajaxpost(url, data, func, dtype){
	if(dtype == ''){
		dtype = "html";	
	}
	$.ajax({
		type: "post",
		url: url,
		data: data,
		dataType : dtype,
		beforeSend: function(){$("#ajaxload").show(); $("#ajaxerror").hide();},
		success: func,
		complete: function(){$("#ajaxload").hide();},
		error: function(){$("#ajaxerror").show();}
	});
}
//---------------------------------------------------------------------------------------------------//
/*
 */
function autovalue(idstr){
	idarr = idstr.split(",");
	idlength = idarr.length;
	var value = "";
	for(i=0; i<idlength; i++){
		value += idarr[i] + "=" + escape($("#"+idarr[i]).val()) + "&";
	}
	return value.substr("0", value.lastIndexOf("&"));
}

function tips(obj, type){
	if(type == 'open'){
		$("#"+obj).fadeIn(500);
	}else if(type == 'close'){
		$("#"+obj).fadeOut(500);
	}
}

function chagecss(obj, css){
	$("#"+obj).addClass(css);
}

function removecss(obj, css){
	$("#"+obj).removeClass(css);
}

function size(obj){
	var srcwidth = obj.width;
	var srcheight = obj.height;
	if(srcwidth>400){
		obj.style.width = 400+"px";
	}
}

function copytoboard(txt, after){
	clipboardData.setData('Text',txt);
	alert(after);
	return false;
}

function checkbrowse(){
	if($.browser.msie){
		return 'msie';
	}
	if($.browser.mozilla){
		return 'mozilla';
	}
	if($.browser.opera){
		return 'opera';
	}
	if($.browser.safari){
		return 'safari';
	}
}
function  trim(str){
    for(var  i  =  0  ;  i<str.length  &&  str.charAt(i)=="  "  ;  i++  )  ;
    for(var  j  =str.length;  j>0  &&  str.charAt(j-1)=="  "  ;  j--)  ;
    if(i>j)  return  "";  
    return  str.substring(i,j);  
} 
function addtext(obj,texts){
    var txa=document.getElementById(obj);
        txa.focus();
    if (document.selection) {
        var range = document.selection.createRange();
        range.text = texts;
    }else if(window.getSelection&&txa.selectionStart>-1){
        var st=txa.selectionStart;
        var ed=txa.selectionEnd;
        txa.value=txa.value.substring(0,st)+texts+txa.value.substring(st,ed)+txa.value.slice(ed);
        txa.setSelectionRange(st+texts.length,ed+texts.length);
    }
}

//debug
function debug(){
	document.getElementById('sqldebug').style.display='';
}

function getLength(moji){
	var i,cnt=0;
	for(i=0;i<moji.length;i++){
		if(escape(moji.charAt(i)).length>=4){
			cnt+=2;
		}else{
			cnt++;
		}
	}
	return cnt;
}
function substr(str, len){
	if(!str || !len){
		return '';
	}
	var a = 0;
	var i = 0;
	var temp = '';
	for(i=0;i<str.length;i++){
		if(str.charCodeAt(i)>255){
			a+=2;
		}else{
			a++;
		}
		if(a > len){
			return temp;
		}
		temp += str.charAt(i);
	}
	return str;
}
function getlastlength(obj, msgobj, maxGuestlength){
	if(event.keyCode==37 || event.keyCode==39){
		return false;
	}
	if(maxGuestlength - getLength($('#'+obj).val()) > 0){
		$('#'+msgobj).html(maxGuestlength - getLength($('#'+obj).val()));
	}else{
		$('#'+obj).val(substr($('#'+obj).val(),maxGuestlength));
		$('#'+msgobj).html(maxGuestlength - getLength($('#'+obj).val())+"");
	}
}

function jumphash(id){
	s = window.location.href;
	ss = s.split('#');
	if(ss[1] != undefined){
		window.location.hash = ss[1];
	}else{
		window.location.hash = id;
	}
}

function share_body(id, src, w, h){
	$('#'+id).html("<iframe frameborder='0' width='"+ w +"' height='"+ h +"' scrolling='no' style='border:0px;height:"+ h +"px;width:"+ w +"px;' src='"+ src +"'></iframe>");
}
