//--------
// 检查当前浏览器是否为Netscape
//--------
function isNetscape(){
	app=navigator.appName.substring(0,1);
	if (app=='N') return true;
	else {return false;}
}

//--------
// 保存当前Form表单（仅适用于IE浏览器）
//--------
function formSaveCheck(fileName){
	if(isNetscape()){alert("Sorry, these function is not supported")}	
	else document.execCommand('SaveAs',null,fileName)
}

//--------
// 校验数据的合法性
//--------
function isValidReg( chars){
	var re=/<|>|\[|\]|\{|\}|『|』|※|○|●|◎|§|△|▲|☆|★|◇|◆|□|▼|㊣|﹋|⊕|⊙|〒|ㄅ|ㄆ|ㄇ|ㄈ|ㄉ|ㄊ|ㄋ|ㄌ|ㄍ|ㄎ|ㄏ|ㄐ|ㄑ|ㄒ|ㄓ|ㄔ|ㄕ|ㄖ|ㄗ|ㄘ|ㄙ|ㄚ|ㄛ|ㄜ|ㄝ|ㄞ|ㄟ|ㄢ|ㄣ|ㄤ|ㄥ|ㄦ|ㄧ|ㄨ|ㄩ|■|▄|▆|\*|@|#|\^|\\/;
	if (re.test( chars) == true) {
		return false;
	}else{
		return true;
	}	
}

//--------
// 检查数据的长度是否合法
//--------
function isValidLength(chars, len) {
	if (chars.length > len) {
		return false;
	}
	return true;
}

//--------
// 校验URL的合法性
//--------
function isValidURL( chars ) {
	//var re=/^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)((((\w+(-*\w*)+)\.)+((com)|(net)|(edu)|(gov)|(org)|(biz)|(aero)|(coop)|(info)|(name)|(pro)|(museum))(\.([a-z]{2}))?)|((\w+(-*\w*)+)\.(cn)))$/;
	var re=/^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(\S+\.\S+)$/;
	//var re=/^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(((((\w+(-*\w*)+)\.)+((com)|(net)|(edu)|(gov)|(org)|(biz)|(aero)|(coop)|(info)|(name)|(pro)|(museum)|(cn)|(tv)|(hk))(\.([a-z]{2}))?)|((\w+(-*\w*)+)\.(cn)))((\/|\?)\S*)*)$/;
	if (!isNULL(chars)) {
		chars = jsTrim(chars);
		if (chars.match(re) == null)
			return false;
		else
			return true;
	}
	return false;
}

//--------
// 校验域名的合法性
//--------
function isValidDomain( chars ) {
	var re=/^(\S+\.\S+)$/;
	if (!isNULL(chars)) {
		chars = jsTrim(chars);
		if (chars.match(re) == null)
			return false;
		else
			return true;
	}
	return false;
}

//--------
// 校验数字的合法性
//--------
function isValidDecimal( chars ) {
	var re=/^\d*\.?\d{1,2}$/;
	if (chars.match(re) == null)
		return false;
	else
		return true;
}

//--------
// 校验数字的合法性
//--------
function isNumber( chars ) {
	var re=/^\d*$/;
	if (chars.match(re) == null)
		return false;
	else
		return true;
}

//--------
// 校验邮编的合法性
//--------
function isValidPost( chars ) {
	var re=/^\d{6}$/;
	if (chars.match(re) == null)
		return false;
	else
		return true;
}

//--------
// 去掉数据的首尾空字符
//--------
function jsTrim(value){
  return value.replace(/(^\s*)|(\s*$)/g,"");
}

//--------
// 校验数据是否为空（当数据为空字符时也为NULL）
//--------
function isNULL( chars ) {
	if (chars == null)
		return true;
	if (jsTrim(chars).length==0)
		return true;
	return false;
}

