// open URL in a new Window
function openURL(URL,w,h)
{window.open(URL, 'newwindow', 'width='+w+',height='+h+',directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes') }
function showMe(URL,w,h)
{showModalDialog(URL,'','dialogWidth:'+w+'; dialogHeight:'+h+'; help:no;center:yes;status:no;resizable:no')}

function ConfirmAction(msg)
{if (confirm(msg))
	return true;
 else
 	return false;
	}

// Client-Side Validation for Userforms 
function Object_hasValue(obj, obj_type)
    {
	    if (obj_type == "TEXT" || obj_type == "PASSWORD")
	{
    	if (obj.value.length == 0) 
      		return false;
    	else 
      		return true;
   	}
    else if (obj_type == "SELECT")
	{
		for (i=1; i < obj.length; i++)
	    	{
			if (obj.options[i].selected)
			return true;
		}
	      	return false;	

	}
    else if (obj_type == "SINGLE_VALUE_RADIO" || obj_type == "SINGLE_VALUE_CHECKBOX")
	{
		if (obj.checked)
			return true;
		else
       		return false;	

	}
    else if (obj_type == "RADIO" || obj_type == "CHECKBOX")
	{
        for (i=0; i < obj.length; i++)
	    	{
		if (obj[i].checked)
			return true;
		}
	       	return false;	
	}
	}
// Check time format
function checkTimeFormat(object_value)
    {
    //Returns true if value is a time format or is NULL
    //otherwise returns false	
    if (object_value.length == 0)
        return true;
	isplit1 = object_value.indexOf(':');
	if (isplit1 == -1 || isplit1 == object_value.length)
		return false;
	sHour = object_value.substring(0, isplit1);
	if (sHour.length == 0)
        return false;
	isplit2 = object_value.indexOf(':', isplit1 + 1);
	if ((isplit2 + 1 ) == object_value.length)
		return false;
	if (isplit2 == -1)
		{
		sMinute = object_value.substring(isplit1 + 1);
		sSecond = '00';
		}
	else
		{
		sMinute = object_value.substring((sHour.length + 1), isplit2);
		sSecond = object_value.substring(isplit2 + 1);
		}
	if (sMinute.length == 0 || sSecond.length==0)
       return false;	
/*	
	isplit = object_value.indexOf(':');
	if (isplit == -1 || isplit == object_value.length)
		return false;
	sHour = object_value.substring(0, isplit);
	if (sHour.length == 0)
        return false;
	sMinute = object_value.substring(isplit + 1);*/
	if (!checkIntegerFormat(sHour)) //check hour
		return false;
	else
	if (!checkNumberRange(sHour, 0,23)) //check hour
		return false;
	else
	if (!checkIntegerFormat(sMinute)) //check minute
		return false;
	else
	if (!checkNumberRange(sMinute, 0,59)) //check minute
		return false;
	else
	if (!checkIntegerFormat(sSecond))
		return false;
	else
	if (!checkNumberRange(sSecond,0,59))
		return false;
	else
		return true;
    }

function checkDateFormat(object_value)
    {
    //Returns true if value is a date format or is NULL
    //otherwise returns false	
    if (object_value.length == 0)
        return true;
    //Returns true if value is a date in the dd-mm-yyyy format
	isplit = object_value.indexOf('/');
	if (isplit == -1 || isplit == object_value.length)
		return false;
		sDay = object_value.substring(0, isplit);
	if (sDay.length == 0)
        return false;
		
	isplit = object_value.indexOf('/', isplit + 1);
	if (isplit == -1 || (isplit + 1 ) == object_value.length)
		return false;
		
    sMonth = object_value.substring((sDay.length + 1), isplit);
	if (sMonth.length == 0)
        return false;
		
	sYear = object_value.substring(isplit + 1);
	if (!checkIntegerFormat(sMonth)) //check month
		return false;
		
	else
	if (!checkNumberRange(sMonth, 1, 12)) //check month
		return false;
		
	else
	if (!checkIntegerFormat(sYear)) //check year
		return false;
		
	else
	if (!checkNumberRange(sYear, 1900, 3000)) //check year
		return false;
		
	else
	if (!checkIntegerFormat(sDay)) //check day
		return false;
		
	else
	if (!checkday(sYear, sMonth, sDay)) // check day
		return false;
		
	else
		return true;
    }
function checkday(checkYear, checkMonth, checkDay)
    {
	maxDay = 31;
	if (checkMonth == 4 || checkMonth == 6 ||
			checkMonth == 9 || checkMonth == 11)
		maxDay = 30;
	else
	if (checkMonth == 2)
	{
		if (checkYear % 4 > 0)
			maxDay =28;
		else
		if (checkYear % 100 == 0 && checkYear % 400 > 0)
			maxDay = 28;
		else
			maxDay = 29;
	}
	return checkNumberRange(checkDay, 1, maxDay); //check day
    }
