//Open Window
function OpenWindow(Url,Width,Height,WindowObj){
	var ReturnStr=showModalDialog(Url,WindowObj,'dialogWidth:'+Width+'pt;dialogHeight:'+Height+'pt;status:no;help:no;scroll:yes;');
	return ReturnStr;
}
//Open Modal Window
function OpenWindowAndSetValue(Url,Width,Height,WindowObj,SetObj){
	var ReturnStr=showModalDialog(Url,WindowObj,'dialogWidth:'+Width+'pt;dialogHeight:'+Height+'pt;status:no;help:no;scroll:no;');
	if (ReturnStr!='007007007007') SetObj.value=ReturnStr;
	return ReturnStr;
}
//Open Editer Window
function OpenEditerWindow(Url,WindowName,Width,Height){
	window.open(Url,WindowName,'toolbar=0,location=0,maximize=1,directories=0,status=1,menubar=0,scrollbars=0,resizable=1,top=50,left=50,width='+Width+',height='+Height);
}

function ReImgSize(IMGWidth,IMGHeight){
	for (i=0;i<document.images.length;i++){ 
		if(document.images[i].id==''){
			if(document.all){
				if(document.images[i].width>IMGWidth){
					document.images[i].style.width=IMGWidth
				   	document.images[i].style.height=IMGHeight
				   	document.images[i].outerHTML='<a href="'+document.images[i].src+'" target="_blank" title="在新窗口打开图片">'+document.images[i].outerHTML+'</a>'
				}
			}else{
				if(document.images[i].width>IMGWidth){
					document.images[i].title="在新窗口打开图片"
					document.images[i].style.cursor="pointer"
					document.images[i].onclick=function(e){window.open(this.src)}
				}
			}
		}
	}
}

function IMGReSize(obj,width,height,B){ 
	var imgArray = document.getElementById(obj).getElementsByTagName("img"); 
	var imgArrayCount = imgArray.length; 
	var w = 0;
	var h = 0;
	for(var i=0;i<imgArrayCount;i++){
		if(width!=''&&height!=''){
			if(imgArray[i].width>imgArray[i].height){
				if(imgArray[i].width>width){
					w = imgArray[i].width;
					imgArray[i].style.width = width; 
					imgArray[i].style.height = imgArray[i].height * (width/w); 
				}else{
					if(imgArray[i].height>height){
						h = imgArray[i].height;
						imgArray[i].style.height = height; 
						imgArray[i].style.width = imgArray[i].width * (height/h); 
					}					
				}
			}
		}else if(width==''){
			if(imgArray[i].height>height){
				h = imgArray[i].height;
				imgArray[i].style.height = height; 
				imgArray[i].style.width = imgArray[i].width * (height/h); 
			}			
		}else if(height==''){
			if(imgArray[i].width>width){
				w = imgArray[i].width;
				imgArray[i].style.width = width;
				imgArray[i].style.height = imgArray[i].height * (width/w);
				if(B!=''){
					imgArray[i].title="在新窗口打开图片";
					imgArray[i].style.cursor="pointer";
					imgArray[i].outerHTML='<a href="'+imgArray[i].src+'" target="_blank">'+imgArray[i].outerHTML+'</a>';
				}
			}			
		}
	} 
} 

/*全游收藏夹*/
function addFav(){
	tit = parent.document.title;
	t = tit.replace(/\s/g,"@@@");
	u = window.top.location.href;
	e = document.selection?(document.selection.type!='None'?document.selection.createRange().text:''):(document.getSelection?document.getSelection():'');
	void(open('http://www.3608.com/users/favorite/favorite_box.asp?title='+escape(t)+'&amp;url='+escape(u)+'&amp;excerpt='+escape(e),'全游网收藏夹','scrollbars=no,width=500,height=300,left=80,top=80,status=no,resizable=yes'));		
}
	
/*全游意见箱*/
function addAdv(){			
	u = window.top.location.href;
	void(open('http://www.3608.com/users/siteadvice/advice_box.asp?url='+escape(u),'全游意见箱','scrollbars=no,width=500,height=320,left=80,top=80,status=no,resizable=yes'));				
}

