

function matchFileExtGroup(filepath, extensionGroup)
{
	if (filepath.length <= 0) return true;
	var i;
	for (i=0; i<extensionGroup.length; i++)
	{
		if (matchFileExt(filepath, Trim(extensionGroup[i])))
		{
			return true;
		}
	}
	return false;
}

function isValidUploadFile(filepath)
{
	var extFilter;
	extFilter = new Array();
	extFilter[0] = ".vb";
	extFilter[1] = ".asp";
	extFilter[2] = ".aspx";
	extFilter[3] = ".config";
	//extFilter[4] = ".xls"
	//extFilter[5] = ".cvs"
	
	if (filepath.length <= 0) return true;
	var i;
	for (i=0; i<extFilter.length; i++)
	{
		if (matchFileExt(filepath, extFilter[i]))
		{
			return false;
		}
	}
	return true;
}

function matchFileExt(filename, extension)
{
	if (extension.length <= 0) return false;
	if (extension.substring(0, 1) != ".") extension = "." + extension;
	if (filename.length < extension.length) return false;
	if (filename.substring(filename.length - extension.length).toLowerCase() == extension)
		return true;
	else
		return false;
}

function trimEnd(str, trimString)
{
	var iPos, Result;
	if (str.length <= 0)
		return "";
	else if (trimString.length <= 0)
		return str;
	else if (str.length < trimString.length)
		return str;
	
	Result = "";
	try
	{
		iPos = str.lastIndexOf(trimString);
		Result = str.substring(0, iPos);
	}
	catch(e) {}
	return Result;
}

function trimStart(str, trimString)
{
	var iLen, Result;
	if (str.length <= 0)
		return "";
	else if (trimString.length <= 0)
		return str;
	else if (str.length < trimString.length)
		return str;
	
	Result = "";
	try
	{
		iLen = trimString.length;
		Result = str.substring(iLen, str.length - iLen);
	}
	catch(e) {}
	return Result;
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";

var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function IsDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : mm/dd/yyyy.")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day.")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date.")
		return false
	}
return true
}

function dateDiff(p_Interval, p_Date1, p_Date2, p_firstdayofweek, p_firstweekofyear){
	//if(!IsDate(p_Date1)){return "invalid date: '" + p_Date1 + "'";}
	//if(!IsDate(p_Date2)){return "invalid date: '" + p_Date2 + "'";}
	var dt1 = new Date(p_Date1);
	var dt2 = new Date(p_Date2);

	// get ms between dates (UTC) and make into "difference" date
	var iDiffMS = dt2.valueOf() - dt1.valueOf();
	var dtDiff = new Date(iDiffMS);

	// calc various diffs
	var nYears  = dt2.getUTCFullYear() - dt1.getUTCFullYear();
	var nMonths = dt2.getUTCMonth() - dt1.getUTCMonth() + (nYears!=0 ? nYears*12 : 0);
	var nQuarters = parseInt(nMonths/3);	//<<-- different than VBScript, which watches rollover not completion
	
	var nMilliseconds = iDiffMS;
	var nSeconds = parseInt(iDiffMS/1000);
	var nMinutes = parseInt(nSeconds/60);
	var nHours = parseInt(nMinutes/60);
	var nDays  = parseInt(nHours/24);
	var nWeeks = parseInt(nDays/7);


	// return requested difference
	var iDiff = 0;		
	switch(p_Interval.toLowerCase()){
		case "yyyy": return nYears;
		case "q": return nQuarters;
		case "m": return nMonths;
		case "y": 		// day of year
		case "d": return nDays;
		case "w": return nDays;
		case "ww":return nWeeks;		// week of year	// <-- inaccurate, WW should count calendar weeks (# of sundays) between
		case "h": return nHours;
		case "n": return nMinutes;
		case "s": return nSeconds;
		case "ms":return nMilliseconds;	// millisecond	// <-- extension for JS, NOT available in VBScript
		default: return "invalid interval: '" + p_Interval + "'";
	}
}

//**END Date Validation Functionss**//

function IsDateOLD(DateString , Dilimeter, DateFormat) 
{ 
	if (DateString==null) return false; 
	if (Dilimeter=="" || Dilimeter==null) 
		Dilimeter = "-"; 
	if (DateFormat=="" || DateFormat==null)
		DateFormat = "m|d|y"
	var dfArray
	dfArray = DateFormat.split("|")
	var i
	var yearPos, monthPos, dayPos
	for (i=0; i<dfArray.length; i++)
	{
		if (dfArray[i].toLowerCase() == "y")
			yearPos = i;
		else if (dfArray[i].toLowerCase() == "m")
			monthPos = i;
		else if (dfArray[i].toLowerCase() == "d")
			dayPos = i;
	}
		
	var tempy = ""; 
	var tempm = ""; 
	var tempd = ""; 
	var tempArray; 
	if (DateString.length<8 && DateString.length>10) 
		return false;  
	tempArray = DateString.split(Dilimeter); 
	if (tempArray.length!=3) 
		return false; 
	/*
	if (tempArray[0].length==4) 
	{ 
		tempy = tempArray[0]; 
		tempd = tempArray[2]; 
	} 
	else 
	{ 
		//tempy = tempArray[2]; 
		//tempd = tempArray[1]; 
	} 
	tempm = tempArray[1]; 
	*/
	tempy = tempArray[yearPos]; 
	tempm = tempArray[monthPos]; 
	tempd = tempArray[dayPos]; 
	if (isNaN(tempd) || isNaN(tempy) || isNaN(tempm))
		return false;
	var tDateString = tempy + "/" + tempm + "/" + tempd + " 8:0:0";
	var tempDate = new Date(tDateString); 
	if (isNaN(tempDate)) 
		return false; 
	if (((tempDate.getUTCFullYear()).toString()==tempy) && (tempDate.getMonth()==parseInt(tempm)-1) && (tempDate.getDate()==parseInt(tempd))) 
	{ 
		return true; 
	} 
	else 
		return false; 
}

