﻿// JScript 文件

function sAlert(str){ 
   var msgw,msgh,bordercolor; 
   msgw=400;//Width
   msgh=100;//Height 
   titleheight=25 //title Height
   bordercolor="#DE0D00"//"#336699";//boder color
   titlecolor="#DE0D00"//"#99CCFF";//title color
   var sWidth,sHeight; 
   sWidth=document.body.offsetWidth; 
   sHeight=screen.height; 
   var bgObj=document.createElement("div"); 
   bgObj.setAttribute('id','bgDiv'); 
   bgObj.style.position="absolute"; 
   bgObj.style.top="0"; 
   bgObj.style.background="#777"; 
   bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75"; 
   bgObj.style.opacity="0.6"; 
   bgObj.style.left="0"; 
   bgObj.style.width=sWidth + "px"; 
   bgObj.style.height=sHeight + "px"; 
   bgObj.style.zIndex = "10000"; 
   document.body.appendChild(bgObj); 
   var msgObj=document.createElement("div") 
   msgObj.setAttribute("id","msgDiv"); 
   msgObj.setAttribute("align","center"); 
   msgObj.style.background="white"; 
   msgObj.style.border="1px solid " + bordercolor; 
   msgObj.style.position = "absolute"; 
   msgObj.style.left = "50%"; 
   msgObj.style.top = "50%"; 
   msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif"; 
   msgObj.style.marginLeft = "-225px" ; 
   msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px"; 
   msgObj.style.width = msgw + "px"; 
   msgObj.style.height =msgh + "px"; 
   msgObj.style.textAlign = "center"; 
   msgObj.style.lineHeight ="25px"; 
   msgObj.style.zIndex = "10001"; 
   var title=document.createElement("h4"); 
   title.setAttribute("id","msgTitle"); 
   title.setAttribute("align","right"); 
   title.style.margin="0"; 
   title.style.padding="3px"; 
   title.style.background=bordercolor; 
   title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);"; 
   title.style.opacity="0.75"; 
   title.style.border="1px solid " + bordercolor; 
   title.style.height="18px"; 
   title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif"; 
   title.style.color="white"; 
   title.style.cursor="pointer"; 
   title.innerHTML="Close"; 
   title.onclick=function(){ 
          document.body.removeChild(bgObj); 
          document.getElementById("msgDiv").removeChild(title); 
          document.body.removeChild(msgObj); 
        } 
   document.body.appendChild(msgObj); 
   document.getElementById("msgDiv").appendChild(title); 
   var txt=document.createElement("p"); 
   txt.style.margin="1em 0" 
   txt.setAttribute("id","msgTxt"); 
   txt.innerHTML=str; 
   document.getElementById("msgDiv").appendChild(txt); 
} 

function sConfirm(str){ 
   var msgw,msgh,bordercolor; 
   msgw=400;//Width
   msgh=100;//Height 
   titleheight=25 //title Height
   bordercolor="#DE0D00"//"#336699";//boder color
   titlecolor="#DE0D00"//"#99CCFF";//title color
   var sWidth,sHeight; 
   sWidth=document.body.offsetWidth; 
   sHeight=screen.height; 
   var bgObj=document.createElement("div"); 
   bgObj.setAttribute('id','bgDiv'); 
   bgObj.style.position="absolute"; 
   bgObj.style.top="0"; 
   bgObj.style.background="#777"; 
   bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75"; 
   bgObj.style.opacity="0.6"; 
   bgObj.style.left="0"; 
   bgObj.style.width=sWidth + "px"; 
   bgObj.style.height=sHeight + "px"; 
   bgObj.style.zIndex = "10000"; 
   document.body.appendChild(bgObj); 
   var msgObj=document.createElement("div") 
   msgObj.setAttribute("id","msgDiv"); 
   msgObj.setAttribute("align","center"); 
   msgObj.style.background="white"; 
   msgObj.style.border="1px solid " + bordercolor; 
   msgObj.style.position = "absolute"; 
   msgObj.style.left = "50%"; 
   msgObj.style.top = "50%"; 
   msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif"; 
   msgObj.style.marginLeft = "-225px" ; 
   msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px"; 
   msgObj.style.width = msgw + "px"; 
   msgObj.style.height =msgh + "px"; 
   msgObj.style.textAlign = "center"; 
   msgObj.style.lineHeight ="25px"; 
   msgObj.style.zIndex = "10001"; 
   var title=document.createElement("h4"); 
   title.setAttribute("id","msgTitle"); 
   title.setAttribute("align","right"); 
   title.style.margin="0"; 
   title.style.padding="3px"; 
   title.style.background=bordercolor; 
   title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);"; 
   title.style.opacity="0.75"; 
   title.style.border="1px solid " + bordercolor; 
   title.style.height="18px"; 
   title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif"; 
   title.style.color="white"; 
   title.style.cursor="pointer"; 
   title.innerHTML="Close"; 
   title.onclick=function(){ 
          document.body.removeChild(bgObj); 
          document.getElementById("msgDiv").removeChild(title); 
          document.body.removeChild(msgObj); 
        } 
   document.body.appendChild(msgObj); 
   document.getElementById("msgDiv").appendChild(title); 
   var txt=document.createElement("span"); 
   txt.style.margin="1em 0";
   txt.setAttribute("id","msgTxt"); 
   
   
   txt.innerHTML="<br/>"+"<input style=\"border-style:Groove;\" type=\"button\" value=\"确定\" onclick=\"sConfirm('d');\" />&nbsp;"+"<input style=\"border-style:Groove;\" type=\"button\" value=\"删除\" onclick=\"sConfirm('d');\" />"+str; 
   document.getElementById("msgDiv").appendChild(txt); 
}





 String.prototype.trim = function() {
        var reExg = /^\s+(.*?)\s+$/;
        return this.replace(reExg,"$1");
    };
    