/*/Set Cookies
function setCookie(CookieName,CookieVal,CookieDate){ 
    var expire_date = new Date();
    expire_date.setTime(expire_date.getTime()+CookieDate);
    document.cookie=""+CookieName+"="+CookieVal+";expires="+expire_date.toGMTString();
	//Cookies时间: 30天*24时*60分*60秒*1000毫秒;
}
//Get Cookies
function getCookie(CookieName){        
    var cookieString=new String(document.cookie);
    var cookieHeader=CookieName+"="
    var beginPosition=cookieString.indexOf(cookieHeader)

    if(beginPosition!=-1){
        return cookieString.substring(beginPosition + cookieHeader.length,cookieString.indexOf(";",beginPosition)) 
    }else{
    	return ""
    }
}*/
function asc2str(ascasc){
	var as=String.fromCharCode(ascasc);
	return as
}

function UrlDecode(str){
	
	/*document.write('<script language="vbscript">')
	document.write('Function asc2str(ascasc)')
	document.write('	asc2str = chr(ascasc)  ')
	document.write('End Function')
	document.write('</script>')*/
	
	var ret=""; 
	for(var i=0;i<str.length;i++){
		var chr = str.charAt(i); 
		if(chr == "+"){ 
			ret+=" "; 
		}else if(chr=="%"){ 
			var asc = str.substring(i+1,i+3); 
		 	//alert(parseInt("0x"+asc)>0x7f);
		 	if(parseInt("0x"+asc)>0x7f){ 
		  		//alert(parseInt("0x"+asc+str.substring(i+4,i+6)));
		  		ret+=asc2str(parseInt("0x"+asc+str.substring(i+4,i+6))); 
		  		i+=5; 
		 	}else{ 
		  		ret+=asc2str(parseInt("0x"+asc)); 
		  		i+=2; 
		 	} 
		}else{ 
			ret+= chr; 
		} 
	} 
	return ret; 
} 

function getCookieVal(offset){
	var endstr = document.cookie.indexOf (";", offset);
	if(endstr == -1)
		endstr = document.cookie.length;
	var kk=document.cookie.substring(offset, endstr);
	return UrlDecode(kk);
}

function getCookie(name,kname){
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;	
	
	while (i < clen){
		var j = i + alen;
		if(document.cookie.substring(i, j) == arg){
			if(kname==""){
				return getCookieVal(j);
			}else{
				var jj=getCookieVal(j);
				if(jj.indexOf(kname+"=")==-1){
					return null;
				}else{
					var l=jj.indexOf(kname+"=");
					var sl=jj.length;
					var ss=jj.substring(l,sl)
					if (ss.indexOf("&")==-1){
						return ss.substring(ss.indexOf(kname+"=")+(kname+"=").length,ss.length);
					}else{
						return ss.substring(ss.indexOf(kname+"=")+(kname+"=").length,ss.indexOf("&"));
					}
				}
				//return GetCookiekey(kname,getCookieVal (j));
			}
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function setCookie(c,k,v,e){
    var av=setCookie.arguments;
    var argc = setCookie.arguments.length;
    var ff;
    var expires = e;
    var path = null;
    var domain = ".3608.com";
    var secure = false;
    var expdate = new Date();
    var l=false;
    var r=getCookie(c);
    
    if(r!=null){l=true;}
    if(e!=null) expdate.setTime(expdate.getTime() + (expires * 365*24*60*60*1000));
    if (argc<4){
        ff=c+"="+(v) +((e == null) ? "" : ("; expires="+ expdate.toGMTString()))+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))+((secure == true) ? "; secure" : "");
    }else{
        if (l){
        ff=c+"="+k+"="+(v) +((e == null) ? "" : ("; expires="+ expdate.toGMTString()))+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))+((secure == true) ? "; secure" : "");
    }else{
        ff=c+"="+k+"="+(v) +((e == null) ? "" : ("; expires="+ expdate.toGMTString()))+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))+((secure == true) ? "; secure" : "");
    }
    }
    document.cookie=ff;
}