function CheckDate(datestr) 
{ 
	var flag = true;  
	getdate = datestr;  //fob(datestr).value; 
	if (getdate.search(/^[0-9]{4}-(0[1-9]|[1-9]|1[1-2])-((0[1-9]|[1-9])|1[0-9]|2[0-9]|3[0-1])$/)==-1)
		flag = false; 
	else 
	{ 
		var year = getdate.substr(0, getdate.indexOf('-'))  
		var transition_month=getdate.substr(0, getdate.lastIndexOf('-'));  
		var month=transition_month.substr(transition_month.lastIndexOf('-')+1, transition_month.length); 
		if (month.indexOf('0')==0) 
			month=month.substr(1,month.length); 
		var day=getdate.substr(getdate.lastIndexOf('-')+1, getdate.length); 
		if (day.indexOf('0')==0) 
			day=day.substr(1, day.length); 
		flag = true; 
	} 
	if ((month==4 || month==6 || month==9 || month==11) && (day>30)) 
		flag = false;  
	if (month == 2) 
	{ 
		if (LeapYear(year)) 
			if (day>29 || day<1) flag = false; 
			else if (day>28 || day<1) flag = false; 
	} 
	else 
		flag = true; 

	if (!flag) 
	{ 
		//alert("Please enter a valid date."); 
		return flag;
	} 
} 

function VerifyDate(year, month, day) 
{
  var regex = new RegExp(/S/);  
  if(regex.test(day)&& regex.test(month) && regex.test(year)) 
  {
    var regExp = new RegExp(/d/);
    if(!regExp.test(day)|| !regExp.test(month) || !regExp.test(year))
      return ("The date fields contains non-number.");
    var tempDateValue = year + "/" + month + "/" + day;
    if(tempDateValue.length < 6||tempDateValue.length > 10)
      return ("The length of date fields is invalid."); 
    var tempDate = new Date(tempDateValue);
    if(isNaN(tempDate))
      return ("The scope of date fields is invalid.");   
    if(parseInt(year) > 1900 && parseInt(year) < 2500 && ((tempDate.getUTCFullYear
()).toString()==year) && (tempDate.getMonth()==parseInt(month)-1) && (tempDate.getDate()
==parseInt(day)))
      return ("The date fields is OK.");
    else
      return ("The date fields is invalid.");
  }
}

function IsInteger(textField)
{
	var e = 0;
	var w = 0;
	var quantity;
	if (textField.value != "") 
	{
		quantity = parseInt(textField.value);
		if (quantity != 0 && !isNaN(parseInt(textField.value))) 
		{
			textField.value = quantity;
		}
		else 
		{ 
			alert("Please enter a valid number.");
			textField.value = "";
			textField.focus();
		}
	}

	/* other way */
	//textField.value = textField.value.replace(/[^\d]/g,'');		
}

/*
function IsFloat(textField)
{
	//var pattern = ^(-?\\d+)(\\.\\d+)?$
	var reg = new RegExp("^(-?\\d+)(\\.\\d+)?$");
	var flag;
	flag = reg.test(textField.value);
	if (!flag)
	{
		alert("Please enter a valid number.");
		//textField.value = "";
		textField.focus();
	}
}
*/

function IsFloat(num)
{
	var reg = new RegExp("^(-?\\d+)(\\.\\d+)?$");
	var flag;
	flag = reg.test(num);
	return flag;
}

function getInt(str)
{
	return str.replace(/[^\d]/g,'');
}

function AcceptFloat(textField)
{
	//var pattern = "^(-?\\d+)(\\.\\d+)?$"
	var reg = new RegExp("^(-?\\d+)(\\.\\d+)?$");
	var flag, i, str1, quantity;
	flag = reg.test(textField.value);
	if (!flag)
	{
		if (textField.value.indexOf(".") > 0)
		{
			str1 = textField.value;
			while (str1.indexOf(".") < str1.lastIndexOf("."))
			{
				i = str1.lastIndexOf(".");
				str1 = str1.substr(0, i)
			}
			str1 = str1.replace(/[^\d^\.]/g, "");
			textField.value = str1;
		}
		else if (textField.value != "")
		{
			quantity = parseInt(textField.value);
			if (quantity != 0 && !isNaN(parseInt(textField.value))) 
			{
				textField.value = quantity;
			}
			else
			{
				alert("Please enter a valid number.");
				textField.value = "";
				textField.focus();
			}
		}
	}
}

