﻿
//function:document write string
function $W(str)
{
    document.write(str);
}
//function:get element by its Id
function $(e) 
{ 
   return document.getElementById ? document.getElementById(e) : null;
}

//function:get elements by name
function $N(e)
{
    return document.getElementsByName(e);
}
//function:replace space by null
String.prototype.Trim = function()
{
	var regEx = /\s*/g;
	return this.replace(regEx,''); 
}

String.prototype.startsWith = function(s){
	if(this.length<s.length)
		return false;
	if(this.substr(0,s.length) == s)
		return true;
	return false;
}
String.prototype.endsWith = function(s){
	if(this.length<s.length)
		return false;
	if(this.substring(this.length-s.length)==s)
		return true;
	return false;
}

//------------------------------------------------------	
//function:replace html mark by null
String.prototype.HtmlEncodeNew = function () {
	return this
		.replace(/&/g, "&amp;")
		.replace(/^[ ]/, '&nbsp;')
		.replace(/"/g, "&quot;")
		.replace(/</g, "&lt;")
		.replace(/>/g, "&gt;");
}
String.prototype.endcodeDot = function ()
{
	return this
		.replace(/&/g, "%26")
		.replace(/\+/g, "%2b");//only this row has semicolon(;)
}
//function：only number is requested
//use this function：Then on input attribute with onkeyup="numonly(this);" and onBlur="numonly(this);"
function numonly(n){ 
n.value=n.value.replace(/\D/g,'') 
} 
//function：get value after ie address's '?'
//use this function：show.htm?id=2 get 'id' value use QueryString("id")
function QueryString(qs)
{
	s = location.href;
	var SharpIndex=s.indexOf("#");
	if (SharpIndex!=-1) {
		s=s.substring(0,SharpIndex);
	}
	s = s.replace("?","?&").split("&");
	re = "";
	for(i=1;i<s.length;i++)
	{
		if(s[i].indexOf(qs+"=")==0)
		{
			re = s[i].replace(qs+"=","");
		}
	}
	return re;
}
//Begin
//function: pop-up window 
//url:popup windows' url 
//nu_width:popup windows'width
//nu_height:popup windows'height
var newWindow = null;
function openwin(url,stoolbar)
{
	if (! newWindow || newWindow.closed)
		newWindow = window.open(url,"",stoolbar);
	else
		newWindow = window.open(url,"",stoolbar);
		newWindow.focus();
}
function openurl(url,nu_width,nu_height)
{
	var nu_left=(window.screen.width-nu_width)/2-5;
	var nu_top=(window.screen.height-nu_height)/2-40;
	openwin(url,"toolbar=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,top="+nu_top+",left="+nu_left+",width=" + nu_width + ",height=" + nu_height);
}
//End
//function to get file's suffixal name
//example: var newimgpath=imgpath.GetExtensionName();
	String.prototype.GetExtensionName = function()
	{
		var regEx = /^.*\/[^\/]*(\.[^\.\?]*).*$/;
		return this.replace(regEx,'$1');
	}

//Begin pagination 
function JudgeNumOnly(obj) 
{ 
	obj.value=obj.value.replace(/\D/g,'');
}
function JudgeGoPage(p_txtNumName, p_PageCount)
{ 
	var m_ret = true;
	var m_toPage = document.getElementById(p_txtNumName);
	if ( m_toPage.value == '' ) 
	{ 
		alert('抱歉，转到的页数不能为空，请重新输入!');
		m_toPage.focus(); 
		m_ret = false;
	} 
	else if( parseInt(m_toPage.value)<1 || parseInt(m_toPage.value)>p_PageCount ) 
	{ 
		alert('抱歉，只能输入1至'+p_PageCount+'的整数，请重新输入！');
		m_toPage.focus();
		m_ret = false;
	}
	return m_ret;
}
//End pagination 
//Begin================================================================
//function to only request number,dot n,sign (text requst money)
//example：input's attribute add onkeypress='numonly1(this)' onkeyup='numonly1(this)' onblur='numonly2(this)'
		function numonly1(k)
		{
			if(!k.value.match(/^[\+\-]?\d*?\.?\d*?$/))
				k.value=k.t_value;
			else
				k.t_value=k.value;
			if(k.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?)?$/))
				k.o_value=k.value
		} 
		function numonly2(k)
		{
			if(!k.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?|\.\d*?)?$/))
				k.value=k.o_value;
			else
			{
				if(k.value.match(/^\.\d+$/))
					k.value=0+k.value;
				if(k.value.match(/^\.$/))
					k.value=0;k.o_value=k.value;
			}
		} 