//--------
// 校验Email的合法性
//--------
function checkEmail (fieldName, bMsg) 
{
    var emailStr = fieldName.value;

    var emailPat=/^(.+)@(.+)$/
    var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
    var validChars="\[^\\s" + specialChars + "\]"
    var quotedUser="(\"[^\"]*\")"
    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
    var atom=validChars + '+'
    var word="(" + atom + "|" + quotedUser + ")"
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

    var matchArray=emailStr.match(emailPat)
    if (matchArray==null) 
    {
        if (bMsg) alert("Email address seems incorrect (check @ and .'s)")
        return false
    }
    var user=matchArray[1]
    var domain=matchArray[2]

    // See if "user" is valid 
    if (user.match(userPat)==null) 
    {
        if (bMsg) alert("The Email address seems incorrect.")
        // fieldName.focus();
        return false
    }

    /* if the e-mail address is at an IP address (as opposed to a symbolic
       host name) make sure the IP address is valid. */
    var IPArray=domain.match(ipDomainPat)
    if (IPArray!=null) 
    {
        for (var i=1;i<=4;i++)
        {
            if (IPArray[i]>255)
            {
                if (bMsg) alert("Destination IP address is invalid!")
                return false
            }
        }
        return true
    }

    // Domain is symbolic name
    var domainArray=domain.match(domainPat)
    if (domainArray==null) 
    {
        if (bMsg) alert("The domain name doesn't seem to be valid.")
        return false
    }

    /* domain name seems valid, but now make sure that it ends in a
    three-letter word (like com, edu, gov) or a two-letter word,
    representing country (uk, nl), and that there's a hostname preceding 
    the domain or country. */

    var atomPat=new RegExp(atom,"g")
    var domArr=domain.match(atomPat)
    var len=domArr.length
    if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) 
    {
        // the address must end in a two letter or three letter word.
        if (bMsg) alert("The address must end in a three-letter domain, or two letter country.")
        return false
    }

    // Make sure there's a host name preceding the domain.
    if (len<2)
    {
        if (bMsg) alert("This address is missing a hostname!")
        return false
    }

    // If we've got this far, everything's valid!
    return true;
}

//--------
// 判断是否为闰年
//--------
function isLeapYear(year){
  if (year % 4 != 0)
    return false;
  if (year % 400 == 0)
    return true;
  if (year % 100 == 0)
    return false;
  return true;
}

//--------
// 校验日期的合法性
//--------
function validateDate(day,month,year)
{
    if ((day<=0)||(month<=0)||(year<=0))
        return false;
        
    if ((month>=1)&&(month<=12)) {
        if (month == 2) {
            if (isLeapYear(year)) {
                if (day<=29) 
                    return true;
            } else {
                if (day<=28)
                    return true;
                else
                    return false;
            }
        } else if ((month==4)||(month==6)||(month==9)||(month==11)) {
            if (day<=30)
                return true;
            else
                return false;
        } else {
            if (day<=31)
                return true;
            else
                return false;
        }
    }

    return false;
}

//--------
// 判断数据是否包含都是Single Byte
//--------
function isSingleByteString(str)
{
   var rc = true;
   var j = 0, i = 0;
   for (i=0; i<str.length; i++) {
     j = str.charCodeAt(i);
     if (j>=128) {
       rc = false;
       break;
     }
   }
   return rc;
}

var submitEvent = true;
function checkDoubleSubmit(){
	return submitEvent;
}

//--------
// 弹出窗口
// 参数：url-弹出窗口显示URL的内容
//       w-弹出窗口的宽度
//       h-弹出窗口的高度
//       isCenter-控制弹出窗口是否在屏幕中央显示，值为true/false
//       isResizable-控制弹出窗口是否可以改变大小，值为true/false
//       isScroll-控制弹出窗口是否有滚动条，值为true/false
//--------
function popupWindow(url,w,h,isCenter,isResizable,isScroll) {
	if (isNULL(url)) return;
	var scrLeft = 0;
	var scrTop = 0;
	var scroll = "no";
	var resize = "no";
	if (isCenter) {
		scrLeft = (screen.width-w)/2;
		scrTop = (screen.height-h)/2;
	}
	if (isResizable) resize="yes";
	if (isScroll) scroll = "yes";
	window.open(url, 'popupWindow', 'height='+h+',width='+w+',top='+scrTop+',left='+scrLeft+',toolbar=no,menubar=no,scrollbars='+scroll+',resizable='+resize+',location=no,status=no');
}

//--------
// 弹出窗口
// 参数：url-弹出窗口显示URL的内容
//       w-弹出窗口的宽度
//       h-弹出窗口的高度
//       isCenter-控制弹出窗口是否在屏幕中央显示，值为true/false
//       isResizable-控制弹出窗口是否可以改变大小，值为true/false
//       isModal-控制弹出窗口是否为模式或非模式对话框，值为ture/false
//--------
function popupModalWindow(url,w,h,isCenter,isResizable,isModal) {
	if (isNULL(url)) return;
	var scrLeft = 0;
	var scrTop = 0;
	var resize = "no";
	var cnt = "no";
	if (isCenter) {
		cnt="yes";
		scrLeft = (screen.width-w)/2;
		scrTop = (screen.height-h)/2;
	}
	if (isResizable) resize="yes";
	if (isModal)
		window.showModalDialog(url, 'popupWindow', 'dialogWidth:'+w+'px;dialogHeight:'+h+'px;dialogLeft:'+scrLeft+'px;dialogTop:'+scrTop+'px;center:'+cnt+';help:no;resizable:'+resize+';status:no');
	else
		window.showModelessDialog(url, 'popupWindow', 'dialogWidth:'+w+'px;dialogHeight:'+h+'px;dialogLeft:'+scrLeft+'px;dialogTop:'+scrTop+'px;center:'+cnt+';help:no;resizable:'+resize+';status:no');
}