/*
function VerifyEmail(email)
{
	var flag;
	var pattern = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
	flag = pattern.test(email);
	if (flag)
	{
		//alert("Your email address is correct!");
		return true;
	}
	else
　  {
		//alert("Please try again!");
		return false;
	}
}
*/

function VerifyEmail(email) 
{
	invalidChars = " /:,;"
	if (email == "") {	// cannot be empty
	  //alert("Please enter your email address.");
	  return false
        }
	for (i=0; i<invalidChars.length; i++) 
	{	// does it contain any invalid characters?
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) 
		{
			return false
		}
  }
  atPos = email.indexOf("@",1)	// there must be one "@" symbol
  if (atPos == -1) 
  {
		return false
  }
  if (email.indexOf("@",atPos+1) != -1) 
  {	// and only one "@" symbol
		return false
  }
  periodPos = email.indexOf(".",atPos)
  if (periodPos == -1) 
  {			// and at least one "." after the "@"
		return false
  }
  if (periodPos+3 > email.length)	
  { // must be at least 2 characters after the "."
		return false
  }
  return true
}

//######### validatedForm #########/////////////////////
//This function performs form validation for required fields. 
//The required fields are indicated by the hidden field "_required". 
//The value is a list of the field ids plus the question number, 
//separated by comma. Note that here we use field ids so that we can 
//group fields have the different names but the same ids, for example, 
//a group of checkboxes. 
function validatedForm(thisform) 
{
	var errormsg = "Please enter a ";
	if (thisform._required != null) 
	{
		if (Trim(thisform._required.value).length != "") 
		{
			var fieldnames = thisform._required.value.split(",");
			for (m=0; m<fieldnames.length; m++) 
			{
				fieldnamearr = fieldnames[m].split("|");
				fieldname = Trim(fieldnamearr[0]);
				if (fieldnamearr.length > 1) 
				{
					fieldlabel = Trim(fieldnamearr[1]);
					errormsg = errormsg + fieldlabel + ".";
				}
				/*
				if (thisform.elements[fieldname].disabled == false || thisform.elements[fieldname].disabled===undefined) 
				{
					//status = thisform.elements[fieldname].disabled;
					//errormsg = status;
				*/
				if (thisform.elements[fieldname].length===undefined) 
				{
					if (thisform.elements[fieldname].disabled == false || thisform.elements[fieldname].disabled===undefined) 
					{
						if (Trim(thisform.elements[fieldname].value).length=="") 
						{
							alert(errormsg);
							thisform.elements[fieldname].focus();
							return false;
						}
						emailfield = fieldname.toLowerCase();
						if (emailfield.indexOf("email")>0) 
						{
							if (validEmail(Trim(thisform.elements[fieldname].value))==false) 
							{
								thisform.elements[fieldname].focus();
								alert("Please enter a valid email address.");
								return false;
							}
						}
					}
				}
				else 
				{
					if (thisform.elements[fieldname][0].disabled == false || thisform.elements[fieldname][0].disabled===undefined) 
					{
						thischecked = -1
						for (i=0; i<thisform.elements[fieldname].length; i++) 
						{
							if (thisform.elements[fieldname][i].checked || (thisform.elements[fieldname][i].selected && thisform.elements[fieldname][i].value.length!="")) 
							{
								thischecked = i;
							}
						}
						if (thischecked == -1) 
						{
							thisform.elements[fieldname][0].focus();
							alert(errormsg);
							return false;
						}
					}
				}
			}
		}
	}
	return true;
}
//######### validateForm #########/////////////////////



function lockTextBox(name, status) 
{
	var x;
	x = document.getElementById(name);
	if (x != null) 
	{
		if (status) x.value = "";
		x.disabled = status;
	}
}



function jumpForm(elementID) 
{
	if (elementID.length > 0)
		document.getElementById(elementID).focus();
	return;
}


//######### LockAll #########/////////////////////
//This function will disable all the fields except 
//the unlockfield and the fields for the submit button and ASP.NET field. 
//All disabled field will be cleared of any data.
//unlockfield: the field that will remain unlocked.
function lockAll(thisform, unlockfield) 
{
	var fieldname;
	for (n=0; n<thisform.elements.length; n++) 
	{
		fieldname = thisform.elements[n].name;
		if (fieldname != unlockfield && fieldname != "Button1" && fieldname != "__VIEWSTATE") 
		{
			ClearField(thisform.elements[n]);
			thisform.elements[n].disabled = true;
		}
	}
}
//######### LockAll #########/////////////////////



//######### unLockAll #########/////////////////////
//This function will unlock (enable) all the fields except 
//the lockfield and the fields for text next to a check box. 
//lockfield: the field that will remain locked.
function unLockAll(thisform, lockfield) 
{
	var fieldname;
	for (n=0; n<thisform.elements.length; n++) 
	{
		fieldname = thisform.elements[n].name;
		if (fieldname != lockfield && fieldname.indexOf("othertext") == -1 ) 
		{
			thisform.elements[n].disabled = false;
		}
	}
}
//######### unLockAll #########/////////////////////



