function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function resetDivSizes()
{
	var list = document.getElementById('div__body');

	if (list == null)
		return; 
	var header = document.getElementById('div__header');
	var title = document.getElementById('div__title');
	var footer = document.getElementById('div__footer');
	var left = document.getElementById('div__left');
	var right = document.getElementById('div__right');
	document.body.scroll = 'no';
	
	var nHeight = getDocumentHeight() - 10;
	nHeight -= getHeight(header) + getHeight(footer) + getHeight(title) + 4;
	list.style.height = ( nHeight > 0 ? nHeight : 0);
		
	var docwidth = getDocumentWidth();
	docwidth -= getWidth(left) + getWidth(right);
   	list.style.width = Math.max( docwidth, 0 );
}
function f_ChangeLargePicture(newPic) //改变图片路么源
	{
		if (newPic == "") return ;
		if (document.all("FlashPicture").src ==newPic) return;
		document.all("FlashPicture").src = newPic;
		
	}
function getDocumentHeight()
{
	if (window.innerHeight)
		return window.innerHeight;
	else 
		return document.body.clientHeight;
}
function ShowTable(e)
				{
				if (e.style.display=='')
				{
					e.style.display='none';
				}
				else
				{
					e.style.display='';
				}
				 
				}
function getDocumentWidth()
{
	if (window.innerWidth)
		return window.innerWidth ;
	else  
		return document.body.clientWidth;
}
function getHeight(elem)
{
	if (elem == null)
		return 0;
	else
		return elem.offsetHeight;
}
function getWidth(elem)
{
	if (elem == null)
		return 0;
	else
		return elem.offsetWidth;
}

function syshotkey(){
	switch(window.event.keyCode){
	case 13:
//		if (!window.event.srcElement.type) return
//		var tmp = window.event.srcElement.type
//		tmp = tmp.toLowerCase();
//		if (tmp!='submit'&&tmp!='button'&&tmp!='reset'&&tmp!='file'&&tmp!='textarea'){
//			window.event.keyCode=9;
//		}
		return;
		//break;
	case 18: //屏蔽ALT
		window.event.keyCode=9;
		break;
	case 112: //屏蔽F1
		window.location.reload(true);
		//alert("对不起，目前还未有帮助!");
		//window.event.keyCode=122;
	//	break;
	case 116: //屏蔽F5
		window.event.keyCode=9;
		break;
	case 122: //屏蔽F11
		window.event.keyCode=9;
		break;
	case 80: //屏蔽Ctr+P
		if (window.event.ctrlKey == true){
			if(!window.document.body.allowprint) return true;
			if(window.document.body.allowprint=='yes') return true;
			//window.event.keyCode = 9;
			alert("对不起，你没有权限打印!");
		}else{
			return;
		}
		break;
	default:
		return;
	}
	window.event.cancelBubble=true;
	window.event.returnValue=false;
}


/**********************************************************
input parameters:
	url:		the url you want to open,  from the root web directory of application  
				eg:"/BERPMain/BERPOnWeb/product/ListProduct.aspx?ProductID=20040512&ProductName=A Good Product"
	title:		the title of dialog
				eg: 
	w:			width of dialog		in pixel
	h:			height of dialog	in pixel
Returen Value:
		a customer defiend string
*********************************************************/
function openModalDialog(url,title,w,h){
	var ReturnValue;
	var width;
	var heigh;
	var mytitle;
	var myurl;
	
	if(w){
		width = w;
	}else{
		width = 350;;
	}
	
	if(h){
		heigh = h;
	}else{
		heigh = 250;
	}
	
	if(title){
		mytitle = title;
	}else{
		mytitle = "Joyer.com.cn";
	}
	
	if(url){
		myurl = url;
	}else{
		myurl = "/login.aspx";
	}
	
	
		// replace &amp; to &
	re=/\&amp;/gim;
	myurl=myurl.replace(re,"&");
	//alert(myurl);
	
	
	/*
	//replace reserved character to url required format
	re=/\?/gim;
	myurl=myurl.replace(re,"%3F");
	re=/\&/gim;
	myurl=myurl.replace(re,"%26");
	re=/\=/gim;
	myurl=myurl.replace(re,"%3D");
	*/
	//alert(myurl);
	myurl = escape(myurl);
	
	alert(myurl);
	//ReturnValue=window.showModalDialog("/MessageBox.aspx?MSG=" + mytitle,null,"dialogWidth:" + width + "px;dialogHeight:" + heigh +"px;status:yes;help:yes;resizable:yes");
	ReturnValue=window.showModalDialog("/Include/ModalFrame.aspx?url="+ myurl+"&title=" + mytitle,null,"dialogWidth:" + width + "px;dialogHeight:" + heigh +"px;status:no;help:no;resizable:no");
	return ReturnValue;
}
	
