var whitespace = " \t\n\r";
//var firstPath="http://59.151.27.88/media";
var firstPath="http://localhost:8080/media";
var pageSize=10;//分页时的下拉列表框最大option数

function showhtml(waitmsg)
{
	document.write("<div id='sending' style='position:absolute; top:320; left:20; z-index:10; visibility:hidden'><TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=0><TR><td width=30%></td><TD class='showMessageBorderStyle'><TABLE WIDTH=100% height=70 BORDER=0 CELLSPACING=2 CELLPADDING=0><TR><td bgcolor=#eeeeee align=center>"+waitmsg+"</td></tr></table></td><td width=30%></td></tr></table></div>\n" );

	document.write("<div id='cover' style='position:absolute; top:0; left:0; z-index:9; visibility:hidden'><TABLE WIDTH=100% height=100% BORDER=0 CELLSPACING=0 CELLPADDING=0><TR><TD align=center><br></td></tr></table></div>\n" );
}

function showInfo(value){
	alert(value);
}

function insertSelectValue(select,count,current){
	obj = document.all(select);
    for(i=0;i<obj.options.length;){
        obj.remove(0);
    }
    count=Math.floor(count);
    current=Math.floor(current);
	start=1;
	size=count;
	if(count>pageSize){
		if(current > pageSize/2){
			start=current-pageSize/2;
			size=current+pageSize/2;
			if(size>count){
                size=count;
            }
		}else{
			start=1;
			size=pageSize;
		}
	}
	for(i=start;i<=size;i++){
		option = document.createElement('option');
		option.text=i;
		option.value=i;
		obj.options.add(option);
		if(i==current){
			obj.selectedIndex = option.index;
		}
	}
}

function showSending()
{
	gnIsShowSending=1;
	var sending=document.all('sending');
	if(sending==null){
		sending=window.parent.document.all('sending');
	}
	sending.style.visibility="visible";
	var cover=document.all('cover');
	if(cover==null){
		cover=window.parent.document.all('cover');
	}
	cover.style.visibility="visible";
}
function hiddenSending(){
	gnIsShowSending=0;
	document.all('sending').style.visibility="hidden";
	document.all('cover').style.visibility="hidden";
}
function hiddenParentSendding(){
	gnIsShowSending=0;
	var sending=document.all('sending');
	if(sending==null){
		sending=window.parent.document.all('sending');
	}
	sending.style.visibility="hidden";
	var cover=document.all('cover');
	if(cover==null){
		cover=window.parent.document.all('cover');
	}
	cover.style.visibility="hidden";
}

function sbmit(TxIndex,formname,Horderbyname)
{	  
   showSending();
   formname.orderbyname.value=Horderbyname;
   formname.action=TxIndex;
   formname.submit();
}
function submitToUrl(url){
	form=document.forms[0];
	form.method='post';
	form.action=url;
	form.submit();
}

//隐藏下拉框
function hiddenSelect(){
	var sel=document.getElementsByTagName("SELECT");
	for(var i=0;i<sel.length;i++){
		sel[0].style.visibility='hidden';
	}
}
//显示下拉框
function showSelect(){
	var sel=document.getElementsByTagName("SELECT");
	for(var i=0;i<sel.length;i++){
		sel[0].style.visibility='visible';
	}
}

function orderby(Impath,url,TxIndex,orderbyname,formname,otherparam)
{		
	var temp='';
	if(TxIndex==null || TxIndex=='null' || TxIndex=='')
	{
		temp='0';		
	}
	else
	{
		temp=TxIndex;
	}
	var tmporderby=temp;	
    if(tmporderby=='0')
	{
		var lstr=url+"?TxIndex=1&orderbyname=-"+orderbyname;	
		if(otherparam != null)
		{
			lstr = lstr + "&" + otherparam;
		}
		orderbyname = "-"+orderbyname;
		document.write("<a href=javascript:sbmit('"+ lstr +"',"+formname+",'"+orderbyname+"')><img src="+Impath+"/images/up.gif border=0></a>");		
	}
	else if(tmporderby=='1')
	{
		var lstr=url+"?TxIndex=0&orderbyname="+orderbyname;	
		if(otherparam != null)
		{
			lstr = lstr + "&" + otherparam;
		}
		document.write( "<a href=javascript:sbmit('"+ lstr +"',"+formname+",'"+orderbyname+"')><img src="+Impath+"/images/down.gif border=0></a>" );		
	}	

}