//######### LockSelected #########/////////////////////
//This function will change the "disabled" status of the field. 
//theform: form object
//fieldprefixstr: a list of field name prefixes separated by comma. 
//Note that "field_1" will match "field1_1", "field_11", "field_123", etc.
//lockstatus: "lock" - disable the fields; "unlock" - enable the fields.
function lockSelected(thisform, fieldprefixstr, lockstatus) 
{
	var fieldprefixarr = fieldprefixstr.split(",");
	for (m=0; m<fieldprefixarr.length; m++) 
	{
		fieldprefix = Trim(fieldprefixarr[m]);
		for (n=0; n<thisform.elements.length; n++) 
		{
			fieldname = thisform.elements[n].name;
			if (fieldname.indexOf(fieldprefix) == 0) 
			{
				if (lockstatus == "lock") 
				{
					ClearField(thisform.elements[n]);
					thisform.elements[n].disabled = true;
				}
				if (lockstatus == "unlock") 
				{
					if (fieldname.indexOf("othertext") == -1 ) 
					{
						thisform.elements[n].disabled = false;
					}
				}
			}
		}
	}
}
//######### LockSelected #########/////////////////////



//######### ClearSelected #########/////////////////////
//Will clear the value of multiple fields. 
//fieldprefixstr: a list of field prefixes that will be cleared
//excludefield: field to be excluded from clearing.
function clearSelected(thisform, fieldprefixstr, excludefield) 
{
	var fieldprefixarr = fieldprefixstr.split(",");
	for (m=0; m<fieldprefixarr.length; m++) 
	{
		fieldprefix = Trim(fieldprefixarr[m]);
		for (n=0; n<thisform.elements.length; n++) 
		{
			fieldname = thisform.elements[n].name;
			if (fieldname.indexOf(fieldprefix) == 0 && fieldname != excludefield) 
			{
				ClearField(thisform.elements[n]);
				if (fieldname.indexOf("othertext") != -1 ) 
				{
					thisform.elements[n].disabled = true;
				}
			}
		}
	}
}



//######### ClearField #########/////////////////////
function clearField(thisfield) 
{
	if (thisfield.type == "text") 
	{
		thisfield.value = "";
	}
	if (thisfield.type == "textarea") 
	{
		thisfield.value = "";
	}
	if (thisfield.type == "checkbox") 
	{
		thisfield.checked = false;
	}
	if (thisfield.type == "radio") 
	{
		thisfield.checked = false;
	}
}



function updateSize(fld_From, fld_To)
{
	var from_elm = document.getElementById(fld_From);
	if (from_elm)
	{	
		var to_elm = document.getElementById(fld_To);
		if (to_elm) to_elm.value = from_elm.value.length
	}
}


//The following added for /yourads/ project

function isValidUploadFile(filepath)
{
	var extFilter;
	extFilter = new Array();
	extFilter[0] = ".vb";
	extFilter[1] = ".asp";
	extFilter[2] = ".aspx";
	extFilter[3] = ".config";
	//extFilter[4] = ".xls"
	//extFilter[5] = ".cvs"
	
	if (filepath.length <= 0) return true;
	var i;
	for (i=0; i<extFilter.length; i++)
	{
		if (matchFileExt(filepath, extFilter[i]))
		{
			return false;
		}
	}
	return true;
}

function matchFileExt(filepath, extension)
{
	if (extension.length <= 0) return false;
	if (extension.substring(0, 1) != ".") extension = "." + extension;
	if (filepath.length < extension.length) return false;
	if (filepath.substring(filepath.length - extension.length).toLowerCase() == extension)
		return true;
	else
		return false;
}

function trimEnd(str, trimString)
{
	var iPos, Result;
	if (str.length <= 0)
		return "";
	else if (trimString.length <= 0)
		return str;
	else if (str.length < trimString.length)
		return str;
	
	Result = "";
	try
	{
		iPos = str.lastIndexOf(trimString);
		Result = str.substring(0, iPos);
	}
	catch(e) {}
	return Result;
}

function trimStart(str, trimString)
{
	var iLen, Result;
	if (str.length <= 0)
		return "";
	else if (trimString.length <= 0)
		return str;
	else if (str.length < trimString.length)
		return str;
	
	Result = "";
	try
	{
		iLen = trimString.length;
		Result = str.substring(iLen, str.length - iLen);
	}
	catch(e) {}
	return Result;
}

//Fuctions to mimmick LTrim,  RTrim, and Trim...
//==================================================================
//LTrim(string) : Returns a copy of a string without leading spaces.
//==================================================================
function LTrim(str)
/*
  PURPOSE: Remove leading blanks from our string.
  IN: str - the string we want to LTrim
*/
{
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(0)) != -1) 
  {
    // We have a string with leading blank(s)...
    var j=0, i = s.length;
    // Iterate from the far left of string until we
    // don't have any more whitespace...
    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
        j++;
    // Get the substring from the first non-whitespace
    // character to the end of the string...
    s = s.substring(j, i);
	}
  return s;
}

