// JavaScript Document
	/*
	Copyright (C) 2004,2007 OA86.COM. All rights reserved.
	Written by 陈祥山
	Web: http://www.oa86.com.cn,http://www.oa86.cn/
	Email: chenxsh@gmail.com
	*/

//分页函数
function Page_Search(iVer){
	if(iVer==1 || iVer==3 || iVer==6){
		var iPage=parseInt($("page").value);
		if(iPage>0){
			window.location=addParam(window.location.href,"page",iPage);
		}
	}
	if(iVer==2 || iVer==7 || iVer==10 || iVer==12){
		var sUrl=Reg(window.location.href,"_p(\\d*).htm","_p{$CurrPage}.htm");
		var iPage=parseInt($("page").value);
		if(iPage>0){
			if(sUrl.indexOf("{$CurrPage}")>0){
				window.location=sUrl.replace("{$CurrPage}",iPage)
			}else{
				window.location=sUrl.replace(".htm","_p"+iPage.toString()+".htm")
			}
		}
	}
}
function Check_keycode(iVer){
	if(event.keyCode==13){
		if(iVer==1 || iVer==3 || iVer==6){
			var iPage=parseInt($("page").value);
			if(iPage>0)
				window.location=addParam(window.location.href,"page",iPage)
		}
		if(iVer==2 || iVer==7 || iVer==10 || iVer==12){
			var sUrl=Reg(window.location.href,"_p(\\d*).htm","_p{$CurrPage}.htm");
			var iPage=parseInt($("page").value);
			if(iPage>0){
				if(sUrl.indexOf("{$CurrPage}")>0){
					window.location=sUrl.replace("{$CurrPage}",iPage)
				}else{
					window.location=sUrl.replace(".htm","_p"+iPage.toString()+".htm")
				}
			}
		}
	}
}

//验证输入
function regInput(obj, reg, inputStr)
{
    var docSel = document.selection.createRange()
    if (docSel.parentElement().tagName != "INPUT")    return false
    oSel = docSel.duplicate()
    oSel.text = ""
    var srcRange = obj.createTextRange()
    oSel.setEndPoint("StartToStart", srcRange)
    var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length)
    return reg.test(str)
}

//参数传递
function ridParam(strParam,strRid){
	strRid=strRid.toLowerCase();
	var arrParam=strParam.split("&");
	var j=arrParam.length;
	if(strParam=="")j=-1;
	var paramRid="";
	for(var i=0;i<j;i++){
		if(arrParam[i].toLowerCase().indexOf(strRid+"=")!=0){
			if(paramRid!="")paramRid+="&";
			paramRid+=arrParam[i];
		}
	}
	return paramRid;
}

function addParam(strParam,strAdd,value){
	var paramAdd="";
	strParam=strParam.toLowerCase();
	strAdd=strAdd.toLowerCase();
	if(strParam.indexOf("?")==-1)strParam="?"+strParam;
	var sUrl=strParam.substring(0,strParam.indexOf("?")+1);
	strParam=strParam.substring(strParam.indexOf("?")+1);
	var arrParam=strParam.split("&");
	for(var i=0;i<arrParam.length;i++){
		if(arrParam[i]!=""){
			if(arrParam[i].indexOf(strAdd+"=")==-1){
				paramAdd+=arrParam[i]+"&";
			}
		}
	}
	paramAdd=sUrl+paramAdd+strAdd+"="+value;
	return paramAdd;
}


function $(id) {
  if(document.all)return document.all(id);
  if(document.getElementById(id))return document.getElementById(id);
}

//正则替换
function Reg(sStr,sReg,sRe){
	var s="",sS=sStr,sR=sReg,sRe=sRe;
	if ((sS.length>0)&&(sR.length>0)) {
		eval("re=/"+sR+"/gim;");
		s=sS.replace(re,sRe);
	}
	return (s);
}