//头部搜索框
function InputSearch(Obj,catelog){
	var kwd = Obj.Keywords.value;
	if(kwd==''){
		alert('请填搜索内容');
		return false;
	}
	if(catelog=='sight'){
		window.open("http://so.3608.com/s?k="+kwd);
	}else if(catelog=='pic'){
		window.open("http://so.3608.com/Pic/s?k="+kwd);
	}else if(catelog=='article'){
		window.open("http://so.3608.com/Article/s?k="+kwd);
	}else if(catelog=='video'){
		window.open("http://so.3608.com/Video/s?k="+kwd);
	}else if(catelog=='map'){
		window.open("http://so.3608.com/Map/s?k="+kwd);
	}else if(catelog=='emap'){
		window.open("http://so.3608.com/Emap/s?k="+kwd);
	}else if(catelog=='weather'){
		window.open("http://so.3608.com/Weather/s?k="+escape(kwd));
	}else if(catelog=='blogs'){
		window.open("http://so.3608.com/Blog/s?k="+kwd);
	}else if(catelog=='news'){
		window.open("http://so.3608.com/News/s?k="+kwd);
	}else if(catelog=='ask'){
		window.open("http://so.3608.com/Ask/s?k="+kwd);
	}else if(catelog=='gonglue'){
		window.open("http://so.3608.com/Gonglue/s?k="+kwd);
	}else{
		alert('请选择搜索条件');
	}
	return false;
}

/*复制文本框内容*/
function CopyInBoard(Url){ 			
	window.clipboardData.setData('text',Url)
	alert('网址复制成功，您可以发给您朋友啦！');			
}

//ajax 控件也可以做成单独文件方便到其它地方调用
function Ajax1(){
	var ajaxObj = null;
	if(window.XMLHttpRequest){
		ajaxObj = new XMLHttpRequest();
	}else if(window.ActiveXObject){
		try{
			ajaxObj = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e1){
			try{
				ajaxObj=new ActiveXObject("MSXML2.XMLHTTP");
			}catch(e2){
				try{
					ajaxObj=new ActiveXObject("MSXML3.XMLHTTP");
				}catch(e3){
					alert("创建Ajax失败："+e3)
				}
			}
		}
	}else{
		alert("未能识别的浏览器");
	}
	//alert("成功");
	return ajaxObj;
}

function Ajax(){
	var ajaxObj = null;
	if(window.ActiveXObject){
		try{
			ajaxObj = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e1){
			try{
				ajaxObj = new ActiveXObject("MSXML2.XMLHTTP");
			}catch(e2){
				try{
					ajaxObj = new ActiveXObject("MSXML3.XMLHTTP");
				}catch(e3){
					alert("创建Ajax失败："+e3)
				}
			}
		}
	}else if(window.XMLHttpRequest){
		ajaxObj = new XMLHttpRequest();
	}else{
		alert("未能识别的浏览器");
	}
	return ajaxObj;
}

//获得表单对象
function $(){
	var elements = new Array();
  	for (var i=0; i<arguments.length; i++){
    	var element = arguments[i];
    	if(typeof element == 'string')
      		element = document.getElementById(element);

    	if(arguments.length == 1)
      		return element;

    	elements.push(element);
  }
  return elements;
}

//信息提示
function fullCoverDiv(mBottom,mLeft){
	document.write('<div id="coverBox" style="z-index:12000; left:0px; width:100%; position:absolute; top:0px; height:100%; text-align:left; display:none;">')
	document.write('	<div style="z-index:10; width:250px; height:150px; border:1px #0082C5 solid; background-color:#FFFFFF; position:absolute;top:expression(document.body.clientHeight-this.style.pixelHeight+document.body.scrollTop-'+mBottom+'); margin-left:'+mLeft+'px;">')
	document.write('		<div style="height:25px;background-image:url(/images/img/msg_bg.gif);">')
	document.write('			<span style="float:left; padding:7px 0px 0px 5px; color:FFFFFF; font-weight:bold;">信息提示</span>')
	document.write('			<span style="float:right;"><img src="/images/img/msg_close.gif" style="cursor:hand;" onClick="$(\'coverBox\').style.display=\'none\'"></span>')
	document.write('		</div>')
	document.write('		<div id="coverTxt" style="height:80px; padding-top:35px; color:#000000; text-align:center;"></div>')
	document.write('		<div style=" text-align:center;"><input type="button" name="button1" value=" 确 定 " onClick="$(\'coverBox\').style.display=\'none\'"></div>')
	document.write('	</div>')
	document.write('	<div style="width:250px;height:150px; background:#000;-moz-opacity:0.2; filter:alpha(opacity=20); position:absolute;top:expression(document.body.clientHeight-this.style.pixelHeight+document.body.scrollTop-'+(mBottom-5)+'); margin-left:'+(mLeft+5)+'px;"></div>')
	document.write('</div>')
}

