											/****************************************************/
											/*			公用JavaScript函数						*/
											/*			作者：吴春海（Clerkie Ng）				*/
											/*			编写日期：2004-11-23					*/
											/****************************************************/
var IEversion=parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE ")+5,navigator.userAgent.indexOf(";",navigator.userAgent.indexOf("MSIE "))));
var oPopup = window.createPopup();

//对HTML进行编码
function HtmlDecode(_txt)
{
	if(_txt	!=	null)
		return _txt.replace(/&amp;/g, '&').replace(/&quot;/g, '\"').replace(/&lt;/g, '<').replace(/&gt;/g, '>');
	else
		return "";    
}


//去除字串前后空格，如果字串并非字串类型则不做转换											
function trim(inputstring)
{
	if(typeof(inputstring)!="string")
		return inputstring;
	else
		return inputstring.replace(/(^\s*)|(\s*$)/g, "");
}

//保存Cookie
function setCookie(name, value)
{
	var today = new Date()
	var expires = new Date()
	expires.setTime(today.getTime() + 1000*60*60*24*365)
	document.cookie = name + "=" + escape(value)+ "; expires=" + expires.toGMTString()
}

//读取Cookie
function getCookie(Name)
{
	var search = Name + "="
	if(document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		if(offset != -1) {
			offset += search.length
			end = document.cookie.indexOf(";", offset)
			if(end == -1) end = document.cookie.length
			return unescape(document.cookie.substring(offset, end))
		}
		else return ""
	}
}



//将焦点跳至下一个对象
function JumpNext()
{
	if(event.keyCode == 13)
	{
		event.keyCode = 9;
	}
}

//输出状态栏信息
function StatusBar(Message)
{
	 window.status=Message;
}