function checkIntegerFormat(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false	
   if (object_value.length == 0)
        return true;

    //Returns true if value is an integer defined as
    //   having an optional leading + or -.
    //   otherwise containing only the characters 0-9.
	var decimal_format = ".";
	var check_char;

   //The first character can be + -  blank or a digit.
	check_char = object_value.indexOf(decimal_format)
    //Was it a decimal?
    if (check_char < 1)
	return CheckNumber(object_value);
    else
	return false;
    }


function NumberRange(object_value, min_value, max_value)
    {
    // check minimum
    if (min_value != null)
	{
        if (object_value < min_value)
		return false;
	}
    // check maximum
    if (max_value != null)
	{
	if (object_value > max_value)
		return false;
	}
    //All tests passed, so...
    return true;
    }

function CheckInput(input,format)
{
var check_char
for (var i=0;i<input.length;i++)
{
check_char=format.indexOf(input.charAt(i))
if (check_char > -1)
{alert("输入字符中包含如下非法字符： "+input.charAt(i));
return false
}
}
return true;}

function CheckNumber(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false	
    if (object_value.length == 0)
        return true;
   //Returns true if value is a number defined as
    //   having an optional leading + or -.
    //   having at most 1 decimal point.
    //   otherwise containing only the characters 0-9.
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;
    //The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(object_value.charAt(0))
    //Was it a decimal?
	if (check_char == 1)
	    decimal = true;
	else if (check_char < 1)
		return false;

	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < object_value.length; i++)
	{
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1)
		{
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0)
		{
			if (decimal || digits)	
				trailing_blank = true;
        // ignore leading blanks
		}
	        else if (trailing_blank)
			return false;
		else
			digits = true;
	}	
    //All tests passed, so...
    return true
    }


function checkNumberRange(object_value, min_value, max_value)
    {
    //if value is in range then return true else return false
    if (object_value.length == 0)
        return true;
    if (!CheckNumber(object_value))
	{
	return false;
	}
    else
	{
	return (NumberRange((eval(object_value)), min_value, max_value));
	}

    //All tests passed, so...
    return true;
    }
	
function getRadioValue(obj)
{

if (obj.length>=2)
	for (i=0; i < obj.length; i++)
	 	{
		if (obj[i].checked)
			return obj[i].value;
		}
else
	return obj.value;
}


 // Convert dd-mm-yyyy hh:mi:ss into date object
 function gendate(sDate,sTime)
 {
 	var sYear,sMonth,sDay,sHour,sMinute,isplit,isplit1,isplit2;
	//Get Day
	isplit=sDate.indexOf("/");
	sDay=sDate.substring(0,isplit);
	//Get Month
	isplit=sDate.indexOf("/",isplit+1);
	sMonth=sDate.substring(sDay.length+1,isplit);
	//Get Year
	sYear=sDate.substring(isplit+1);

	isplit1 = sTime.indexOf(":");
	sHour = sTime.substring(0, isplit1);
	isplit2 = sTime.indexOf(':', isplit1 + 1);
	if (isplit2 == -1)
		{
		sMinute = sTime.substring(isplit1 + 1);
		sSecond = '00';
		}
	else
		{
		sMinute = sTime.substring((sHour.length + 1), isplit2);
		sSecond = sTime.substring(isplit2 + 1);
		}
	
	var DateVal=new Date(sYear,sMonth-1,sDay,sHour,sMinute,sSecond);
	return DateVal;
 }
 
// Compare two given date, if date1 is greater than date2, return true, else false.
 function CompareDate(sDate1,sTime1,sDate2,sTime2)
{
	var DateVal1=gendate(sDate1,sTime1);
	var DateVal2=gendate(sDate2,sTime2);
	return (DateVal1>DateVal2);
}
 function CompareDate1(sDate1,sTime1,sDate2,sTime2)
{
	var DateVal1=gendate(sDate1,sTime1);
	var DateVal2=gendate(sDate2,sTime2);
	return (DateVal1<DateVal2);
	ErrorMessage(102);
}

//Remove both leading and trailing spaces of the string.
function Trim(textvalue)
{
	var strLength=textvalue.length;
	var tempValue=textvalue;
	if (strLength>0)
	{
		for (i=strLength;i>=0;i--)
		{
			if (tempValue.substring(i-1,i)==" ")
				tempValue=tempValue.substring(0,i-1);
			else
				break;
		}
		strLength=tempValue.length;
		if (strLength!=0)
		{
			for (i=0;i<strLength;i++)
			{
				if (tempValue.substring(0,1)==" ")
					tempValue=tempValue.substring(1,tempValue.length);
				else
					break;
			}
		}
	}
	return tempValue;
}

//Field
function makeSqlString(vSql)
{
var re="'";
var sReturn=re+vSql.replace(re,"''")+re;
return sReturn;
}


//Show hide Layers
function MM_showHideLayers() { 
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_findObj(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=MM_findObj(n,d.layers[i].document); 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 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_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];}}
}