//==================================================================
//RTrim(string) : Returns a copy of a string without trailing spaces.
//=================================================================//=
function RTrim(str)
/*
  PURPOSE: Remove trailing blanks from our string.
  IN: str - the string we want to RTrim
*/
{
  // We don't want to trip JUST spaces, but also tabs,
  // line feeds, etc.  Add anything else you want to
  // "trim" here in Whitespace
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) 
  {
    // We have a string with trailing blank(s)...
    var i = s.length - 1;       // Get length of string
    // Iterate from the far right of string until we
    // don't have any more whitespace...
    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
        i--;
    // Get the substring from the front of the string to
    // where the last non-whitespace character is...
    s = s.substring(0, i+1);
  }
  return s;
}


//=============================================================
//Trim(string) : Returns a copy of a string without leading or trailing spaces
//=============================================================
function Trim(str)
/*
  PURPOSE: Remove trailing and leading blanks from our string.
  IN: str - the string we want to Trim

  RETVAL: A Trimmed string!
*/
{
  return RTrim(LTrim(str));
}


function IsDateOLD2(DateString , Dilimeter, DateFormat) 
{ 
	if (DateString==null) return false; 
	if (Dilimeter=="" || Dilimeter==null) 
		Dilimeter = "-"; 
	if (DateFormat=="" || DateFormat==null)
		DateFormat = "m|d|y"
	var dfArray
	dfArray = DateFormat.split("|")
	var i
	var yearPos, monthPos, dayPos
	for (i=0; i<dfArray.length; i++)
	{
		if (dfArray[i].toLowerCase() == "y")
			yearPos = i;
		else if (dfArray[i].toLowerCase() == "m")
			monthPos = i;
		else if (dfArray[i].toLowerCase() == "d")
			dayPos = i;
	}
		
	var tempy = ""; 
	var tempm = ""; 
	var tempd = ""; 
	var tempArray; 
	if (DateString.length<8 && DateString.length>10) 
		return false;  
	tempArray = DateString.split(Dilimeter); 
	if (tempArray.length!=3) 
		return false; 
	/*
	if (tempArray[0].length==4) 
	{ 
		tempy = tempArray[0]; 
		tempd = tempArray[2]; 
	} 
	else 
	{ 
		//tempy = tempArray[2]; 
		//tempd = tempArray[1]; 
	} 
	tempm = tempArray[1]; 
	*/
	tempy = tempArray[yearPos]; 
	tempm = tempArray[monthPos]; 
	tempd = tempArray[dayPos]; 
	if (isNaN(tempd) || isNaN(tempy) || isNaN(tempm))
		alert("Invalid date.");
		return false;
	var tDateString = tempy + "/" + tempm + "/" + tempd + " 8:0:0";
	var tempDate = new Date(tDateString); 
	if (tempy < 1900 || tempy > 2099)
		return false;
	if (isNaN(tempDate)) 
		alert("Invalid date." + tempDate);
		return false; 
	if (((tempDate.getUTCFullYear()).toString()==tempy) && (tempDate.getMonth()==parseInt(tempm)-1) && (tempDate.getDate()==parseInt(tempd))) 
	{ 
		return true; 
	} 
	else 
		return false; 
}

function CheckDate(datestr) 
{ 
	var flag = true;  
	getdate = datestr;  //fob(datestr).value; 
	if (getdate.search(/^[0-9]{4}-(0[1-9]|[1-9]|1[1-2])-((0[1-9]|[1-9])|1[0-9]|2[0-9]|3[0-1])$/)==-1)
		flag = false; 
	else 
	{ 
		var year = getdate.substr(0, getdate.indexOf('-'))  
		var transition_month=getdate.substr(0, getdate.lastIndexOf('-'));  
		var month=transition_month.substr(transition_month.lastIndexOf('-')+1, transition_month.length); 
		if (month.indexOf('0')==0) 
			month=month.substr(1,month.length); 
		var day=getdate.substr(getdate.lastIndexOf('-')+1, getdate.length); 
		if (day.indexOf('0')==0) 
			day=day.substr(1, day.length); 
		flag = true; 
	} 
	if ((month==4 || month==6 || month==9 || month==11) && (day>30)) 
		flag = false;  
	if (month == 2) 
	{ 
		if (LeapYear(year)) 
			if (day>29 || day<1) flag = false; 
			else if (day>28 || day<1) flag = false; 
	} 
	else 
		flag = true; 

	if (!flag) 
	{ 
		//alert("Please enter a valid date."); 
		return flag;
	} 
} 

function VerifyDate(year, month, day) 
{
  var regex = new RegExp(/S/);  
  if(regex.test(day)&& regex.test(month) && regex.test(year)) 
  {
    var regExp = new RegExp(/d/);
    if(!regExp.test(day)|| !regExp.test(month) || !regExp.test(year))
      return ("The date fields contains non-number.");
    var tempDateValue = year + "/" + month + "/" + day;
    if(tempDateValue.length < 6||tempDateValue.length > 10)
      return ("The length of date fields is invalid."); 
    var tempDate = new Date(tempDateValue);
    if(isNaN(tempDate))
      return ("The scope of date fields is invalid.");   
    if(parseInt(year) > 1900 && parseInt(year) < 2500 && ((tempDate.getUTCFullYear
()).toString()==year) && (tempDate.getMonth()==parseInt(month)-1) && (tempDate.getDate()
==parseInt(day)))
      return ("The date fields is OK.");
    else
      return ("The date fields is invalid.");
  }
}