function clickIE() {var message="";if (document.all) {(message);return false;}}
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {var message="";(message);return false;}}}


function closeWin(){
window.top.close();return true;
}      

/*****************************************************************************************************************************
Author:           Jacky Huang
Name:            openPermissionKeyWindow
Created Date: 2003-04-04
Purpose:        Used to open a window to check user permission key.
[in] isModalWindow: boolean value if it's false, the window is a modalless dialog, otherwise it's a modal dialog
Modify By:     Glay
Modify date:   2003-08-19
Modify Purpose:Resolve the problem -- 
	 If system don't need to input permission key,then it won't show the checkpermissionkey window and replaced 
	 with confirm window.
Solution:Use the "CheckPermissionKeyModalFrame.aspx" and "NeedCheckPermissionKey.aspx" pages to set the fit open window.
*******************************************************************************************************************************/
//by Glay
//Set the size of the confirmWindow 
function setConfirmWindowSize(cfmWTitleJs)
	{
		window.dialogWidth="300px";
		window.dialogHeight="170px";
	}
		

function openCheckPermissionkeyModalDialog(url,title,w,h)
{
	var ReturnValue;
	var width;
	var heigh;
	var mytitle;
	var myurl;
	
	if(w){
		width = w;
	}else{
		width = 350;;
	}
	
	if(h){
		heigh = h;
	}else{
		heigh = 250;
	}
	
	if(title){
		mytitle = title;
	}else{
		mytitle = "HHERP";
	}
	
	if(url){
		myurl = url;
	}else{
		myurl = "../login.aspx";
	}
	// replace &amp; to &
	re=/\&amp;/gim;
	myurl=myurl.replace(re,"&");
	myurl = escape(myurl);
	ReturnValue=window.showModalDialog("/Include/CheckPermissionKeyModalFrame.aspx?url="+ myurl+"&title=" + mytitle,null,"dialogWidth:" + width + "px;dialogHeight:" + heigh +"px;status:no;help:no;resizable:no");
	return ReturnValue;
}

function openCheckPermissionkeyModelessDialog(url,title,w,h)
{
	var ReturnValue;
	var width;
	var heigh;
	var mytitle;
	var myurl;
	var DialogUrl;
	var re; //regular expression
	if(w){
		width = w;
	}else{
		width = 350;;
	}
	
	if(h){
		heigh = h;
	}else{
		heigh = 250;
	}
	
	if(title){
		mytitle = title;
	}else{
		mytitle = "HHERP";
	}
	
	if(url){
		myurl = url;
	}else{
		myurl = "/login.aspx";
	}
	// replace &amp; to &
	re=/\&amp;/gim;
	myurl=myurl.replace(re,"&");
	//replace reserved character to url required format
	myurl = escape(myurl);
	DialogUrl="/Include/CheckPermissionKeyModalFrame.aspx?url="+ myurl+"&title=" + mytitle;
	ReturnValue=window.showModelessDialog(DialogUrl,null,"dialogWidth:" + width + "px;dialogHeight:" + heigh +"px;status:no;help:no;resizable:no");
	return ReturnValue;
}
		
		
function openPermissionKeyWindow(isModalWindow)
{
	var rv;
	var width = 356;
	var heigh = 222;
	//by Glay
	var url = "../NeedCheckPermissionKey.aspx";
	//var url = "../CheckPermissionKey.aspx";
	
	var title = "cr.title.CheckPermissionKey";
	if(isModalWindow != "undefine"){
		if(isModalWindow==false){
			rv = openCheckPermissionkeyModelessDialog(url,title,width,heigh);
			if(rv==true){
				return true;
			}else{
				return false;
			}
		}
	}
	rv = openCheckPermissionkeyModalDialog(url,title,width,heigh);
	if(rv==true){
		return true;
	}else{
		return false;
	}
}