//字符串验证
    function validateStr(str,type)
    {
        var rtn = false;
        var patrn;
        switch(type)
        {
            case 1:
                patrn = /^[a-zA-Z0-9 | \u4e00-\u9fa5]([\w- | \u4e00-\u9fa5]){0,}[a-zA-Z0-9 | \u4e00-\u9fa5]$/;break; //用户名
            case 2:
                patrn = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;break;     //Email
            case 3:
                patrn = /^[\d|-]{7,19}$/;break;                                    //电话号码格式
            case 4:
                patrn = /^((20\d{2})|(19\d{2}))-((0[1-9])|(1[0-2]))-((0[1-9])|([1-2][0-9])|(3([0|1])))$/;break;  //日期
            case 5:
                patrn = /^0?(130|131|132|133|134|135|136|137|138|139|150|151|152|153|154|155|156|157|158|159)(\d){8}$/g; break;//new   RegExp("13[0-9]{1,1}[0-9]{8,8}","g");break;     //手机号 13 或 15带头跟着9位数字
            case 6:
                patrn = /^([a-zA-Z0-9]){2,14}$/;break;                             //域名
            case 7:
                patrn = /^((\d{17}[\d|X])|\d{15})$/; break;                        //身份证号
            case 8:
                patrn = /^[0-9]{6}$/; break;  
            default:
                break;
        }
        
        if(!patrn.test(str))
        {
            rtn = true;
        }
        return rtn;
    }
    
    //读取cookie
    function readCookie(name)
    {
	    var cookieValue = "";
	    var search = name + "=";
	    if(document.cookie.length > 0)
	    {
		    offset = document.cookie.indexOf(search);
		    if (offset != -1)
		    {
			    offset += search.length;
			    end = document.cookie.indexOf(";", offset);
			    if (end == -1) end = document.cookie.length;
			    cookieValue = unescape(document.cookie.substring(offset, end))
		    }
	    }
	    return cookieValue;
    }
    
    function initPop(message)
	{
	    $("div_ms").innerHTML=message;
	    gotoCenter("div_pop");
	    $("div_pop").style.display="";
	}
	function gotoCenter(id)
    {
        var myWidth = 0, myHeight = 0;
        if (typeof (window.innerWidth) == "number") {
                myWidth = window.innerWidth;
                myHeight = window.innerHeight;
            } else {
                if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
                    myWidth = document.documentElement.clientWidth;
                    myHeight = document.documentElement.clientHeight;
                } else {
                    if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
                        myWidth = document.body.clientWidth;
                        myHeight = document.body.clientHeight;
                    }
                }
            }
        	
       
	    var obj = document.getElementById(id);
        obj.style.position = "absolute";
        var left =(parseInt(myWidth/2) - parseInt(obj.style.width)/2) +"px";
        var top =(myHeight - obj.style.height)  /2+document.documentElement.scrollTop+"px";

        obj.style.top=top;
        obj.style.left=left;
        obj.style.display="";
    }
    function initPopConfirm(message)
    {
        var div = document.createElement("div")
        div.id="div_pop_confirm";
        div.className='sccg';
        div.style.display="";
        div.style.width=300+"px";
        document.body.appendChild(div);
        var rs=false;
        div.innerHTML="<div class=\"ccj\">"+
                    "<div class=\"cja\">"+
                        "<img alt=\"\" src=\"http://images.carsfun.com/index/zc1.gif\" /></div>"+
                    "<div class=\"cjb\">"+
                        "<img alt=\"\" src=\"http://images.carsfun.com/index/zc3.gif\" /></div>"+
                    "<div class=\"myzt\" id=\"div_pop_confirm_title\">车趣网提示</div>"+
                    "<span class=\"more\">"+
                        "<img alt=\"\" onclick=\"document.body.removeChild($('div_pop_confirm'));\" src=\"http://images.carsfun.com/index/xx.jpg\" /></span>"+
                "</div>"+
                "<div class=\"jianj\" >"+
                    "<div class=\"juz\" id=\"div_pop_message\">"+message+
                        "</div>"+
                "</div>"+
                "<div class=\"mye\">"+
                    "<div class=\"juz\" id=\"div_swap2\">"+
                        "<input class=\"kang\" onclick=\"clearGoods();document.body.removeChild($('div_pop_confirm'));\" type=\"button\" value=\"确定\" /><input class=\"kang\" onclick=\"document.body.removeChild($('div_pop_confirm'));\" type=\"button\" value=\"取消\" />"+
                    "</div>"+
                "</div>"+
                "<div class=\"sccx\">"+
                    "<div class=\"cjaa\">"+
                        "<img src=\"http://images.carsfun.com/index/dl.gif\" width=\"7\" height=\"7\" /></div>"+
                    "<div class=\"cjbb\">"+
                        "<img src=\"http://images.carsfun.com/index/rl.gif\" width=\"7\" height=\"7\" /></div>"+
                "</div>"+
                "<div class=\"mytc1\">"+
                    "<img src=\"http://images.carsfun.com/index/tc.gif\" /></div>";
       gotoCenter("div_pop_confirm");
       return rs;
    }
    