function stripInitialEndingWhitespace (s)
{
    var returnString = stripInitialWhitespace (s);
    returnString = stripEndingWhitespace (returnString);
    return returnString
}

function charInString (c, s)
{   for (i = 0; i < s.length; i++)
    {   if (s.charAt(i) == c) return true;
    }
    return false
}

function stripInitialWhitespace (s)
{   var i = 0;
    s +=""; // convert numbet to string
    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;

    return s.substring(i, s.length);
}

function stripEndingWhitespace (s)
{
    var i = s.length;

    while ((i > 0) && charInString (s.charAt(i-1), whitespace))
       i--;

    return s.substring(0,i);
}

function isEmpty(s)
{
    if ((s == null) || ((stripInitialEndingWhitespace(s)).length == 0))
    {
        return true
    }
    else
        return false
}

function isInteger (s)
{
    var i;
    if (isEmpty(s))
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }

    return true;
}

function isDigit (c)
{   
	return ((c >= "0") && (c <= "9"))
}

function checkform(form_prompt)
{
	var pass=confirm(form_prompt);
	if( pass )
	{
		return true;
	}
	else
	{
		return false;
	}
}
nereidFadeObjects = new Object();
nereidFadeTimers = new Object();

function nereidFade(object, destOp, rate, delta) {
	if (!document.all) {return;}
	if (object != "[object]"){
	  setTimeout("nereidFade("+object+","+destOp+","+rate+","+delta+")",0);
	  return;
	}
	clearTimeout(nereidFadeTimers[object.sourceIndex]);
	diff = destOp-object.filters.alpha.opacity;
	direction = 1;
	if (object.filters.alpha.opacity > destOp){
	  direction = -1;
	}
	delta=Math.min(direction*diff,delta);
	object.filters.alpha.opacity+=direction*delta;
	if (object.filters.alpha.opacity != destOp){
	  nereidFadeObjects[object.sourceIndex]=object;
	  nereidFadeTimers[object.sourceIndex]=setTimeout("nereidFade(nereidFadeObjects["+object.sourceIndex+"],"+destOp+","+rate+","+delta+")",rate);
	}
}
	function addoption()
	{
		var index = document.all.select1.selectedIndex;
		if(index!=-1)
		{
			var value = document.all.select1.options[index].value;
			var item = document.all.select1.options[index].text;
			
			//
			var bool = 0;
			for(var i=0;i<document.all.select2.length;i++)
			{
				if(document.all.select2.options[i].value==value)
				{
					bool = 1;
					break;
				}
			}

			//
			if(bool==0)
			{
				var oOption = document.createElement("OPTION");
				document.all.select2.options.add(oOption);
				oOption.innerText = item;
				oOption.value = value;
			}
			document.all.select1.options.remove(index);
		}
	}

	function del()
	{
		var index = document.all.select2.selectedIndex;
		
		if(index!=-1)
		{
			var value = document.all.select2.options[index].value;
			var item = document.all.select2.options[index].text;
			
			//
			var bool = 0;
			for(var i=0;i<document.all.select1.length;i++)
			{
				if(document.all.select1.options[i].value==value)
				{
					bool = 1;
					break;
				}
			}

			//
			if(bool==0)
			{
				var oOption = document.createElement("OPTION");
				document.all.select1.options.add(oOption);
				oOption.innerText = item;
				oOption.value = value;
			}
			document.all.select2.options.remove(index);
		}
	}
	
	function addall()
	{
		//
		for(var i=0;i<document.all.select1.length;i++)
		{
			//alert(i);
			var item = document.all.select1.options[i].text;
			var value = document.all.select1.options[i].value;
			var oOption = document.createElement("OPTION");
			document.all.select2.options.add(oOption);
			oOption.innerText = item;
			oOption.value = value;
			//document.all.select1.options.remove(i);
		}
		var length = document.all.select1.length;
		for(var i=0;i<length;i++)
		{
			document.all.select1.options.remove(0);
		}
	}

	function delall()
	{
		var length = document.all.select2.length;
		//
		for(var i=0;i<document.all.select2.length;i++)
		{
			var item = document.all.select2.options[i].text;
			var value = document.all.select2.options[i].value;
			var oOption = document.createElement("OPTION");
			document.all.select1.options.add(oOption);
			oOption.innerText = item;
			oOption.value = value;
			
		}
		
		for(var i=0;i<length;i++)
		{
			document.all.select2.options.remove(0);
		}
	}
	

	function radiokchose()
	{
		var chosed = 0; 
		with( document.all.tags("INPUT") )
		{
			for( i = 0; i < length; i++ )
			{
				if( item(i).checked == true && item(i).type == 'radio' )
				{
					chosed++;
				}
			}
		}
		if( chosed == 0 )
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	
	function checkboxchose()
	{
		var chosed = 0; 
		with( document.all.tags("INPUT") )
		{
			for( i = 0; i < length; i++ )
			{
				if( item(i).checked == true && item(i).type == 'checkbox' )
				{
					chosed++;
				}
			}
		}
		if( chosed == 0 )
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	

	function checkLength(obj){
		var lstrValue = obj.value;
		var iLength = obj.value.length;   
		if(lstrValue.indexOf(".")>=0){		 
			if((lstrValue.indexOf(".")+2)<(iLength-1)){				
				obj.value = lstrValue.substring(0,lstrValue.indexOf(".")+3);			 
			}
		}
	}
	
	
	function isFirstDateGreaterOrEqual(aDate1, aDate2)
	{
	    if(aDate1==null || aDate2 == null)
	    {
	        return false;
	    }
	
	    if(aDate1 >= aDate2) return true;
	    else return false;
	}

	function isFirstDateGreater(aDate1, aDate2)
	{
		
	    if(aDate1==null || aDate2 == null)
	    {
	        return false;
	    }
	
	    if(aDate1 > aDate2) return true;
	    else return false;
	}

	function validateDate(asDate, asMask)
	{
	    var liMonthPos;
	    var liDayPos;
	    var liYearPos;
	    var liMonth;
	    var liDay;
	    var liYear;
	    var lsSep;
	    var liMaxVal;
	    var liMedVal;
	    var liYearIndex;
	    // if not enough characters in date return immediately!
	    if(asDate.length < 6 ) return false;
	 
	    // get the positions of the Date components
	    liDayPos		=	asMask.indexOf("dd",0);
	    liMonthPos	=	asMask.indexOf("MM",0);
	    liYearPos		=	asMask.indexOf("yyyy",0);
	
	    liMaxVal=maxVal(liDayPos,liMonthPos,liYearPos);
	    liMedVal=medVal(liDayPos,liMonthPos,liYearPos);
	
	    lsSep = asMask.substring(liMaxVal-1,liMaxVal);
	
	    if(liYearPos ==liMaxVal)
	    {
	        liYearIndex=2;
	    }
	    else if(liYearPos==liMedVal)
	    {
	        liYearIndex = 1;
	    }
	    else
	    {
	        liYearIndex=0;
	    }
	
	    if(asDate.length < 10 )
	    {
	        asDate = padDateStr(asDate,lsSep,liYearIndex);
	        if(asDate == null) return false;
	    }
	
	    //check all separators are Ok
	    if(asDate.substring(liMaxVal-1,liMaxVal)!=lsSep) return false;
	    if(asDate.substring(liMedVal-1,liMedVal)!=lsSep) return false;
	
	    // check all are numbers
	    if(!isInteger(asDate.substring(liDayPos,liDayPos+2))) 		return false;
	    if(!isInteger(asDate.substring(liMonthPos,liMonthPos+2))) return false;
	    if(!isInteger(asDate.substring(liYearPos,liYearPos+4))) 	return false;
	
	    liDay		= parseInt(asDate.substring(liDayPos,liDayPos+2),10);
	    liMonth	= parseInt(asDate.substring(liMonthPos,liMonthPos+2),10);
	    liYear	= parseInt(asDate.substring(liYearPos,liYearPos+4),10);
	
	    // Validate all entries
	    if(!validateMonth(liMonth)) 			return false;
	    if(!validateYear(liYear)) 				return false;
	    if(!validateDay(liDay,liMonth,liYear))	return false;
	
	    return true;
}
function maxVal(aix,aiy,aiz)
{
    var val1;
    var maxVal;
    if(aix > aiy)
    {
        val1=aix;
    }
    else
    {
        val1=aiy;
    }

    if(val1 > aiz)
    {
        maxVal=val1;
    }
    else
    {
        maxVal=aiz;
    }
    return maxVal;

}

// Returns the Medium of the parameters
function medVal(aix,aiy,aiz)
{
    var medVal;
    if(aix  > aiy && aix > aiz)
    {
        if(aiy > aiz)
            medVal = aiy;
        else
            medVal = aiz;
    }

    else if(aix  > aiy && aix < aiz)
    {
            medVal = aix;
    }
    else if(aix  < aiy && aix < aiz)
    {
        if(aiy > aiz)
            medVal = aiz;
        else
            medVal = aiy;
    }
    else if(aix  < aiy && aix > aiz)
    {
            medVal = aix;
    }
    return medVal;
}
var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;
function makeArray(n) {
   for (var i = 1; i <= n; i++) {
      this[i] = 0;
   }
   return this;
}
function validateDay(aiDay,aiMonth,aiYear)
{
    if(isNaN(aiDay))	return false;
    if(aiDay > daysInMonth[aiMonth] || aiDay<1) return false;
    //if ((aiMonth == 2) && (aiDay > daysInFebruary(aiYear))) return false;
    return true;
}

function validateMonth(aiMonth)
{
    if(isNaN(aiMonth))return false;
    if(aiMonth <1 || aiMonth >12 ) return false;
    else return true;
}
function validateYear(aiYear)
{
    if(isNaN(aiYear))return false;
    if(aiYear <1970) return false;
    else return true;
}

function validateDateTime(asDateTime,asDateMask)
{
	var i = asDateTime.length;
    while ((i > 0) && (!charInString (asDateTime.charAt(i-1), whitespace)))
       i--;
	if (i==0) return false;
    var lDate=asDateTime.substring(0,i-1);
	var lTime=asDateTime.substring(i,asDateTime.length);
	if (validateDate(lDate,asDateMask) && validateTime(lTime))
		return true;
	else
		return false;
}
function validateTime(asTime)
{
    if(asTime.length != 8 ) return false;
	var liHour=asTime.substring(0,2);
	var liMinute=asTime.substring(3,5);
	var liSecond=asTime.substring(6,8);
    if(!isInteger(liHour)) 	return false;
    if(!isInteger(liMinute))   return false;
    if(!isInteger(liSecond)) 	return false;
	if (asTime.substring(2,3)!=":")
		return false;
	if (asTime.substring(5,6)!=":")
		return false;
    if (parseInt(liHour,10)>23 || parseInt(liHour,10)<0)
		return false;
    if (parseInt(liMinute,10)>59 || parseInt(liHour,10)<0)
		return false;
    if (parseInt(liSecond,10)>59 || parseInt(liHour,10)<0)
		return false;
    return true;
}
function validateDateTimeEx(asDateTime,asDateMask)
{
    var i = asDateTime.length;
    while ((i > 0) && (!charInString (asDateTime.charAt(i-1), whitespace)))
       i--;
	//alert();
	if (i==0) return false;

    var lDate=asDateTime.substring(0,i-1);
	var lTime=asDateTime.substring(i,asDateTime.length);
	if (validateDateEx(lDate,asDateMask) && validateTime(lTime))
		return true;
	else
		return false;
}
function validateDateEx(asDate, asMask)
{
    var liMonthPos;
    var liDayPos;
    var liYearPos;
    var liMonth;
    var liDay;
    var liYear;
    var lsSep;
    var liMaxVal;
    var liMedVal;
    var liYearIndex;
    // if not enough characters in date return immediately!
    if(asDate.length < 6 ) return false;
 
    // get the positions of the Date components
    liDayPos		=	asMask.indexOf("dd",0);
    liMonthPos	=	asMask.indexOf("MM",0);
    liYearPos		=	asMask.indexOf("yyyy",0);

    liMaxVal=maxVal(liDayPos,liMonthPos,liYearPos);
    liMedVal=medVal(liDayPos,liMonthPos,liYearPos);

    lsSep = asMask.substring(liMaxVal-1,liMaxVal);

    if(liYearPos ==liMaxVal)
    {
        liYearIndex=2;
    }
    else if(liYearPos==liMedVal)
    {
        liYearIndex = 1;
    }
    else
    {
        liYearIndex=0;
    }

    if(asDate.length < 10 )
    {
        asDate = padDateStr(asDate,lsSep,liYearIndex);
        if(asDate == null) return false;
    }

    //check all separators are Ok
    if(asDate.substring(liMaxVal-1,liMaxVal)!=lsSep) return false;
    if(asDate.substring(liMedVal-1,liMedVal)!=lsSep) return false;

    // check all are numbers
    if(!isInteger(asDate.substring(liDayPos,liDayPos+2))) 		return false;
    if(!isInteger(asDate.substring(liMonthPos,liMonthPos+2))) return false;
    if(!isInteger(asDate.substring(liYearPos,liYearPos+4))) 	return false;

    liDay		= parseInt(asDate.substring(liDayPos,liDayPos+2),10);
    liMonth	= parseInt(asDate.substring(liMonthPos,liMonthPos+2),10);
    liYear	= parseInt(asDate.substring(liYearPos,liYearPos+4),10);

    // Validate all entries
    if(!validateMonth(liMonth)) 			return false;
    if(!validateYear(liYear)) 				return false;
    if(!validateDay(liDay,liMonth,liYear))	return false;

    return true;
}
function validateDay(aiDay,aiMonth,aiYear)
{
    if(isNaN(aiDay))	return false;
    if(aiDay > daysInMonth[aiMonth] || aiDay<1) return false;
    //if ((aiMonth == 2) && (aiDay > daysInFebruary(aiYear))) return false;
    return true;
}

function validateMonth(aiMonth)
{
    if(isNaN(aiMonth))return false;
    if(aiMonth <1 || aiMonth >12 ) return false;
    else return true;
}
function validateYear(aiYear)
{
    if(isNaN(aiYear))return false;
    if(aiYear <1970) return false;
    else return true;
}

function openHelperWindow(helperURL,actionURL,aFeatures)
{
    var lheight = screen.availHeight/1.5;
    var lwidth = screen.availWidth/1.5;
    var newFeatures = "height=" + lheight + ",innerHeight=" + lheight;
    newFeatures += ",width=" + lwidth + ",innerWidth=" + lwidth;
    if (window.screen)
    {
      var xc = (( screen.availHeight - lheight ) / 2);
      var yc = (( screen.availWidth - lwidth ) / 3);
      newFeatures += ",left=" + xc + ",screenX=" + xc;
      newFeatures += ",top=" + yc + ",screenY=" + yc;
      newFeatures += ",resizable=yes," + aFeatures;
    }

    actionURL=actionURL.replace("?","^");
    while (actionURL.indexOf('&')>=0)
    {
      actionURL=actionURL.replace("&","^");
    }
    var lsSplit="?";
    if (helperURL.indexOf('?') >=0)
    {
      lsSplit="&";
    }

	var lwName=window.name;
	lwName=lwName+"helper";

    var newWin = open(helperURL+lsSplit+"parentUrl="+actionURL, lwName, newFeatures);
    if (newWin.opener == null) newWin.opener = window;
    newWin.opener = this;
    newWin.focus();
    return newWin;
}

function openSubWindow(url,aFeatures)
{
    var lheight = screen.availHeight/1.5;
    var lwidth = screen.availWidth/1.5;
    var newFeatures = "height=" + lheight + ",innerHeight=" + lheight;
    newFeatures += ",width=" + lwidth + ",innerWidth=" + lwidth;
    if (window.screen)
    {
      var xc = (( screen.availHeight - lheight ) / 2);
      var yc = (( screen.availWidth - lwidth ) / 3);
      newFeatures += ",left=" + xc + ",screenX=" + xc;
      newFeatures += ",top=" + yc + ",screenY=" + yc;
      newFeatures += ",resizable=yes," + aFeatures;
    }

	var lwName=window.name;
	lwName=lwName+"sub";
    var newWin = open(url, lwName, newFeatures);
    if (newWin.opener == null) newWin.opener = window;
    newWin.focus();
    return newWin;
}

function closeHelperWindow()
{
    window.document.forms[0].parentActionUrl.value=window.document.forms[0].parentActionUrl.value.replace("^","?");

    while (window.document.forms[0].parentActionUrl.value.indexOf('^')>=0)
    {
      window.document.forms[0].parentActionUrl.value=window.document.forms[0].parentActionUrl.value.replace("^","&");
    }
    var lsSplit="?";
    if (window.document.forms[0].parentActionUrl.value.indexOf('?') >=0)
    {
      lsSplit="&";
    }
    window.document.forms[0].parentActionUrl.value=window.document.forms[0].parentActionUrl.value+lsSplit+"helper_selectItems="+window.document.forms[0].returnValue.value;
    window.opener.document.forms[0].action=window.document.forms[0].parentActionUrl.value;
    window.opener.document.forms[0].submit();
    window.opener = null;
    window.close();
}

function ListOpen(url) 
{
	window.open(url,"new","resizable=yes,scrollbars=yes,width=600,height=320");
}
	