﻿// JavaScript Document
var JS_BaseURL = "";
function OpenCenterWindow(URL,WindowName,Width,Height,scroll){
    startx = (screen.width/2) - (Width/2);
    starty = (screen.height/2) - (Height/2);
    window.open(URL,WindowName,"width=" + Width+",height=" + Height + ",top=" + starty + ",left=" + startx + ",scrollbars=" + scroll + ",statu=1");
}
function ShowPopModalDlg(url,w,h){
	showx = (screen.width - w)/2  ; // + deltaX;
	showy = (screen.height - h)/2; // + deltaY;
	SetCookieEx("PopUpURL",url);
	var features =
		'dialogWidth:'  + w  + 'px;' +
		'dialogHeight:' + h + 'px;' +
		'dialogLeft:'   + showx     + 'px;' +
		'dialogTop:'    + showy     + 'px;' +
		'directories:no; localtion:no; menubar:no; status=no; toolbar=no;scrollbars:yes;Resizeable=no';
	var retval = window.showModalDialog(JS_BaseURL + "/manage/include/dialog/index.html","_blank",features );
	return retval;
}
function OpenCenterWindow(URL,WindowName,Width,Height,scroll){
    startx = (screen.width/2) - (Width/2);
    starty = (screen.height/2) - (Height/2) - 60;
	if(starty >=60){
		starty = starty - 60;
	}else{
		starty = 0;
	}
    window.open(URL,WindowName,"width=" + Width+",height=" + Height + ",top=" + starty + ",left=" + startx + ",scrollbars=" + scroll + ",statu=1");
}
function doSelCheckBox(varsel,varto)
{
  try{
   if(confirm("确定要执行么？"))
   {
     var selobj = eval("document.all." + varsel);
     var toobj = eval("document.all." + varto);
     var objnum = selobj.length;
     if(objnum!=undefined)
     {
		var selnum = 0;
		var strsel = "";
		for(var i=0;i<objnum;i++)
		{
			var objitem = eval("document.all." + varsel + "[" + i + "]");
			if(objitem.checked)
			{
				//如果有选择项，则赋值
				if(selnum == 0)
				 strsel +=objitem.value;
				else
				 strsel += "," + objitem.value;
				selnum += 1;
			}
		}
		if(selnum == 0)
		{
		 alert("还没有选择任何一条记录");
		 return false;
		}
		else
		{
		 toobj.value = strsel;
		 return true;
		}
     }
     else
     {
	   //////////////////////////////
       if(selobj.value!=undefined)
       {
         if(selobj.checked)
         {
           toobj.value = selobj.value;
           return true;
         }
         else
         {
			alert("没有选择任何一条记录");
			return false;
         }
       }
       else
	   {
			alert("无法选择");
			return false;
	   }
	 ////////////////////////////////
     }
   }
   else
   {
     return false;
   }
  }catch(e)
  {
     alert("未能操作:" + e);
     return false;
  }
}
function showflash(url,divobj,swfwidth,swfheight){
	var tmp = "";
	tmp += "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"" + swfwidth + "\" height=\"" + swfheight + "\">\r\n";
    tmp += "<param name=\"movie\" value=\"" + url + "\">\r\n";
    tmp += "<param name=\"quality\" value=\"high\">\r\n";
	tmp += "<param name=\"wmode\" value=\"opaque\" />"
    tmp += "<embed src=\"" + url + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"" + swfwidth + "\" height=\"" + swfheight + "\"></embed>\r\n";
    tmp += "</object>\r\n";
	divobj.innerHTML = tmp;
}
function ismail(str)
{
	if(str.indexOf('@')<1) return false;
	var a;a=new Array(2);
	a=str.split('@');if(a.length!=2) return false;
	username=a[0];servername=a[1]
	if(username.length<2) return false;
	if(servername.length<6) return false;
	if(servername.indexOf('.')<1) return false;
	return true;
}
function isdate(str)
{
var	a,b
a=new Array(10)
a=str.split('-');
if(a.length!=3){
	return false;
}
b=new Array(13);b[1]=31;b[2]=28;b[3]=31;b[4]=30;b[5]=31;b[6]=30;b[7]=31;b[8]=31;b[9]=30;b[10]=31;b[11]=30;b[12]=31;y=a[0];m=a[1];d=a[2];
if(!(IsN(y,1900,2069))){
	return false;
}
if(!(IsN(m,1,12))){
	return false;
}
if((((y%4==0)&&(y%100!=0))||(y%400==0))&&(m==2)){
	if(!(IsN(d,1,29))){
		return false;
	}
}
else{
	if(!(IsN(d,1,b[m]))){
		return false;
	}
}
return true;
}
function IsN(x,l,u){
	if(x<l){
		return false;
	}
	else{
		if(x>=l){
			if(x>u){
				return false;
			}
			else{ 
				return true;
			}
		}
		else{
			return false;
		}
	}
}
function SetCookieEx(name, value) 
{
	try{
		var argv = SetCookieEx.arguments;
		var argc = SetCookieEx.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;  
		var path = "/"; //allows the tree to remain open across pages with diff names & paths

		document.cookie = name + "=" + escape (value) + 
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
		((path == null) ? "" : ("; path=" + path)) +  
		((domain == null) ? "" : ("; domain=" + domain)) +    
		((secure == true) ? "; secure" : "");
	}catch(e){
		alert(e);
	}
}