//cookie方法
function get_cookie(name) {
	cookiename = name + '=';
	cookiepos = document.cookie.indexOf(cookiename);
	if(cookiepos != -1) {
		cookiestart =cookiepos+cookiename.length;
		cookieend = document.cookie.indexOf(';', cookiestart);
		if(cookieend == -1) {
			cookieend = document.cookie.length;
		}
		return unescape(document.cookie.substring(cookiestart, cookieend));
	}
	return '';
}
function set_cookie (name, value)
{
    var rightNow = new Date();
    var expdate = new Date();
    expdate.setTime (expdate.getTime() + 5 * (24 * 60 * 60 * 1000)); //+1 day
    document.cookie = name + "=" + value +"; expires=" + expdate.toGMTString()+";path=/";
}


//全选系统
function SelectAllCheckBox(){
  document.write('<input type="checkbox" name="AllSelect" id="AllSelect" onclick="SelectAll()">')
}
function SelectAll(){
  var check = $("AllSelect").checked;
  for (i=0;i< parseInt(document.forms[0].length);i++) { 
    if (document.forms[0].elements[i].type == "checkbox" & document.forms[0].elements[i].disabled==false & document.forms[0].elements[i].name=="InfoID") { 
      document.forms[0].elements[i].checked = check;
    }
  }
}


//排序方法
function setSort(obj,intSort){
	/*
	if(isNaN(parseInt(intSort))){
		intSort=0;
	}
	*/
	var intNum=window.prompt("请输入序号(整数)：",intSort);
	if(intNum!=null){
		if(isNaN(intNum))
			alert("不是整数,无效的输入");
		else{
			obj.href+="&sortTo="+intNum;
			return true;
		}	
	}
	return false;
}


//图片自动调整的模式，1为按比例调整 ，2 按大小调整。
var resizemode=2
function imgresize(o){
 	if (resizemode==2 || o.onmousewheel){
		if(parseInt(o.width)>parseInt(o.height)){
			o.style.width='500px';	
		}else
		{
			o.style.height='500px';
		}
	}else{
		var parentNode=o.parentNode.parentNode
		if (parentNode){
			if (parentNode.tagName=='DIV'){
				if (o.offsetWidth>=parentNode.offsetWidth) o.style.width='98%';
			}else{
				var parentNode=o.parentNode.parentNode.parentNode
				if (parentNode)
				{
					if (o.offsetWidth>=parentNode.offsetWidth) o.style.width='98%';
				}
			}
		}else{
			var parentNode=o.parentNode
			if (parentNode){
				if (parentNode.tagName=='DIV') alert(parentNode.tagName);
				if (o.offsetWidth>=parentNode.offsetWidth) o.style.width='98%';
			}
		}
	}
}

//放入购物车接口
function inputcarts(productid,productpicurl){
	if(productid==undefined){
		var idlist="";
		var obj=document.getElementsByName("ProductID");
		for(var i=0;i<obj.length;i++){
			if(obj[i].checked){idlist=="" ? idlist=obj[i].value : idlist=idlist+"|"+obj[i].value}
		}
		if(idlist==""){
			alert("Please select your product!");
			return false;
		}else{
    		var arr=showModalDialog('/user/order/shoppingcart.asp?productidlist='+idlist+'&rnd='+Math.random(),'','dialogWidth:420px; dialogHeight:360px; help: no; scroll: no; status: no');
		}
	}else{
    	var arr=showModalDialog('/user/order/shoppingcart.asp?productid='+productid+'&productpicurl='+productpicurl+'&rnd='+Math.random(),'','dialogWidth:420px; dialogHeight:360px; help: no; scroll: no; status: no');
	}
}
//放入收藏夹接口
function addfavorite(infoid,moduletype){
    var arr=showModalDialog('/user/message/favorite_action.asp?moduletype='+moduletype+'&infoid='+infoid+'&rnd='+Math.random(),'','dialogWidth:420px; dialogHeight:360px; help: no; scroll: no; status: no');
}

