//060419 Kaiming
function CompareDate(day, month, year, comparedate, expression, err_msg)
{
	var day1 = day.value
	var month1 = month.value
	var year1 = year.value
	
	var date1 = new Date()
	for(i=0;i<=11;i++)
	{
		date1.setMonth(i)
		date1_str = date1.toString()
		date1_str = date1_str.substring(4,7)
		if(date1_str == month1)
			month2 = i 
	}
	
	date1 = new Date()
	date1.setDate(day1)
	date1.setMonth(month2)
	date1.setYear(year1)

	if(expression == ">")
	{
		if(date1.getTime() > comparedate.getTime())
		{
			alert(err_msg)
			return false;
		}
	}
	else if(expression == "<")
	{
		if(date1.getTime() < comparedate.getTime())
		{
			alert(err_msg)
			return false;
		}
	}
	else if(expression == "=")
	{
		if(date1.getTime() == comparedate.getTime())
		{
			alert(err_msg)
			return false;
		}
	}
	else
	{
		alert("Invalid expression for comparedate")
		return;
	}
}

function PopulateMonthDDL()
{
	var date1 = new Date()
	var strdate
	var arr = new Array(12)	
	for(i=0;i<=11;i++)
	{
		date1.setMonth(i)
		//gets only the abbrievated form of the month name
		strdate = date1.toUTCString().substring(7,11)
	
		document.write("<option value=" + strdate + ">" + strdate + "</option>")
	}		
}

function PopulateDayDDL()
{
	for(i=1;i<=31;i++)
	{
		document.write("<option value=" + i + ">" + i + "</option>")
	}
}
function validFullYear(check,err_msg,min_no,max_no){
   
   str = check.value;
   int_str = parseInt(str);
   
   if(isNaN(str) == true || int_str < min_no || int_str > max_no){
      alert(err_msg);
	  check.focus();
	  return false;
   }   
}
//060419 Kaiming

function filecheck(check){
   var input=check.value;
   str=String(input);
   if( str == ""){
      alert("Please upload a photo");
	  return false;
   }
   else{
	   idx=str.indexOf(".",0);
	   fileext=str.substr((idx+1),str.length);
	   if(fileext == "gif" ){  
	     if(confirm("Your Gif Image may appear distorted , it is advisable to upload jpg image.\n\tAre you sure you want to upload Gif Image?")){ 		 
		    return true;
		 }	
	     else
		    return false;		
	   }
    }
}	

function selectlistindex(check)
{   
   var checknull=1;
   for(i=0;i<check.options.length;i++){
     if (check.options[i].selected){
	    checknull=0;
        idx=i;	 
		break;
     }
   }	
   if (checknull!= 0) 
	  return 0;     		
   else
     return idx;
}

function listcheck(check,err_msg){
   var checknull=0; 
   for(i=0;i<check.options.length;i++){
     if (check.options[i].selected){
	   if( i == 0 ){
	      checknull=1;
	      break;
	   }	  
	 }
   }    
   if (checknull==1){
      alert(err_msg);
	  check.focus();
	  return false;
   }
}

function validfield(check,int_no,err_msg){
   str=new String(check.value)
   if(str.length < int_no || isNaN(str) == true ){
      alert(err_msg);
	  check.focus();
	  return false;
   }
}
 
function validNum(check){
   str=new String(check.value)
   if(isNaN(str) == true ){
      alert("Please Fill in numbers only");
	  check.focus();
	  return false;
   }
 }

function emptyfield(check,err_msg){
   if (check.value == ""){
      alert(err_msg);
	  check.focus();
	  return false;
   }
}

function checkEmail(check,errmsg){
   email = new String(check.value);   
     if (email.indexOf("@") == -1){
	    alert(errmsg);
		check.focus();
		return false;
	 }
	 else
	 {
	   idx1=email.indexOf("@");
	 }
	 if(email.indexOf(".") == -1){
	    alert(errmsg);
		check.focus();
		return false;
	 }
	 else{
	    idx2=email.indexOf(".");
	 }
	 str1=email.substring(0,idx1);
	 if(str1.length < 2){
	    alert(errmsg);
		check.focus();
		return false;
	 }
	 str2=email.substring(idx1,idx2);
	 if(str2.length < 2){
	    alert(errmsg);
		check.focus();
		return false;
	 }
	 str3=email.substring(idx2,email.length-1);
	 if(str3.length < 2){
		alert(errmsg);
		check.focus();
		return false;
	 } 
}

function checkBox(check,err_msg){
   var counter=0;
   for(var i=0;i<check.length;i++)
   {
     if(check[i].checked)
	 {
	   counter=counter+1;
	 }
   }
   if(counter < 1 )
   {
     alert(err_msg);
	 check[0].focus();
	 return false;
   }
}

function rbcheck(check,err_msg){         
   var value=null;
   for (var i=0;i<check.length;i++){
      if(check[i].checked){
	     value=check[i].value;
		 break;
	   }
	}
   if(value == null){
      alert(err_msg);
	  check[0].focus();
	  return false;
   } 
}