function IsInteger(textField)
{
	var e = 0;
	var w = 0;
	var quantity;
	if (textField.value != "") 
	{
		quantity = parseInt(textField.value);
		if (quantity != 0 && !isNaN(parseInt(textField.value))) 
		{
			textField.value = quantity;
		}
		else 
		{ 
			alert("Please enter a valid number.");
			textField.value = "";
			textField.focus();
		}
	}
	/* other way */
	//textField.value = textField.value.replace(/[^\d]/g,'');		
}

/*
function IsFloat(textField)
{
	//var pattern = ^(-?\\d+)(\\.\\d+)?$
	var reg = new RegExp("^(-?\\d+)(\\.\\d+)?$");
	var flag;
	flag = reg.test(textField.value);
	if (!flag)
	{
		alert("Please enter a valid number.");
		//textField.value = "";
		textField.focus();
	}
}
*/

function IsFloat(num)
{
	var reg = new RegExp("^(-?\\d+)(\\.\\d+)?$");
	var flag;
	flag = reg.test(num);
	return flag;
}

function getInt(str)
{
	return str.replace(/[^\d]/g,'');
}

function AcceptFloat(textField)
{
	//var pattern = "^(-?\\d+)(\\.\\d+)?$"
	var reg = new RegExp("^(-?\\d+)(\\.\\d+)?$");
	var flag, i, str1, quantity;
	flag = reg.test(textField.value);
	if (!flag)
	{
		if (textField.value.indexOf(".") > 0)
		{
			str1 = textField.value;
			while (str1.indexOf(".") < str1.lastIndexOf("."))
			{
				i = str1.lastIndexOf(".");
				str1 = str1.substr(0, i)
			}
			str1 = str1.replace(/[^\d^\.]/g, "");
			textField.value = str1;
		}
		else if (textField.value != "")
		{
			quantity = parseInt(textField.value);
			if (quantity != 0 && !isNaN(parseInt(textField.value))) 
			{
				textField.value = quantity;
			}
			else
			{
				alert("Please enter a valid number.");
				textField.value = "";
				textField.focus();
			}
		}
	}
}

/*
function VerifyEmail(email)
{
	var flag;
	var pattern = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
	//var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
	flag = pattern.test(email);
	if (flag)
	{
		//alert("Your email address is correct!");
		return true;
	}
	else
　{
		//alert("Please try again!");
		return false;
	}
}
*/

function VerifyEmail(email) 
{
	invalidChars = " /:,;"
	if (email == "") {	// cannot be empty
	  //alert("Please enter your email address.");
	  return false
        }
	for (i=0; i<invalidChars.length; i++) 
	{	// does it contain any invalid characters?
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) 
		{
			return false
		}
  }
  atPos = email.indexOf("@",1)	// there must be one "@" symbol
  if (atPos == -1) 
  {
		return false
  }
  if (email.indexOf("@",atPos+1) != -1) 
  {	// and only one "@" symbol
		return false
  }
  periodPos = email.indexOf(".",atPos)
  if (periodPos == -1) 
  {			// and at least one "." after the "@"
		return false
  }
  if (periodPos+3 > email.length)	
  { // must be at least 2 characters after the "."
		return false
  }
  return true
}

function getTagId(tName) 
{
	tName = tName.replace(/(^[\s　]*)|([\s　]*$)/g, "");
	var tagid = 0;
	for(var ti = 0; ti < tName.length; ti++) 
	{
		tagid += tName.charCodeAt(ti);
	}
	return tagid;
}

function urlEncode(str)
{
	var i,temp,p,q;
	var result="";
	str = str.replace(/(^[\s　]*)|([\s　]*$)/g, "");
	for(i=0;i<str.length;i++)
	{
		temp = str.charCodeAt(i);
		if(temp>=0x4e00)
		{
			execScript("ascCode=hex(asc(\""+str.charAt(i)+"\"))", "vbscript");
			result+=ascCode.replace(/(.{2})/g, "%$1");
		}
		else
		{
			result += escape(str.charAt(i));
		}
	}
	return result;
}