//--------
// 弹出窗口
// 参数：url-弹出窗口显示URL的内容
//       w-弹出窗口的宽度
//       h-弹出窗口的高度
//       isCenter-控制弹出窗口是否在屏幕中央显示，值为true/false
//       isResizable-控制弹出窗口是否可以改变大小，值为true/false
//       isScroll-控制弹出窗口是否有滚动条，值为true/false
//--------
function openWindowCenter(urll,w,h){
  var top=(window.screen.height-h)/2;
  var left=(window.screen.width-w)/2;
  var param='toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no, status=no,top=';
  param=param+top;
  param=param+',left=';
  param=param+left;
  param=param+',height='+h;
  param=param+',width='+w;
  var w=window.open (urll,"",param)
  if(w!=null && typeof(w)!="undefined"){
		w.focus();
  }
}

//--------
//checkbox全选
//参数：field-需要操作的对象
//--------
function checkAll(field) {
	if(field!=null){
        for (i = 0; i < field.length; i++) {
        	field[i].checked = true; 
		}
	}
}

//--------
//checkbox全取消
//参数：field-需要操作的对象
//--------
function uncheckAll(field) {
	if(field!=null){
        for (i = 0; i < field.length; i++) {
        	field[i].checked = false; 
		}
	}
}

//--------
//获取ajaxPOST返回值
//参数：url-请求url
//参数：para-请求参数
//--------
function getAjaxPostData(url,para){
     var ajax = _jsc.ajax.getAjax();
     ajax.open("POST",url,false);
	 ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
     ajax.send(para);
     try{
     	var s = ajax.responseText;
     	return s;
     }catch(e){
     	return null;
     }
}

//--------
//获取ajaxGET返回值
//参数：url-请求url
//参数：para-请求参数
//--------
function getAjaxGetData(url,para){
     var ajax = _jsc.ajax.getAjax();
     ajax.open("GET",url+"?"+para,false);
     ajax.send(null);
     try{
     	var s = ajax.responseText;
     	return s;
     }catch(e){
     	return null;
     }
}

function showTemplate(event){
  var obj = document.getElementById("Layer1");
  var showTemplateSpan = document.getElementById("showTemplateSpan");
  showTemplateSpan.innerHTML=document.getElementById("hidContent").value;
  obj.style.display = 'block';
  obj.style.left=160;//document.body.scrollLeft + event.clientX+10;
  obj.style.top=document.body.scrollTop+event.y + 10;
}
function hiddenTemplate(event){
  document.getElementById('Layer1').style.display = 'none';
  document.getElementById("hidContent").value="";
}

function checkFieldLength(fieldId,fieldDesc,fieldLength ){ 
  var str = document.getElementById(fieldId).value;
  var theLen=0;
  var teststr='';
  for(i=0;i<str.length;i++){
    teststr=str.charAt(i); 
    if(str.charCodeAt(i)>255)
      theLen=theLen + 2;
    else
      theLen=theLen + 1;
  }
  if( fieldLength>=theLen ){
    return true;
  }else{
    alert(fieldDesc+" 长度超过规定长度！");
    return false;
  }
}

function popupDialog(url,width,height){
    var x = parseInt(screen.width / 2.0) - (width / 2.0); 
    var y = parseInt(screen.height / 2.0) - (height / 2.0);
    var isMSIE= (navigator.appName == "Microsoft Internet Explorer");
    if (isMSIE) {
        retval = window.showModalDialog(url, window, "dialogWidth:"+width+"px; dialogHeight:"+height+"px; dialogLeft:"+x+"px; dialogTop:"+y+"px; status:no; directories:no;scrollbars:no;Resizable=no; ");
    } else {
        var win = window.open(url, "mcePopup", "top=" + y + ",left=" + x + ",scrollbars=" + scrollbars + ",dialog=yes,modal=yes,width=" + width + ",height=" + height + ",resizable=no" );
        eval("try { win.resizeTo(width, height); } catch(e) { }");
        win.focus();
    }
}