//End================================================================

//synchronous' way to get xmlHttp return value 
var xmlHttp = false;
function ReturnXmlNoAsy(url)
{
	if (!xmlHttp) {
		try{xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");} //IE
		catch (e){try {xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}catch (e2) {xmlHttp = false;}}
		if (!xmlHttp && typeof XMLHttpRequest != 'undefined'){xmlHttp = new XMLHttpRequest();}
	}
	var m_str = "";
	xmlHttp.open("GET", url, false);
	xmlHttp.onreadystatechange = function(){if (xmlHttp.readyState == 4){
	if(xmlHttp.status==200){
	m_str = xmlHttp.responseText;
	}
	}};
	xmlHttp.send(null);
	return m_str;
}	
//Create xmlHttp project
function CreateXmlHttp()
{
	try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
	catch (e) { try { xmlHttp = new XMLHttpRequest(); }
	catch (e) { xmlHttp = false; }}}
}
//Ajax Process function
function ajax_process(url,id)
{
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = ajax_sumbitemployment;
	xmlHttp.send(null);
	function ajax_sumbitemployment() 
	{
		if (xmlHttp.readyState == 1) {document.getElementById(id).innerHTML="数据读取中...";}
		if (xmlHttp.readyState == 3) {document.getElementById(id).innerHTML="数据交互中....";}
		if (xmlHttp.readyState == 4){
		    if(xmlHttp.status==200)
		    {
		        document.getElementById(id).innerHTML=xmlHttp.responseText;
		    }
		}
	}
}
//function to decode Cookie then get Cookie value
function GetCookieVal(offset)
{
	var endstr = document.cookie.indexOf (":", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
//set Cookie value
function SetCookie(name, value)
{
	var expdate = new Date();
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
	document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
	+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
	+((secure == true) ? "; secure" : "");
}
//function:delete Cookie
function DelCookie(name)
{
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetMyCookie (name);
	document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}
//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
function GetNoEscapeCookie(name) {;
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) 
	{
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} 
	else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) end = dc.length;
	return dc.substring(begin + prefix.length, end);
}

//function to decide browser type and about
function getOs() 
{ 
   var OsObject = ""; 
   if(navigator.userAgent.indexOf("MSIE")>0) { 
        return "MSIE"; 
   } 
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){ 
        return "Firefox"; 
   } 
   if(isSafari=navigator.userAgent.indexOf("Safari")>0) { 
        return "Safari"; 
   }  
   if(isCamino=navigator.userAgent.indexOf("Camino")>0){ 
        return "Camino"; 
   } 
   if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){ 
        return "Gecko"; 
   } 
   
} 
//add to browser's favorite 
function bookmarksite()
{
var title = document.title;
var url =window.location.href;
if (window.sidebar) // firefox
  window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print)
{ // opera
  var elem = document.createElement('a');
  elem.setAttribute('href',url);
  elem.setAttribute('title',title);
  elem.setAttribute('rel','sidebar');
  elem.click();
} 
else if(document.all)// ie
  window.external.AddFavorite(url, title);
}

// set Home Page
var isIE=(document.all&&document.getElementById&&!window.opera)?true:false; 
var isMozilla=(!document.all&&document.getElementById&&!window.opera)?true:false; 
var isOpera=(window.opera)?true:false;
var seturl='url(#default#homepage)';

