
function isEmail(str) 
{
        var supported = 0;
        if (window.RegExp) 
        {
                var tempStr = "a";
                var tempReg = new RegExp(tempStr);
                if (tempReg.test(tempStr)) supported = 1;
        }
        if (!supported) 
        {
                return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
        }
        var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
        var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
        return (!r1.test(str) && r2.test(str));
}

function removespace(s){
   var result;
   result = "";
   for (var i=0; i<s.length; i++){
      if (s.charAt(i) != ' '){
         result += s.charAt(i);
      }
   }
   return result;
}

function isRadioChecked(Opt){

  for (i=0; i<Opt.length; i++) {
      if (Opt[i].checked) {
          return true;
          break;
      }
  }
  return false;
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))   }

function isInteger(s)
{   // to check if the number is integer
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    // All characters are numbers.
    return true;
}

//auto change the days of the selected month and year
function  change_menu(year_id,month_id,day_id){
	var  index  =  year_id.selectedIndex;
	var  i	=  month_id.selectedIndex;
	var  y	=  year_id.options[index].value;
	var  mlength  =  0
	
	day_id.options[0].selected  =  true;
	if  ((i  ==  0)|| (i  ==  2) ||(i  ==  4)|| (i	==  6)||(i  ==	7)||(i	==  9)||(i  ==	11)){
		mlength  =  31;
		day_id.options.length  =  mlength;
		day_id.options[28].value  =  29;
		day_id.options[28].text  =  29;
		day_id.options[29].value  =  30;
		day_id.options[29].text  =  30;
		day_id.options[30].value  =  31;
		day_id.options[30].text  =  31; 	
	}
	else  if  (i  ==  1)
	{
		if  (((y%4  ==	0)&&(y%100!=0))||(y%400==0))
		{
			mlength  =  29;
			day_id.options.length  =  mlength;
			day_id.options[28].value  =  29;
			day_id.options[28].text  =  29;
		}
		else{
			mlength  =  28;  
			day_id.options.length  =  mlength;
		}
	}
	else  if  ((i  ==  3)||(i  ==  5)||(i  ==  8)||(i  ==  10)){
		mlength  =  30;
		day_id.options.length  =  mlength;
		day_id.options[28].value  =  29;
		day_id.options[28].text  =  29;
		day_id.options[29].value  =  30;
		day_id.options[29].text  =  30;
	}  
}

function isValidDate(iYear,iMonth,iDay){
	//for months that have only 30 days
	if  ((iMonth==4)||(iMonth==6)||(i==9)||(i==11)){
        if (iDay>30) {
           return false;
        }	
	}
	//for Feb that may have 28 or 29 days
	else if (iMonth==2)
	{
		if (((iYear%4==0)&&(iYear%100!=0))||(iYear%400==0))
		{
		  //a lead year
		  if (iDay>29){
		     return false;
		  }
		}
		else{
		  //not a lead year
		  if (iDay>28){
		     return false;
		  }
		}
	}
	return true;
}

function MonthName2Num(strMonth){
    var MonthName = new Array;
    MonthName[1] = "jan";
    MonthName[2] = "feb";
    MonthName[3] = "mar";
    MonthName[4] = "apr";
    MonthName[5] = "may";
    MonthName[6] = "jun";
    MonthName[7] = "jul";
    MonthName[8] = "aug";
    MonthName[9] = "sep";
    MonthName[10] = "oct";
    MonthName[11] = "nov";
    MonthName[12] = "dec";
    for (i=1;i<13;i++){
       if (strMonth.substring(0,3).toLowerCase()==MonthName[i]){
          return i;
          break;
       }
    }
    return 0;
}


function Num2Monthname(iMonth){
    var MonthName = new Array;
    MonthName[1] = "January";
    MonthName[2] = "February";
    MonthName[3] = "March";
    MonthName[4] = "April";
    MonthName[5] = "May";
    MonthName[6] = "June";
    MonthName[7] = "July";
    MonthName[8] = "August";
    MonthName[9] = "September";
    MonthName[10] = "October";
    MonthName[11] = "November";
    MonthName[12] = "December";
    return MonthName[iMonth];
}


function BeforeToday(Y,M,D){

    Now = new Date();
    yT = Now.getUTCFullYear();
    mT = Now.getUTCMonth() + 1;
    dT = Now.getUTCDate();

    Today = yT + right("0"+mT,2) + right("0"+dT,2);
    InDate1 = Y + right("0"+M,2)+right("0"+D,2);

    if (Number(InDate1)<Number(Today)){
       return true;
    }else {
       return false;
    }
}


function DateDiff(Y1,M1,D1,Y2,M2,D2){

    InDate1 = Y1 + right("0"+M1,2) + right("0"+D1,2);
    InDate2 = Y2 + right("0"+M2,2) + right("0"+D2,2);
    return (Number(InDate2) - Number(InDate1));
}

function right(inString,iLength){
   return (inString.substring(inString.length-iLength,iLength+1));
}

function openwin(url,w,h){
	window.open(url,'win','width='+w+',height='+h+',scrollbars=yes,menubar=no');
}

function openwin2(url,w,h){
	window.open(url,'win2','width='+w+',height='+h+',scrollbars=yes,menubar=no');
}

function openwin3(url,w,h){
	window.open(url,'win3','width='+w+',height='+h+',scrollbars=yes,menubar=no');
}

function reload_parent(){
	window.opener.location.reload(true);
	self.close();
}

function del_event(url){
     msg ="Are you sure to delete this record?";
     
	if (confirm(msg)) {
	    self.location.replace(url);
		//self.location.reload(true);
    }
}