//数据字典
function drawDic(_Data,_Name,_ShowType,_ValueType,_DefaultValue){
	
	var Selflg;
	switch(_ShowType){
		case "CHECKBOX":
			for(n in _Data){
				if(_DefaultValue.indexOf(_Data[n][_ValueType])!=-1){
					Selflg="checked";
				}else{
					Selflg="";
				}
			document.writeln("<input type='checkbox' name='"+_Name+"' value='"+_Data[n][_ValueType]+"' "+Selflg+" />");
			document.writeln(_Data[n][1]);
			}
		break;
		case "RADIO":
			for(n in _Data){
				if(_DefaultValue.indexOf(_Data[n][_ValueType])!=-1){
					Selflg="checked";
				}else{
					Selflg="";
				}
			document.writeln("<input type='radio' name='"+_Name+"' value='"+_Data[n][_ValueType]+"' "+Selflg+" />");
			document.writeln(_Data[n][1]);
			}
		break;
		case "SELECT":
			document.writeln("<select name='"+_Name+"' id='"+_Name+"'>");
			document.writeln("<option value=''></option>");
			for(n in _Data){
				if(_DefaultValue.indexOf(_Data[n][_ValueType])!=-1){
					Selflg="selected";
				}else{
					Selflg="";
				}
			document.writeln("<option value='"+_Data[n][_ValueType]+"' "+Selflg+">"+_Data[n][1]+"</option>");
			}
			document.writeln("</select>");
		break;
	}
}

function OA86marquee(id,mw,mh,mr,sr,ms,pause,dr){
	
	var obj=document.all(id);
	obj.ss=false; //stop tag
	obj.mr=mr; //marquee rows
	obj.sr=sr; //marquee display rows
	obj.mw=mw; //marquee width
	obj.mh=mh; //marquee height
	obj.ms=ms; //marquee speed
	obj.pause=pause; //pause time
	obj.pt=0; //pre top
	obj.st=0; //stop time
	obj.dr=dr; //direction

	with(obj){
		style.width=mw+"px";
		style.height=mh+"px";
		noWrap=false;
		onmouseover=stopm;
		onmouseout=startm;
		scrollTop=0+"px";
		scrollLeft=0+"px";
	}
	
	if(obj.mr!=1){
		switch(obj.dr){
			case("up"):
				obj.tt=mh*mr/sr;
				obj.ct=mh; //current top
				obj.innerHTML+=obj.innerHTML;
				setInterval(scrollUp,obj.ms); break;
			default://("left"):
				obj.tt=mw*mr/sr;
				obj.ct=mw;
				obj.innerHTML='<div style="width:'+(obj.tt*2)+'px;"><div style="float:left;">'+obj.innerHTML+'</div><div style="float:right;">'+obj.innerHTML+'</div></div>';
				document.write('<style type="text/css">#'+id+' table{width:'+mw*mr+'px;} #'+id+' td{width:'+mw+'px;}</style>');
				setInterval(scrollLeft,obj.ms); break;
		}
	}

	function scrollUp(){
		if(obj.ss==true) return;
		obj.ct+=1;
		if(obj.ct==obj.mh+1){
			obj.st+=1; obj.ct-=1;
			if(obj.st==obj.pause){obj.ct=0; obj.st=0;}
		}else {
			obj.pt=(++obj.scrollTop);
			if(obj.pt==obj.tt){obj.scrollTop=0;}
		}
	}

	function scrollLeft(){
		if(obj.ss==true) return;
		obj.ct+=1;
		if(obj.ct==obj.mw+1){
			obj.st+=1; obj.ct-=1;
			if(obj.st==obj.pause){obj.ct=0; obj.st=0;}
		}else {
			obj.pt=(++obj.scrollLeft);
			if(obj.pt==obj.tt){obj.scrollLeft=0;}
		}
	}

	function stopm(){obj.ss=true;}
	function startm(){obj.ss=false;}
}


function doclick(id,times){
	var docid=$("SelectedDocID").value;
	if(docid!=""){
		if($("rows_"+docid)){
			for(var i=0;i<$("rows_"+docid).cells.length;i++){
				$("rows_"+docid).cells[i].className="list_content";
			}
		}
	}

	$("SelectedDocID").value=id;
	obj=$("rows_"+id);
	for(var i=0;i<obj.cells.length;i++){
		obj.cells[i].className=="list_content" ? obj.cells[i].className="list_content_selected" : obj.cells[i].className="list_content"
	}
}