function ExpireCookieEx(name) 
{  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookieEx(name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
function GetCookieEx(name)
{  
	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)      
			return getCookieValEx(j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}
function getCookieValEx(offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
	endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}
function getSelCheckBox(varsel)
{
  try{
   if(1==1)
   {
     var selobj = eval("document.all." + varsel);
     var objnum = selobj.length;
     if(objnum!=undefined)
     {
		var selnum = 0;
		var strsel = "";
		for(var i=0;i<objnum;i++)
		{
			var objitem = eval("document.all." + varsel + "[" + i + "]");
			if(objitem.checked)
			{
				//如果有选择项，则赋值
				if(selnum == 0)
				 strsel +=objitem.value;
				else
				 strsel += "," + objitem.value;
				selnum += 1;
			}
		}
		if(selnum == 0)
		{
		 return "";
		}
		else
		{
		 return strsel;
		}
     }
     else
     {
	   //////////////////////////////
       if(selobj.value!=undefined)
       {
         if(selobj.checked)
         {
           return selobj.value;
         }
         else
         {
			 return "";
         }
       }
       else
	   {
			return "";
	   }
	 ////////////////////////////////
     }
   }
   else
   {
     return "";
   }
  }catch(e)
  {
     alert("可能没有选择足够的条件以完成操作");
     return "";
  }
}
function scalePhoto(imgId,width,height){
	var img = document.getElementById(imgId);
	if(img!= null && img!=undefined){
		var imgWidth = img.width;
		var imgHeight = img.height; 
		if(imgWidth>width&&imgHeight>height){
			//both image's width and height are larger than required one
			var widthRate = imgWidth/width;
			var heightRate = imgHeight/height;
			if(widthRate>heightRate){
				//use width to retrieve the image
				img.width=width;
				img.height=imgHeight*(width/imgWidth);
			}else{
				img.height=height;
				img.width=imgWidth*(height/imgHeight);
			}
		}else if(imgWidth>width){
				//the image width lg than the required width
				img.width=width;
				img.height=imgHeight*(width/imgWidth);
		}else if(imgHeight>height){
				//the image height lg than the required
				img.height=height;
				img.width=imgWidth*(height/imgHeight);
		}
	}
}
function scalePhoto2(img,width,height){
	if(img!= null && img!=undefined){
		alert(img.width);
		var imgWidth = img.width;
		var imgHeight = img.height; 
		if(imgWidth>width && imgHeight>height){
			//both image's width and height are larger than required one
			var widthRate = imgWidth/width;
			var heightRate = imgHeight/height;
			if(widthRate>heightRate){
				//use width to retrieve the image
				img.width=width;
				img.height=imgHeight*(width/imgWidth);
			}else{
				img.height=height;
				img.width=imgWidth*(height/imgHeight);
			}
		}else if(imgWidth>width){
				//the image width lg than the required width
				img.width=width;
				img.height=imgHeight*(width/imgWidth);
		}else if(imgHeight>height){
				//the image height lg than the required
				img.height=height;
				img.width=imgWidth*(height/imgHeight);
		}
	}
}
function jtrim(s)
{
	var i,b=0,e=s.length;
	for(i=0;i<s.length;i++) if(s.charAt(i)!=' '){b=i;break;}
	if(i==s.length) return "";
	for(i=s.length-1;i>b;i--) if(s.charAt(i)!=' '){e=i;break;}
	return s.substring(b,e+1);
}
function submitSelectList(objfrom,objTo){
	return doSelCheckBox(objfrom,objTo);
}
function InputFile(obj,strClassID){
	var returnfile = ShowPopModalDlg(JS_BaseURL + '/manage/include/upload/Default.aspx?ClassID=' + strClassID,756,596);
	if(returnfile.strip()!=''){
		obj.value = returnfile;
	}
	return false;
}
function DeleteFile(strObjName,strClassID){
  if(confirm('您确认要删除该文件么?')){
	$(strObjName).value = '';
	/*
		var fileName = $(strObjName).value;
		var tmp = ShowPopModalDlg(JS_BaseURL + '/manage/include/upload/DelFile.aspx?ClassID=' + strClassID + '&File=' + fileName,420,230);
		alert(tmp);
		if(tmp!=undefined){
			$(strObjName).value = tmp;
		}
	*/
  }
}
function ShowUploadImage(strClassID,strImg){
	ShowPopModalDlg(JS_BaseURL + '/manage/include/upload/ShowImg.aspx?ClassID=' + strClassID + "&Img=" + strImg,600,596);
}
function MenuSetup(strClassID){
	ShowPopModalDlg(JS_BaseURL + '/manage/tree/MenuSetup.aspx?ClassID=' + strClassID,620,440);
	return false;
}
function ScrollPicFlash(width,height,textHeight,pics,links,texts){
 var focus_width=width
 var focus_height=height
 var text_height=textHeight
 var swf_height = focus_height+text_height

 document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+ focus_width +'" height="'+ swf_height +'">');
 document.write('<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="http://mat1.qq.com/news/flash/playswf.swf"><param name=wmode value=transparent><param name="quality" value="high">');
 document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
 document.write('<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">');
 document.write('<embed src="http://mat1.qq.com/news/flash/playswf.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#DADADA" quality="high" width="'+ focus_width +'" height="'+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');  document.write('</object>');
}