function openWindow(url,windowName,width,height){
    var x = parseInt(screen.width / 2.0) - (width / 2.0); 
    var y = parseInt(screen.height / 2.0) - (height / 2.0);
    var isMSIE= (navigator.appName == "Microsoft Internet Explorer");
    if (isMSIE) {
    	var p = "resizable=1,location=no,scrollbars=yes,width=";
    	p = p+width;
    	p = p+",height=";
    	p = p+height;
    	p = p+",left=";
    	p = p+x;
    	p = p+",top=";
    	p = p+y;
        retval = window.open(url, windowName, p);
    } else {
        var win = window.open(url, "mcePopup", "top=" + y + ",left=" + x + ",scrollbars=" + scrollbars + ",dialog=yes,modal=yes,width=" + width + ",height=" + height + ",resizable=no" );
        eval("try { win.resizeTo(width, height); } catch(e) { }");
        win.focus();
    }
}

//--------
// 检查两个文本框中结束时间是否小于开始时间
//--------
function checkDate(){
	var d1 = document.getElementById("begintime").value;
	var d2 = document.getElementById("endtime").value;
	ss1=d1.split("-");
	ss2=d2.split("-");
	date1 = new Date(ss1[0],ss1[1],ss1[2]);
	date2 = new Date(ss2[0],ss2[1],ss2[2]);
	if (date1>date2)
	{
		alert("结束时间应该大于或等于开始时间！");
		return false;
	}
	return true;
}

function select_move(c,val)
{
    var list= $i("search_select_list");
    list.style.display=val;
}
function addSelectList()
{
    var as=document.getElementById("search_select_list").getElementsByTagName("a");
    for(var i=0;i<as.length;i++)
    {
        as[i].onclick=function(){
            var select=$i("search_select");
            select.setAttribute("val",this.getAttribute("val"));
            select.innerHTML=this.innerHTML;
            select.style.color="#000";
            select_move(null,"none");
			try{
				$i("typeinfo").setAttribute("typeid", this.getAttribute("val"));
				_jsc.state.getState("l");
			} catch(e) {}
            return false;
        }
    }
}
//计算天数差的函数
function DateDiff(sDate1, sDate2){
   var  aDate, oDate1, oDate2, iDays; 
   aDate = sDate1.split("-");
   aDate[2] = aDate[2].substr(0,1) == '0' ? aDate[2].substr(1, aDate[2].length-1) : aDate[2];
   aDate[1] = aDate[1].substr(0,1) == '0' ? aDate[1].substr(1, aDate[1].length-1) : aDate[1];
   oDate1 = new Date(aDate[0],aDate[1]-1,aDate[2]);
   aDate = sDate2.split("-");
   aDate[2] = aDate[2].substr(0,1) == '0' ? aDate[2].substr(1, aDate[2].length-1) : aDate[2];
   aDate[1] = aDate[1].substr(0,1) == '0' ? aDate[1].substr(1, aDate[1].length-1) : aDate[1];
   oDate2 = new Date(aDate[0],aDate[1]-1,aDate[2]);
   iDays = parseInt((oDate2-oDate1)/1000/60/60/24);    //把相差的毫秒数转换为天数
   return iDays;
} 

// 获得购物车个数
function get_cart_length(){
	var _cookie = _jsc.cookies.getCookie('adzonecart') ? _jsc.cookies.getCookie('adzonecart') : '';
	return _cookie == '' ? 0 : _cookie.split(';').length;
}

//  显示与隐藏
function Move_Show(moveid,showid,showevent){
        this.mid = document.getElementById(moveid);
        this.sid = document.getElementById(showid);
        this.sevent = showevent
        this.hidetimer = null;
        this.adjustwidth = 0;
        var _this = this;
        this.init = function(){
            _this.mid.onmouseover =function(){
                if(!_this.sid.style.width){
                    var newsid = _this.mid;
                    while(newsid.parentNode.tagName.toLowerCase() != "li"){
                       newsid = newsid.parentNode;
                       }
                    _this.sid.style.width = newsid.offsetWidth + _this.adjustwidth + "px";
                }
                _this.sid.style.display="block";
                if(_this.sevent)
                    _this.sevent;
                if(_this.hidetimer)
                    window.clearTimeout(_this.hidetimer);
            }
            _this.mid.onmouseout = function(){
                _this.disp_none();
            }
            
            _this.sid.onmouseover = function(){
                if(_this.hidetimer)
                    window.clearTimeout(_this.hidetimer);
            }
            _this.sid.onmouseout = function(){
                _this.disp_none();
            }
        }
        
        this.disp_none = function(){
            _this.hidetimer = window.setTimeout(function(){
                _this.sid.style.display="none";
            },300);
        }
    }