//######### validatedForm #########/////////////////////
//This function performs form validation for required fields. 
//The required fields are indicated by the hidden field "_required". 
//The value is a list of the field ids plus the question number, 
//separated by comma. Note that here we use field ids so that we can 
//group fields have the different names but the same ids, for example, 
//a group of checkboxes. 
function validatedForm(thisform) 
{
	var errormsg = "Please enter a ";
	if (thisform._required != null) 
	{
		if (Trim(thisform._required.value).length != "") 
		{
			var fieldnames = thisform._required.value.split(",");
			for (m=0; m<fieldnames.length; m++) 
			{
				fieldnamearr = fieldnames[m].split("|");
				fieldname = Trim(fieldnamearr[0]);
				if (fieldnamearr.length > 1) 
				{
					fieldlabel = Trim(fieldnamearr[1]);
					errormsg = errormsg + fieldlabel + ".";
				}
				/*
				if (thisform.elements[fieldname].disabled == false || thisform.elements[fieldname].disabled===undefined) 
				{
					//status = thisform.elements[fieldname].disabled;
					//errormsg = status;
				*/
				if (thisform.elements[fieldname].length===undefined) 
				{
					if (thisform.elements[fieldname].disabled == false || thisform.elements[fieldname].disabled===undefined) 
					{
						if (Trim(thisform.elements[fieldname].value).length=="") 
						{
							alert(errormsg);
							thisform.elements[fieldname].focus();
							return false;
						}
						emailfield = fieldname.toLowerCase();
						if (emailfield.indexOf("email")>0) 
						{
							if (validEmail(Trim(thisform.elements[fieldname].value))==false) 
							{
								thisform.elements[fieldname].focus();
								alert("Please enter a valid email address.");
								return false;
							}
						}
					}
				}
				else 
				{
					if (thisform.elements[fieldname][0].disabled == false || thisform.elements[fieldname][0].disabled===undefined) 
					{
						thischecked = -1
						for (i=0; i<thisform.elements[fieldname].length; i++) 
						{
							if (thisform.elements[fieldname][i].checked || (thisform.elements[fieldname][i].selected && thisform.elements[fieldname][i].value.length!="")) 
							{
								thischecked = i;
							}
						}
						if (thischecked == -1) 
						{
							thisform.elements[fieldname][0].focus();
							alert(errormsg);
							return false;
						}
					}
				}
			}
		}
	}
	return true;
}
//######### validateForm #########/////////////////////



function lockTextBox(name, status) 
{
	var x;
	x = document.getElementById(name);
	if (x != null) 
	{
		if (status) x.value = "";
		x.disabled = status;
	}
}



function jumpForm(elementID) 
{
	if (elementID.length > 0)
		document.getElementById(elementID).focus();
	return;
}


//######### lockAll #########/////////////////////
//This function will disable all the fields except 
//the unlockfield and the fields for the submit button and ASP.NET field. 
//All disabled field will be cleared of any data.
//unlockfield: the field that will remain unlocked.
function lockAll(thisform, unlockfield) 
{
	var fieldname;
	for (n=0; n<thisform.elements.length; n++) 
	{
		fieldname = thisform.elements[n].name;
		if (fieldname != unlockfield && fieldname != "Button1" && fieldname != "__VIEWSTATE") 
		{
			clearField(thisform.elements[n]);
			thisform.elements[n].disabled = true;
		}
	}
}
//######### lockAll #########/////////////////////



//######### unLockAll #########/////////////////////
//This function will unlock (enable) all the fields except 
//the lockfield and the fields for text next to a check box. 
//lockfield: the field that will remain locked.
function unLockAll(thisform, lockfield) 
{
	var fieldname;
	for (n=0; n<thisform.elements.length; n++) 
	{
		fieldname = thisform.elements[n].name;
		if (fieldname != lockfield) 
		{
			thisform.elements[n].disabled = false;
		}
	}
}
//######### unLockAll #########/////////////////////



//######### lockSelected #########/////////////////////
//This function will change the "disabled" status of the field. 
//theform: form object
//fieldprefixstr: a list of field name prefixes separated by comma. 
//Note that "field_1" will match "field1_1", "field_11", "field_123", etc.
//lockstatus: "lock" - disable the fields; "unlock" - enable the fields.
function lockSelected(thisform, fieldprefixstr, lockstatus) 
{
	var fieldprefixarr = fieldprefixstr.split(",");
	for (m=0; m<fieldprefixarr.length; m++) 
	{
		fieldprefix = Trim(fieldprefixarr[m]);
		for (n=0; n<thisform.elements.length; n++) 
		{
			fieldname = thisform.elements[n].name;
			if (fieldname.indexOf(fieldprefix) == 0) 
			{
				if (lockstatus == "lock") 
				{
					clearField(thisform.elements[n]);
					thisform.elements[n].disabled = true;
				}
				if (lockstatus == "unlock") 
				{
					if (fieldname.indexOf("othertext") == -1 ) 
					{
						thisform.elements[n].disabled = false;
					}
				}
			}
		}
	}
}
//######### lockSelected #########/////////////////////



//######### clearSelected #########/////////////////////
//Will clear the value of multiple fields. 
//fieldprefixstr: a list of field prefixes that will be cleared
//excludefield: field to be excluded from clearing.
function clearSelected(thisform, fieldprefixstr, excludefield) 
{
	var fieldprefixarr = fieldprefixstr.split(",");
	for (m=0; m<fieldprefixarr.length; m++) 
	{
		fieldprefix = Trim(fieldprefixarr[m]);
		for (n=0; n<thisform.elements.length; n++) 
		{
			fieldname = thisform.elements[n].name;
			if (fieldname.indexOf(fieldprefix) == 0 && fieldname != excludefield) 
			{
				clearField(thisform.elements[n]);
				if (fieldname.indexOf("othertext") != -1 ) 
				{
					thisform.elements[n].disabled = true;
				}
			}
		}
	}
}



//######### clearField #########/////////////////////
function clearField(thisfield) 
{
	if (thisfield.type == "text") 
	{
		thisfield.value = "";
	}
	if (thisfield.type == "textarea") 
	{
		thisfield.value = "";
	}
	if (thisfield.type == "checkbox") 
	{
		thisfield.checked = false;
	}
	if (thisfield.type == "radio") 
	{
		thisfield.checked = false;
	}
}