//获取滚动条高度
function getScrollTop(){    
    var scrollPos = 0;     
    if (typeof window.pageYOffset != 'undefined') {     
       scrollPos = window.pageYOffset;     
    }     
    else if (typeof window.document.compatMode != 'undefined' &&     
       window.document.compatMode != 'BackCompat') {     
       scrollPos = window.document.documentElement.scrollTop;     
    }     
    else if (typeof window.document.body != 'undefined') {     
       scrollPos = window.document.body.scrollTop;     
    }     
    return scrollPos;    
}

//加为好友
function AddFriend(unk,uno){
		OpenWindow('http://blog.3608.com/Templets/LBS/Frame.asp?FileName=http://blog.3608.com/User_System/Friend/Friends_Box.asp&PageTitle=添加好友&FNickName=' + unk + '&FUserNo=' + uno + '',250,100,window);
	}
//站内短信
function SendMsg(unk,uno){
		OpenWindow('http://blog.3608.com/Templets/LBS/Frame.asp?FileName=http://blog.3608.com/User_System/Msg/Msg_Box.asp&PageTitle=发送站内短信&RNickName=' + unk + '&RUserNo=' + uno + '',405,250,window);
	}
//拷贝
function setCopy(_sTxt){
	try{
		clipboardData.setData('Text',_sTxt)
	}catch(e){};
	alert('已经把该网址复制到系统剪贴板\n您可以使用（Ctrl+V或鼠标右键）粘贴功能\n通过其他软件记录或发送给您的朋友');
}

//设置字号【小 中 大 特大】
function setFont(obj,size){
	document.getElementById(obj).style.fontSize=size;
}  
//打印
function doPrint(){
	window.print();
}

//gba 转码 utf-8
function gb2utf8(data){
	var glbEncode = [];
	gb2utf8_data = data;
	execScript("gb2utf8_data = MidB(gb2utf8_data, 1)", "VBScript");
	var t=escape(gb2utf8_data).replace(/%u/g,"").replace(/(.{2})(.{2})/g,"%$2%$1").replace(/%([A-Z].)%(.{2})/g,"@$1$2");
	t=t.split("@");
	var i=0,j=t.length,k;
	while(++i<j) {
		k=t.substring(0,4);
		if(!glbEncode[k]) {
			gb2utf8_char = eval("0x"+k);
			execScript("gb2utf8_char = Chr(gb2utf8_char)", "VBScript");
			glbEncode[k]=escape(gb2utf8_char).substring(1,6);
		}
		t=glbEncode[k]+t.substring(4);
	}
	gb2utf8_data = gb2utf8_char = null;
	return unescape(t.join("%"));
}

function CheckLogindata(obj){
	if(obj.MemName.value =="" ){
		alert("请输入用户名！")
		obj.MemName.focus()
		return false;
	}
	if(obj.Password.value =="" ){
		alert("请输入密码！")
		obj.Password.focus()
		return false;
	}
}

function UrlEncode(str){
   var ret="";
   var strSpecial="!\"#$%&'()*+,/:;<=>?[]^`{|}~%";
   for(var i=0;i<str.length;i++){
    var chr = str.charAt(i);
     var c=str2asc(chr);
     tt += chr+":"+c+"n";
     if(parseInt("0x"+c) > 0x7f){
       ret+="%"+c.slice(0,2)+"%"+c.slice(-2);
     }else{
       if(chr==" ")
         ret+="+";
       else if(strSpecial.indexOf(chr)!=-1)
         ret+="%"+c.toString(16);
       else
         ret+=chr;
     }
   }
   return ret;
}

//========================================
//YYYY-MM-DD日期格式检查
//========================================
function isDateString(sDate)
{
  var iaMonthDays = [31,28,31,30,31,30,31,31,30,31,30,31]
  var iaDate = new Array(3)
  var year, month, day

  if (arguments.length != 1) return false
  iaDate = sDate.toString().split("-")
  if (iaDate.length != 3) return false
  if (iaDate[1].length > 2 || iaDate[2].length > 2) return false

  year 	= parseFloat(iaDate[0])
  month = parseFloat(iaDate[1])
  day	= parseFloat(iaDate[2])

  if (year < 1900 || year > 2100) return false
  if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1]=29;
  if (month < 1 || month > 12) return false
  if (day < 1 || day > iaMonthDays[month - 1]) return false
  return true
}

//========================================
//默认选定Select值[s1:元素名,s1_value:值]
//========================================
function option_select(s1,s1_value){
	for (i=0;i<s1.length;i++){
		if (s1.options[i].value==s1_value){
			s1.selectedIndex=i;
		}			
	}
}