//打开新的窗口，旧版本
function OpenScript(url, width, height)
{
	var Win = window.open(url,"OpenScript",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=yes,menubar=no,status=no' );
	Win.focus();
}

//打开新的窗口，旧版本
function OpenNewWin(url, width, height)
{
	var Win = window.open(url,"NewWin",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=yes,menubar=no,status=no' );
	Win.focus();
}

//打开新的窗口，最新版本，Clerkie @ 2005-7-1
function OpenWindow(_url,_name, _width, _height)
{
	if(_url	==	null)
	{
		alert('没有指定页面链接！');
		return;
	}

	if(_name	==	null)
		_name	=	(Math.round(Math.random() * 1000)).toString();
		
	if(_width	==	null)
		_width	=	640;
		
	if(_height	==	null)
		_height	=	480;
		
	var Win = window.open(_url,_name,'left=' + (screen.width-_width)/2 + ',top=' + (screen.height-_height)/2 + ',width=' + _width + ',height=' + _height + ',resizable=0,scrollbars=yes,menubar=no,status=no');
	Win.focus();
}

//允许改变窗口大小的版本
function OpenWindow2(_url,_name, _width, _height)
{
	if(_url	==	null)
	{
		alert('没有指定页面链接！');
		return;
	}

	if(_name	==	null)
		_name	=	(Math.round(Math.random() * 1000)).toString();
		
	if(_width	==	null)
		_width	=	640;
		
	if(_height	==	null)
		_height	=	480;
		
	var Win = window.open(_url,_name,'left=' + (screen.width-_width)/2 + ',top=' + (screen.height-_height)/2 + ',width=' + _width + ',height=' + _height + ',resizable=yes,scrollbars=yes,menubar=no,status=no');
	Win.focus();
}

//关闭当前窗口而不给任何提示
function CloseWindow()
{
	if(IEversion	>=	5)
		opener=null;
		
	window.close();
}

//以模式窗口的方式打开一个新的窗口
function OpenDialog(_url,_name, _width, _height)
{
	if(_url	==	null)
	{
		alert('没有指定页面链接！');
		return;
	}

	if(_name	==	null)
		_name	=	(Math.round(Math.random() * 1000)).toString();
		
	if(_width	==	null)
		_width	=	640;
		
	if(_height	==	null)
		_height	=	480;
		
	window.showModalDialog(_url,_name,"dialogTop=' + (screen.height-_height)/2 + 'px;dialogLeft=' + (screen.width-_width)/2 + 'px;dialogWidth=' + _width + 'px;dialogHeight=' + _height + 'px;center=yes");
}

//以模式窗口的方式打开一个新的窗口，并返回新窗口的返回值
function OpenModalDialog(url)
{
	return window.showModalDialog(url,"","dialogWidth=640px;dialogHeight=480px;center=yes");
}

//打开查询窗口
function OpenSearchDialog(url)
{
	return window.showModalDialog(url,"Search","dialogWidth=450px;dialogHeight=180px;center=yes;help:no;status:no;");
}

//将传入的值返回给母窗体
function CloseModalDialog(inputstring)
{
	var temp="";
	window.returnValue=inputstring;
	temp=inputstring;
	window.close();
	return temp;
}

//更改CheckBox的值，当CheckBoxName为空时，则更改页面上所有CheckBox的状态
function CheckBox(CheckBoxName,Status)
{
	if(trim(CheckBoxName)=="")
	{
		for (i=0;i<document.forms[0].elements.length;i++)
		{
		if (document.forms[0].elements(i).type=="checkbox")
			document.forms[0].elements(i).checked = Status;
		}
	}
	else
	{
		for (i=0;i<document.forms[0].elements.length;i++)
		{
		if (document.forms[0].elements(i).type=="checkbox" && document.forms[0].elements(i).id.search(CheckBoxName)>0)
			document.forms[0].elements(i).checked = Status;
		}
	}
}


//判断是否为数字（包括整形和浮点数）
function isDec(inputstring)
{
	inputstring=trim(inputstring);
	if(inputstring=="") return true;
	var i=0;
	var temp;
	var result=true;
	
	while(i<inputstring.length)
	{
		if(result==false) break;
		temp=inputstring.substring(i,i+1);
		if((temp<"0" || temp>"9") && temp!=".")
		result=false;
		i=i+1;
	}
	return result;
}


//从列表中删除除指定名称以外的客户
function RemoveByName(dropdownlist)
{
	customer=window.prompt("请输入客户名称(客户名称支持模糊查询)，如需输入多个客户名称，请在名称与名称之间使用英文豆号分隔开。","");
	
	if(customer != null)
	{
		if(customer.indexOf(",")	>	-1)
		{
			cu2	=	customer.split(",");
			
			for(i=0;i<dropdownlist.length;i++)
			{
				RemoveChild	=	true;
				
				for(j=0;j<cu2.length;j++)
				{
					if(dropdownlist.options[i].text.indexOf(cu2[j])	>	-1)
					{
						RemoveChild	=	false;
					}
				}
				
				if(RemoveChild)
				{
					dropdownlist.options.removeChild(dropdownlist.options[i]);
					i--;
				}
			}
		}
		else
		{
			for(i=0;i<dropdownlist.length;i++)
			{
				if(dropdownlist.options[i].text.indexOf(customer)	==	-1)
				{
					dropdownlist.options.removeChild(dropdownlist.options[i]);
					i--;
				}
			}
		}
	}
}


//从列表中删除除指定编号以外的客户
function RemoveByCode(dropdownlist)
{
	customer=window.prompt("请输入客户编号(客户编号支持模糊查询)，如需输入多个客户编号，请在编号与编号之间使用英文豆号分隔开。","");
	
	if(customer != null)
	{
		if(customer.indexOf(",")	>	-1)
		{
			cu2	=	customer.split(",");
			
			for(i=0;i<dropdownlist.length;i++)
			{
				RemoveChild	=	true;
				
				for(j=0;j<cu2.length;j++)
				{
					if(dropdownlist.options[i].value.indexOf(cu2[j])	>	-1)
					{
						RemoveChild	=	false;
					}
				}
				
				if(RemoveChild)
				{
					dropdownlist.options.removeChild(dropdownlist.options[i]);
					i--;
				}
			}
		}
		else
		{
			for(i=0;i<dropdownlist.length;i++)
			{
				if(dropdownlist.options[i].value.indexOf(customer)	==	-1)
				{
					dropdownlist.options.removeChild(dropdownlist.options[i]);
					i--;
				}
			}
		}
	}
}


//检查用户是否选中最少一个客户
function SelectCustomer(dropdownlist)
{
	if(dropdownlist.length	==	0)
	{
		alert("请在客户列表中选择至少一个客户！");
		return false;
	}
	
	if(dropdownlist.selectedIndex	<	0)
	{
		for(i=0;i<dropdownlist.length;i++)
		{			
			dropdownlist.options[i].selected	=	true;
		}
	}
	
	return true;
}


//检查用户是否选中最少一个客户
function RptSelectCustomer(dropdownlist)
{
	if(dropdownlist.selectedIndex	>	-1)
	{
		lblAlert.style.display	=	"block";
		return true;
	}
	else
	{
		alert("请在客户列表中选择至少一个客户！");
		return false;
	}
}


function fob(n, d) 
{ 
	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=fob(n,d.layers[i].document);
	}
	return x;
}

//重新载入当前页面
function ReloadPage()
{
	window.location.href	=	window.location.href;
}

function ShowPopup(obj)
{
	if("False" == "False")
	{
		var iX = window.event.x;
		var iY = window.event.y;
		var sMenuText = "";

		sMenuText = obj;

		var oPopupBody = oPopup.document.body;
			oPopupBody.style.padding = "4px";
			oPopupBody.style.backgroundColor = "infobackground";
			oPopupBody.style.color = "infotext";
			oPopupBody.style.borderTop = "2px solid threedshadow";
			oPopupBody.style.borderLeft = "2px solid threedshadow";
			oPopupBody.style.borderBottom = "2px solid threeddarkshadow";
			oPopupBody.style.borderRight = "2px solid threeddarkshadow";
			oPopupBody.style.fontFamily = "Tahoma";
			oPopupBody.style.fontSize = "12px";
			oPopupBody.innerHTML = sMenuText;
			oPopupBody.onclick = doClick;

		oPopup.show(iX, iY,400, 180, document.body);

	}
}

function doClick() 
{
	oPopup.hide();
}

function HtmlEncode(text)
{
    return text.replace(/&/g, '&amp').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

function HtmlDecode(text)
{
    return text.replace(/&amp;/g, '&').replace(/&quot;/g, '\"').replace(/&lt;/g, '<').replace(/&gt;/g, '>');
}

function CheckValue(_ControlList,_AlertList)
{
	try
	{
		for(var i = 0;i<_ControlList.length;i++)
		{
			if(fob(_ControlList[i]).value	==	"")
			{
				fob(_ControlList[i]).focus();
				alert(_AlertList[i]);
				return false;
			}
		}
		
		return true;
	}
	catch(e)
	{
		alert(e.description);
	}
}

function Compile(code) 
{
    var _Encode =   '';
    
    for(var i=0;i<code.length;i++)
    {
        _Encode +=  code.substr(i,1).charCodeAt()   +   new Number(String.fromCharCode(067,048,048));
    }
    
    return _Encode;
}
            
function OpenCustomerPortal(_Link)
{
    var a = window.open ("http://extranet.alcanpackaging.com.cn/PropackCP/Default.aspx" + _Link,"CustomerPortal","left=0,top=0,width=" + (screen.width - 10) + ",height=" + (screen.height - 130) + ",resizable=yes,scrollbars=yes,menubar=yes,status=yes");
	a.focus();
}

function OpenCustomerPortalSmallWin(_url,_name,_width,_height)
{
	if(_name	==	null)
		_name	=	(Math.round(Math.random() * 1000)).toString();
		
	if(_width	==	null)
		_width	=	640;
		
	if(_height	==	null)
		_height	=	480;
		
	var Win = window.open("http://extranet.alcanpackaging.com.cn/PropackCP/" + _url,_name,'left=' + (screen.width-_width)/2 + ',top=' + (screen.height-_height)/2 + ',width=' + _width + ',height=' + _height + ',resizable=0,scrollbars=yes,menubar=no,status=no');
	Win.focus();
}

function ShowEMailAddress(_Number)
{
    var _returnValue    =   "";
    
    switch(_Number)
    {
        case 1:
            _returnValue    =   "<a href='mailto:propack@propackchina.com?subject=A%20business%20message%20from%20Propackchina.com' title='click here to send mail'>propack@propackchina.com</a>";
            break;
        case 2:
            _returnValue    =   "<a href='mailto:printing@propackchina.com?subject=A%20business%20message%20from%20Propackchina.com' title='click here to send mail'>printing@propackchina.com</a>";
            break;
        case 3:
            _returnValue    =   "<a href='mailto:jypack@public1.wx.js.cn?subject=A%20business%20message%20from%20Propackchina.com' title='click here to send mail'>jypack@public1.wx.js.cn</a>";
            break;
        case 4:
            _returnValue    =   "<a href='mailto:cdpack@propackchina.com?subject=A%20business%20message%20from%20Propackchina.com' title='click here to send mail'>cdpack@propackchina.com</a>";
            break;    
        case 5:
            _returnValue    =   "<a href='mailto:yadong_yang@propackchina.com?subject=A%20business%20message%20from%20Propackchina.com' title='click here to send mail'>yadong_yang@propackchina.com</a>";
            break;
        case 6:
            _returnValue    =   "<a href='mailto:propack@propack.com.hk?subject=A%20business%20message%20from%20Propackchina.com' title='click here to send mail'>propack@propack.com.hk</a>";
            break;
        case 7:
            _returnValue    =   "<a href='mailto:yuan_zhou@propackchina.com?subject=A%20business%20message%20from%20Propackchina.com' title='click here to send mail'>yuan_zhou@propackchina.com</a>";
            break;
        case 8:
            _returnValue    =   "<a href='mailto:qingming_wang@propackchina.com?subject=A%20business%20message%20from%20Propackchina.com' title='click here to send mail'>qingming_wang@propackchina.com</a>";
            break;    
        case 9:
            _returnValue    =   "<a href='mailto:ppsh@propackchina.com?subject=A%20business%20message%20from%20Propackchina.com' title='click here to send mail'>ppsh@propackchina.com</a>";
            break;
        case 10:
            _returnValue    =   "<a href='mailto:qinghe_xu@propackchina.com?subject=A%20business%20message%20from%20Propackchina.com' title='click here to send mail'>qinghe_xu@propackchina.com</a>";
            break;
        case 11:
            _returnValue    =   "<a href='mailto:ian_wang@propackchina.com?subject=A%20business%20message%20from%20Propackchina.com' title='click here to send mail'>ian_wang@propackchina.com</a>";
            break;
        case 12:
            _returnValue    =   "<a href='mailto:simon_he@propackchina.com?subject=A%20business%20message%20from%20Propackchina.com' title='click here to send mail'>simon_he@propackchina.com</a>";
            break;
        case 13:
            _returnValue    =   "<a href='mailto:nick.hao@alcan.com?subject=A%20business%20message%20from%20alcan.com' title='click here to send mail'>nick.hao@alcan.com</a>";
            break;    
        case 14:
            _returnValue    =   "<a href='mailto:wenying.ni@alcan.com?subject=A%20business%20message%20from%20alcan.com' title='click here to send mail'>wenying.ni@alcan.com</a>";
            break;
        case 15:
            _returnValue    =   "<a href='mailto:joey_bruwer@propackchina.com?subject=A%20business%20message%20from%20Propackchina.com' title='click here to send mail'>joey_bruwer@propackchina.com</a>";
            break;
        case 16:
            _returnValue    =   "<a href='mailto:lena.li@alcan.com?subject=A%20business%20message%20from%20alcan.com' title='click here to send mail'>lena.li@alcan.com</a>";
            break;
        case 17:
            _returnValue    =   "<a href='mailto:Amy.hou@alcan.com?subject=A%20business%20message%20from%20alcan.com' title='click here to send mail'>Amy.hou@alcan.com</a>";
            break;
        case 18:
            _returnValue    =   "<a href='mailto:ck.chan@alcan.com?subject=A%20business%20message%20from%20alcan.com' title='click here to send mail'>ck.chan@alcan.com</a>";
            break;
        case 19:
            _returnValue    =   "<a href='mailto:iris.xu@alcan.com?subject=A%20business%20message%20from%20alcan.com' title='click here to send mail'>iris.xu@alcan.com</a>";
            break;
        case 20:
            _returnValue    =   "<a href='mailto:susan.sun@alcan.com?subject=A%20business%20message%20from%20alcan.com' title='click here to send mail'>susan.sun@alcan.com</a>";
            break;
        case 21:
            _returnValue    =   "<a href='mailto:ian.wang@alcan.com?subject=A%20business%20message%20from%20alcan.com' title='click here to send mail'>ian.wang@alcan.com</a>";
            break;
        case 22:
            _returnValue    =   "<a href='mailto:sandy.li@alcan.com?subject=A%20business%20message%20from%20alcan.com' title='click here to send mail'>sandy.li@alcan.com</a>";
            break;
        case 23:
            _returnValue    =   "<a href='mailto:silvia.yuan@alcan.com?subject=A%20business%20message%20from%20alcan.com' title='click here to send mail'>silvia.yuan@alcan.com</a>";
            break;
        case 24:
            _returnValue    =   "<a href='mailto:wenwei.nie@alcan.com?subject=A%20business%20message%20from%20alcan.com' title='click here to send mail'>wenwei.nie@alcan.com</a>";
            break;
        case 25:
            _returnValue    =   "<a href='mailto:jianjian.ma@alcan.com?subject=A%20business%20message%20from%20alcan.com' title='click here to send mail'>jianjian.ma@alcan.com</a>";
            break;
        case 26:
            _returnValue    =   "<a href='mailto:gangye.wu@alcan.com?subject=A%20business%20message%20from%20alcan.com' title='click here to send mail'>gangye.wu@alcan.com</a>";
            break;
        case 27:
            _returnValue    =   "<a href='mailto:roger.luo@alcan.com?subject=A%20business%20message%20from%20alcan.com' title='click here to send mail'>roger.luo@alcan.com</a>";
            break;
        case 28:
            _returnValue    =   "<a href='mailto:lisa1.li@alcan.com?subject=A%20business%20message%20from%20alcan.com' title='click here to send mail'>lisa1.li@alcan.com</a>";
            break;
            
        default:
            _returnValue    =   "<a href='mailto:webmaster@propackchina.com' title='click here to send mail'>webmaster@propackchina.com</a>";
            break;    
    }
    
    document.write(_returnValue);
}