function updateSize(fld_From, fld_To)
{
	var from_elm = document.getElementById(fld_From);
	if (from_elm)
	{	
		var to_elm = document.getElementById(fld_To);
		if (to_elm) to_elm.value = from_elm.value.length
	}
}

// browser  type  
var Browsertype = {
    IE:     !!(window.attachEvent && !window.opera),
    Opera:  !!window.opera,
    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
    MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
  };
  
// GET random 
function GetUniqueID()
{
    return Math.floor(Math.random() * 10000000) + (new Date()).getTime() % 1000000000;
}

function PageReturnFalse(evt)
{
    if (Browsertype.IE) //IE
    {
        window.event.returnValue = false ;   
    }
    else //Firefox
    {
       evt.preventDefault(); // stop event to server.
    }
}

function IsSelectCheckbox(chkcontainer)
{
    var chkboxList,ischeck = false ;
    
    var chkbox = document.getElementById(chkcontainer);
    
    if(chkbox != null)
    {
	    chkboxList =chkbox.getElementsByTagName("INPUT");
    	
	    if (chkboxList != undefined && chkboxList != null && chkboxList.length > 0)
	    {
		    for (i=0; i<chkboxList.length; i++)
		    {
		        if(chkboxList[i].type=="checkbox")
		        {
			        if(chkboxList[i].checked)
			        {
			            ischeck = true;
			            break;
			        }
			    }
		    }
	    }
	}

	return ischeck;
}

function GetSelectChks(chkcontainer)
{
    var chkboxList,chklst = new Array() ;
    
     var chkbox = document.getElementById(chkcontainer);
    
    if(chkbox != null)
    {
	    chkboxList =chkbox.getElementsByTagName("INPUT");
    	
	    if (chkboxList != undefined && chkboxList != null && chkboxList.length > 0)
	    {
		    for (i=0; i<chkboxList.length; i++)
		    {
		        if(chkboxList[i].type=="checkbox")
		        {
			        if(chkboxList[i].checked)
			        {
			            chklst.push(chkboxList[i]);
			        }
			    }
		    }
	    }
	}

	return chklst;
}



function NoGetSelectChks(chkcontainer)
{
    var chkboxList,chklst = new Array() ;
	chkboxList =document.getElementById(chkcontainer).getElementsByTagName("INPUT");
	
	if (chkboxList != undefined && chkboxList != null && chkboxList.length > 0)
	{
		for (i=0; i<chkboxList.length; i++)
		{
		    if(chkboxList[i].type=="checkbox")
		    {
			    if(!chkboxList[i].checked)
			    {
			        chklst.push(chkboxList[i]);
			    }
			}
		}
	}

	return chklst;
}

function GetFormUploadFiles(chkcontainer)
{
    var chkboxList,chklst = new Array() ;
	chkboxList = document.getElementById(chkcontainer).getElementsByTagName("INPUT");
	
	if (chkboxList != undefined && chkboxList != null && chkboxList.length > 0)
	{
		for (i=0; i<chkboxList.length; i++)
		{
		    if(chkboxList[i].type=="file")
		    {
			   chklst.push(chkboxList[i]);
			}
		}
	}

	return chklst;
}


function RemoveArray(array,attachId) 
{ 
    var f=false; 
    for(var i=0,n=0;i<array.length;i++) 
    { 
    if(array[i]!=attachId) 
    { 
    array[n++]=array[i] 
    }else 
    f=true; 
    } 
    if(f==true) 
    array.length -= 1; 
} 

function FindArray(array,value)
{
    var f= false;
    for(var i=0,n=0;i<array.length;i++) 
    { 
        if(array[i]==value) 
        { 
            f= true;
            break;
        }
    }
    return f;
}

Array.prototype.remove = function (obj) { 
    return RemoveArray(this,obj); 
}; 

Array.prototype.find = function (obj) { 
    return FindArray(this,obj); 
}; 

function MM_openBrWindow(theURL,winName,features) { //v2.0
      window.open(theURL,winName,features);
    }
    


function openWinCenter(u, w, h,winName) 
{ 
    var l = (screen.width - w) / 2; 
    var t = (screen.height - h) / 2; 
    var s = 'width=' + w + ', height=' + h + ', top=' + t + ', left=' + l; 
    s += ', toolbar=no, scrollbars=no, menubar=no, location=no, resizable=no'; 
    MM_openBrWindow(u, winName, s); 
} 

function DelRowByTdEle(e)
{
   var objdel =document.getElementById(e);
   document.getElementById('tblmemberlst').deleteRow(objdel.parentNode.parentNode.rowIndex);
}


function GetSelectLnks(chkcontainer)
{
    //return a array of link
	return document.getElementById(chkcontainer).getElementsByTagName("A");
}


//enter control
function Panel_FireDefaultButton(event, target) 
{
    if (event.keyCode == 13 && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea"))) 
    {
        var defaultButton = document.getElementById(target);
        if (defaultButton && typeof (defaultButton.click) != "undefined") 
        {
            defaultButton.click();
            event.cancelBubble = true;
            if (event.stopPropagation) event.stopPropagation();
            return false;
        }
    }
    return true;
}