function setmyhomepage(weburl,obj)	{
	if(isMozilla){
		try {netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");} 
		catch (e){alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'");}
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage',weburl);
	}
	if(isIE){
		obj.style.behavior=seturl;obj.sethomepage(weburl); 
	}
}

function setfavorite(weburl, webname)
{
	if(isMozilla){
		if (document.all){ window.external.addFavorite(weburl,webname);}
		else if (window.sidebar){ window.sidebar.addPanel(webname, weburl,"");}
	}
	if(isIE){window.external.AddFavorite(weburl, webname);}	
}



//function to get all selected values
function GetSetChecked()
{
    var list = document.documentElement.getElementsByTagName("input"); 
    var strid="";
    for(i=0;i<list.length;i++)
    {  
        if(list[i].type == "checkbox"&& list[i].checked)
        {
            if(strid=="")
                strid=list[i].value;
            else
                strid+="|"+list[i].value;
        }
    } 
    return strid;   
}

///function to select all checkboxs in this page
function SelChecked()
{
    var cboxAll=$("cboxAll");
    var list = document.documentElement.getElementsByTagName("input");
    for(i=0;i<list.length;i++)
    {  
        if(list[i].type == "checkbox")
        {
            list[i].checked =true;
        }
    }
}
function RemChecked()
{
    var list = document.documentElement.getElementsByTagName("input");
    for(i=0;i<list.length;i++)
    {  
        if(list[i].type == "checkbox")
        {
            list[i].checked =false;
        }
    }
}
///function to SELECT INVERT 
function RevChecked()
{
    var cboxAll=$("cboxAll");
    var list = document.documentElement.getElementsByTagName("input");
    for(i=0;i<list.length;i++)
    {  
        if(list[i].type == "checkbox")
        {
            list[i].checked =!list[i].checked;
        }
    }
}

//check sql pour in
function  IsValid(oField)
{
    oField=unescape(oField);
    re=/;|#|([\s\b+()]*select|update|insert|delete|declare|@|exec|dbcc|alter|drop|create|backup|if|else|end|and|or|add|set|open|close|use|begin|return|as|go|exists)[\s\b+]/i; 
    var e = re.test(oField);
    if(e) {
    
    location.href="../bug.aspx";//change this friendly page
    return true;
    }else
    {
        return false;
    }
 }
 
//function to check String value is not null
//and its length is more than or equal to one
function CheckLength(str)
{
    if(str!=null){
        str =str.Trim();
        if(str.length>0){
        return true;
        }}
   return false;
}
//function to show div
function DivShow(Elem)
{
	$(Elem).style.display="block";	
}
//function to hidden div
function DivHidden(Elem)
{
	$(Elem).style.display="none";
}
/*firefox  event*/ 
function __firefox(){ 
HTMLElement.prototype.__defineGetter__("runtimeStyle", __element_style); 
window.constructor.prototype.__defineGetter__("event", __window_event); 
Event.prototype.__defineGetter__("srcElement", __event_srcElement); 
} 
function __element_style(){ 
return this.style; 
} 
function __window_event(){ 
return __window_event_constructor(); 
} 
function __event_srcElement(){ 
return this.target; 
} 
function __window_event_constructor(){ 
if(document.all){ 
return window.event; 
} 
var _caller = __window_event_constructor.caller; 
while(_caller!=null){ 
var _argument = _caller.arguments[0]; 
if(_argument){ 
var _temp = _argument.constructor; 
if(_temp.toString().indexOf("Event")!=-1){ 
return _argument; 
} 
} 
_caller = _caller.caller; 
} 
return null; 
} 
if(window.addEventListener){ 
__firefox(); 
} 
/*end firefox*/ 
function GetSetCheckedNew()
{
    var list = document.documentElement.getElementsByTagName("input"); 
    var strid="";
    for(i=0;i<list.length;i++)
    {  
        if(list[i].type == "checkbox"&& list[i].checked)
        {
            if(strid=="")
                strid=list[i].value;
            else
                strid+=","+list[i].value;
        }
    } 
    return strid;   
}

function AjaxReturnValue(url)
{
    var m_str = "";
    CreateXmlHttp();
    xmlHttp.open("GET",url,false);
    xmlHttp.send(null);
    if(xmlHttp.status==200)
    {
        m_str=xmlHttp.responseText;
    }
    return m_str;
}

function LoadCity(elem,id)
{
    var xmlHttp=false;
    var ipnce=parseInt($(elem).value);
    if(ipnce>0)
    {
        var url ="/zs/address/AddAddress.ashx?option="+ipnce+"&rnd="+Math.random();
        try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }
        catch (e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
        catch (e) { try { xmlHttp = new XMLHttpRequest(); }
        catch (e) { xmlHttp = false; }}}
        xmlHttp.open("GET",url,true);
        xmlHttp.onreadystatechange=function(){
        if(xmlHttp.readyState==4){
        if(xmlHttp.status==200){
        var _options=eval(xmlHttp.responseText);
        var selcity=$(id);
        if(_options.length>0){
        selcity.options.length=0;
        for(i=0;i<_options.length;i++){
            var varitem = CreateOption(_options[i].name,_options[i].value);
            selcity.options.add(varitem);
        }}}
        }};xmlHttp.send(null);
    }
    else
    {
        $(id).options.length=0;
        $(id).options.add(CreateOption('请选择','0'));
    }
}

function CreateOption(txt,value)
{
    var _option=document.createElement("option");
    _option.value=value;
    _option.text=txt;
    return _option;
}

function BindDailHandle(){
    var elems= document.getElementsByName("dail");
    for(i=0;i<elems.length;i++){
        elems[i].onclick =function(){
            chkHandle(this,"delgcond",this.value);
        }
    }
}

function chkHandle(obj,target,text){
	var oTarget = $(target);
	var bPrefix = true;
	if(oTarget.value.endsWith("？")||oTarget.value.endsWith("。"))
		bPrefix = false;
	if(obj.checked){
		if(oTarget.value.indexOf(text) == -1){
			if(oTarget.value.Trim() == "")
				oTarget.value = text;
			else
				oTarget.value += (bPrefix? "，" : "") + text;
		}
	}
	else{
		var reg = new RegExp("^" + text + "，?|，?" + text, "ig");
		oTarget.value = oTarget.value.replace(reg,"");
	}
}
function change2(item,state)
{
  item.className = "DivClose"+state;
}
function ShowCity()
 {
   TypeShow("DivImg");
 }
 //显示层+背景
function TypeShow(Elem)
{
	$(Elem).style.display="block";	
}
//隐藏层+背景
function TypeHidden(Elem)
{
	$(Elem).style.display="none";
}
//改变省份
function setProvince(name,value)
{
   TypeHidden("DivImg");
   addCookie("User_Place",escape(name)+"|"+value);
   window.location.reload();
}
function addCookie(objName,objValue)
{
    //添加cookie
    var str = objName + "=" + objValue;
        var date = new Date();
        var ms = 24*3600*1000;
        date.setTime(date.getTime() + ms);
        str += "; expires=" + date.toGMTString();
        str += ";path=" + "/"
    document.cookie = str;
}
function Createli()
{
    var _value =unescape(GetNoEscapeCookie("product"));
    if(_value!="null"){
        var args =_value.split('&');
        if(typeof args=="object"){
            var title="";
            var url="";
            var _ul =$("oldview");
            for(var a=0;a<args.length;a++){
                title=args[a];
                url=args[a+1];
                if(CheckLength(title)){;
                    var _li =document.createElement("li");
                    var _a =document.createElement("a");
                    _a.setAttribute("target","_blank");
                    _a.setAttribute("title",title);
                    _a.setAttribute("href",url);
                    _a.innerHTML=title;
                    _li.appendChild(_a);
                    _ul.appendChild(_li);
                } 
                a=a+1;
            }
        }
    }
}