function openSuccessWindow(title,content){
	var rv;
	var width=310;
	var heigh=200;
	var url="/Include/SuccessWindow.aspx";
	if(content){
		url +="?content=" + escape(content);
	}
	rv = openModalDialogSucc(url,content,title,width,heigh);
 
}          
 
function openModalDialogSucc(url,content,title,w,h){
	var ReturnValue;
	var width;
	var heigh;
	var mytitle;
	var myurl;
	
	if(w){
		width = w;
	}else{
		width = 350;;
	}
	
	if(h){
		heigh = h;
	}else{
		heigh = 250;
	}
	
	if(title){
		mytitle = title;
	}else{
		mytitle = "Joyer.com.cn";
	}
	
	if(url){
		myurl = url;
	}else{
		myurl = "/login.aspx";
	}
	
	
		// replace &amp; to &
	re=/\&amp;/gim;
	myurl=myurl.replace(re,"&");
	//alert(myurl);
	
	
	/*
	//replace reserved character to url required format
	re=/\?/gim;
	myurl=myurl.replace(re,"%3F");
	re=/\&/gim;
	myurl=myurl.replace(re,"%26");
	re=/\=/gim;
	myurl=myurl.replace(re,"%3D");
	*/
	//alert(myurl);
	myurl = escape(myurl);
	
	
	ReturnValue=window.showModalDialog("/MessageBox.aspx?MSG=" + content,null,"dialogWidth:" + width + "px;dialogHeight:" + heigh +"px;status:no;help:yes;resizable:yes");
	//ReturnValue=window.showModalDialog("/Include/ModalFrame.aspx?url="+ myurl+"&title=" + mytitle,null,"dialogWidth:" + width + "px;dialogHeight:" + heigh +"px;status:no;help:no;resizable:no");
	return ReturnValue;
} 			
 
function openNormalMsgWindow(title,content){
    var rv;
	var width=320;
	var heigh=220;
	var url="/include/NormalMsgWindow.aspx";
	rv = openModalDialogNormal(url,content,width,heigh);
}   
 function openModalDialogNormal(url,title,w,h){
	var ReturnValue;
	var width;
	var heigh;
	var mytitle;
	var myurl;
	
	if(w){
		width = w;
	}else{
		width = 350;;
	}
	
	if(h){
		heigh = h;
	}else{
		heigh = 250;
	}
	
	if(title){
		mytitle = title;
	}else{
		mytitle = "Joyer.com.cn";
	}
	
	if(url){
		myurl = url;
	}else{
		myurl = "/login.aspx";
	}
	
	
		// replace &amp; to &
	re=/\&amp;/gim;
	myurl=myurl.replace(re,"&");
	//alert(myurl);
	
	
	/*
	//replace reserved character to url required format
	re=/\?/gim;
	myurl=myurl.replace(re,"%3F");
	re=/\&/gim;
	myurl=myurl.replace(re,"%26");
	re=/\=/gim;
	myurl=myurl.replace(re,"%3D");
	*/
	//alert(myurl);
	myurl = escape(myurl);
	
	//alert(myurl);
	//ReturnValue=window.showModalDialog("/MessageBox.aspx?MSG=" + mytitle,null,"dialogWidth:" + width + "px;dialogHeight:" + heigh +"px;status:yes;help:yes;resizable:yes");
	window.showModalDialog("/include/NormalMsgWindow.aspx?MSG=" + title,null,"dialogWidth:" + width + "px;dialogHeight:" + heigh +"px;status:no;help:yes;resizable:yes");
	//return ReturnValue;
}                                                                                                               
function openConfirmWindow(title,content){
	var rv;
	var width=300;
	var heigh=170;
	var url="../Include/ConfirmWindow.aspx";
	if(content){
		url +="?content=" + escape(content);
	}
	rv = openModalDialog(url,title,width,heigh);
	if(rv==true){
		return true;
	}else{
		return false;
	}
}   
 
/** 
IsNumber: 用于判断一个数字型字符串是否为数值型， 
还可判断是否是正数或负数，返回值为true或false 
string: 需要判断的字符串 
sample: 
var a = '123'; 
if (IsNumber(a)) 
{ 
alert('a is a number'); 
} 
*/ 

function IsNumber(string) 
{ 
if (isNaN(string)) 
	return false; 
else 
	return true; 
} 

/** 
IsInteger: 用于判断一个数字型字符串是否为整形， 
还可判断是否是正整数或负整数，返回值为true或false 
string: 需要判断的字符串 
sample: 
var a = '123'; 
if (IsInteger(a)) 
{ 
alert('a is a integer'); 
} 

*/ 

function IsInteger(string) 
{  
	if (isNaN(string)) 
		return false;
	else
	{
		var pos;
		var integer; 
		pos=string.indexOf(".")
		if(pos>0)
			return false;
		integer=parseInt(string);
		if (isNaN(integer)) 
			return false; 
		else 
			return true; 
	}
} 
		   
		   
/** 
IsPositiveInteger: 用于判断一个数字型字符串是否为大于0的整形， 
还可判断是否是正整数或负整数，返回值为true或false 
string: 需要判断的字符串 
sample: 
var a = '123'; 
if (IsInteger(a)) 
{ 
alert('a is a integer'); 
} 

*/ 

function IsPositiveInteger(string) 
{  
	if (isNaN(string)) 
		return false;
	else
	{
		var pos;
		var integer; 
		pos=string.indexOf(".")
		if(pos>0)
			return false;
		integer=parseInt(string);
		if (integer<0) 
			return false; 
		else 
			return true; 
	}
} 
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;
}		
				   
//TODO  will be add
/*
document.attachEvent('onkeydown',syshotkey);
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=new Function("return false")
*/
//window.attachEvent('onload',resetDivSizes);

function openwindow( url, winName, width, height) 
{
    xposition=0; yposition=0;
        if ((parseInt(navigator.appVersion) >= 4 ))
        {
            xposition = (screen.width - width) / 2;
            yposition = (screen.height - height) / 2;
        }
    theproperty= "width=" + width + "," 
    + "height=" + height + "," 
    + "location=0," 
    + "menubar=0,"
    + "resizable=1,"
    + "scrollbars=yes,"
    + "status=0," 
    + "titlebar=0,"
    + "toolbar=0,"
    + "hotkeys=0,"
    + "screenx=" + xposition + "," //仅适用于Netscape
    + "screeny=" + yposition + "," //仅适用于Netscape
    + "left=" + xposition + "," //IE
    + "top=" + yposition; //IE 
    window.open( url,winName,theproperty );
}
//弹出方法 [div]
function showMessageBox(wTitle,content,wWidth) 
{ 
	 closeWindow(); 
	 var bWidth=parseInt(document.body.scrollWidth); 
	 //var bHeight=parseInt(document.documentElement.scrollHeight); 
	 var bHeight=parseInt(document.body.scrollHeight);
	 if(isIe){ 
	 setSelectState('hidden');} 
	 var back=document.createElement("div"); 
	 back.id="back"; 
	 var styleStr="top:0px;left:0px;position:absolute;background:#666;width:"+bWidth+"px;height:"+bHeight+"px;"; 
	 styleStr+=(isIe)?"filter:alpha(opacity=0);":"opacity:0;"; 
	 back.style.cssText=styleStr; 
	 document.body.appendChild(back); 
	 showBackground(back,50); 
	 var mesW=document.createElement("div"); 
	 mesW.id="mesWindow"; 
	 mesW.className="mesWindow"; 
	 mesW.innerHTML="<div class='mesWindowTop'><table width='100%' height='100%'border='0'><tr height='25'><td style='padding-left:5px;'><strong>"+wTitle+"</strong></td><td style='width:1px;'><input type='button' onclick='closeWindow();' title='关闭窗口' class='close' value='关闭' /></td></tr></table></div><div class='mesWindowContent' id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom'></div>"; 
	
	 styleStr="left:"+400+"px;top:"+(document.body.scrollTop+200)+"px;position:absolute;width:"+wWidth+"px;"; 
	 //styleStr="left:"+(((pos.x-wWidth)>0)?(pos.x-wWidth):pos.x)+"px;top:"+(pos.y)+"px;position:absolute;width:"+wWidth+"px;"; 
	 mesW.style.cssText=styleStr; 
	 document.body.appendChild(mesW); 
} 
//关闭窗口[div] 
function closeWindow() 
{ 
	 if(document.getElementById('back')!=null) { 
	 	document.getElementById('back').parentNode.removeChild(document.getElementById('back')); 
	 } 
	 if(document.getElementById('mesWindow')!=null){ 
	 	document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow')); 
	 } 
     if(isIe){ setSelectState('');} 
} 
