
/*For others function*/
function onEnter(e)
{	
	if(e.keyCode == 13) return true;
	return false;
}

function onEscape(e)
{	
	if(e.keyCode == 27) return true;
	return false;
}

function isValidEmail(text_box_class_name, err_msg_id)
{	
	err_msg = 'Invalid email address.';
	email = $('.'+text_box_class_name);			
	if(!/^([a-zA-Z0-9_\.])+\@([a-zA-Z0-9\-])+\.([a-zA-Z0-9]{2,4})(\.[a-zA-Z0-9]{2,4})?$/.test(email.val()))
	{			
		email.focus();
		if(err_msg_id!=null) $('#'+err_msg_id).html(err_msg);
		else alert(err_msg);
		return false;
	}
	return true;
}

function IsNumeric(strString, option) 
{ 
	if(option==null || option==false)
	    var strValidChars = "0123456789"; 
	else var strValidChars = "0123456789."; 	
    var strChar; 
    var blnResult = true; 
    //var strSequence = document.frmQuestionDetail.txtSequence.value; 

    //test strString consists of valid characters listed above 

    if (strString.length == 0) 
        return false; 
    for (i = 0; i < strString.length && blnResult == true; i++) 
    { 
        strChar = strString.charAt(i); 
        if (strValidChars.indexOf(strChar) == -1) 
        { 
            blnResult = false; 
        } 
     } 
	return blnResult; 
}

function timeCharAccept(strString) 
{ 	
	var strValidChars = "0123456789:"; 	
    var strChar;     
    for (i = 0; i < strString.length; i++) { 
        strChar = strString.charAt(i); 
        if (strValidChars.indexOf(strChar) == -1) { 
            return false; 
        } 
     } 
	return true; 
}

function is_positive_float_number(item_id, err_msg_id) {
		
	$("#"+item_id).css('backgroundColor','white');
	if(err_msg_id!=null) $("#"+err_msg_id).html('');
	value = $("#"+item_id).val();	    
	invalid_number = false; 
	is_error = false;
	err_msg = "";
	
	if(value.length==0)
	{
		if(err_msg_id!=null) $("#"+err_msg_id).html('This field cannot be empty.'); else alert('This field cannot be empty.');
		$("#"+item_id).focus(); 
		return false;
	}
	
	for(i=0; i<value.length; i++)
	{
		if(value.charAt(i)=="-" )
		{
			invalid_number = true;
			break;
		}
	}
	
	if(isNaN(value))
	{
		is_error = true;
		err_msg = "Invalid number.";		
	}	    
	else if(parseFloat(value)==0)
	{
		is_error = true;
		err_msg = "This field must be greater than zero.";			
	}
	else if(invalid_number)
	{
		is_error = true;
		err_msg = "This field cannot be negative number.";			
	}
	
	if(is_error)
	{        	
		if(err_msg_id!=null) $("#"+err_msg_id).html(err_msg);  else alert(err_msg);
		$("#"+item_id).focus();  	
		$("#"+item_id).css('backgroundColor','#FF3333');
		return false;
	}
	return true;
} 

function trimAllChar(str, char) 
{ 
    if(char==null) char=' ';
	var str1 = ''; 
    var i = 0; 
    while(i != str.length) 
    { 
        if(str.charAt(i) != char) 
            str1 = str1 + str.charAt(i); i ++; 
    } 
    return str1; 
}

function trimAllSpace(str) 
{ 
    var str1 = ''; 
    var i = 0; 
    while(i != str.length) 
    { 
        if(str.charAt(i) != ' ') 
            str1 = str1 + str.charAt(i); i ++; 
    } 
    return str1; 
}

function trimString(str) 
{ 
     var str1 = ''; 
     var i = 0; 
     while ( i != str.length) 
     { 
         if(str.charAt(i) != ' ') str1 = str1 + str.charAt(i); i++; 
     }
     var retval = IsNumeric(str1); 
     if(retval == false) 
         return -100; 
     else 
         return str1; 
}

function roundNumber(num, dec)
{
	if(dec==null) dec = 2;
	result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

/*
var strval = document.webform.TextBox1.value;
*/
function validatetime(obj)
{  
	
	var strval = obj.value
	//var strval = $(obj).val();
	
  var strval1;
  
  //Removing all space
  strval = trimAllSpace(strval); 
  //$(obj).val(strval);
  
  if(strval.lenght==0) return true;
  
  if(!timeCharAccept(strval)) {
	//alert("invalid time. Time format should be HH:MM.");
  	return false;
  }	

  if(strval.lenght > 5) {
   //alert("invalid time. Time format should be HH:MM.");
   return false;
  }
      
  var pos1 = strval.indexOf(':');
  
  if(pos1 < 0 ) {
  
  	if(strval.length>=5) {
  		//alert("invalid time. Time format should be HH:MM.");
   		return false;
  	}
  	else if(strval.length>1) {
  		var tmphorval = 0;
  		var tmpminval = 0;
  		
  		if(strval.length==2) {
  			tmphorval = parseInt(strval);			
  		}
  		else if(strval.length==3) {
  			tmphorval = parseInt(strval.substring(0,2));
  			tmpminval = parseInt(strval.substring(2,3));
  		}
  		else if(strval.length==4) {
  			tmphorval = parseInt(strval.substring(0,2));
  			tmpminval = parseInt(strval.substring(2,4));
  		}
  		
  		if(tmphorval > 23) {
			//alert("Invalid time. Hour can not be greater that 23.");
			return false;
		}
		else if(tmphorval < 0) {
			//alert("Invalid time. Hour can not be hours less than 0.");
			return false;
		}			
		else if(tmpminval > 59) {
			//alert("Invalid time. Minute can not be more than 59.");
			 return false;
		}   
		else if(tmpminval < 0) {
			//alert("Invalid time. Minute can not be less than 0.");
			return false;
		}
  	}
  }  
  else if(pos1 > 2 || pos1 < 1) {
   //alert("invalid time. Time format should be HH:MM.");
   return false;
  }
  
  if(pos1>0) {
	  //Checking hours

	  var horval =  trimString(strval.substring(0,pos1));
	   
	  if(horval == -100)
	  {
	   //alert("Invalid time. Hour should contain only integer value (0-23).");
	   return false;
	  }
		  
	  if(horval > 23)
	  {
	   //alert("Invalid time. Hour can not be greater that 23.");
	   return false;
	  }
	  else if(horval < 0)
	  {
	   //alert("Invalid time. Hour can not be hours less than 0.");
	   return false;
	  }
	  //Completes checking hours.

	  
	  //Checking minutes.

	  var minval =  trimString(strval.substring(pos1+1,pos1 + 3));
	  
	  if(minval == -100)
	  {
	   //alert("Invalid time. Minute should have only integer value (0-59).");
	   return false;
	  }
		
	  if(minval > 59)
	  {
		 //alert("Invalid time. Minute can not be more than 59.");
		 return false;
	  }   
	  else if(minval < 0)
	  {
	   //alert("Invalid time. Minute can not be less than 0.");
	   return false;
	  }
  } 
  //Checking minutes completed.  
      
  return true;
  
  
 }

function compare_date(str1, str2)	// date must be formatted in mm/dd/yyyy
{
	var dtCh = '/';	
	
	arr_str1 = str1.split(dtCh);
	arr_str2 = str2.split(dtCh);
	
	var day1=parseInt(arr_str1[1]), month1=parseInt(arr_str1[0]), year1=parseInt(arr_str1[2]);
	var day2=parseInt(arr_str2[1]), month2=parseInt(arr_str2[0]), year2=parseInt(arr_str2[2]); 
	
	if(year1 > year2) return 1;
	if(year1 < year2) return -1;
	
	if(month1 > month2) return 1;
	if(month1 < month2) return -1;
	
	if(day1 > day2) return 1;
	if(day1 < day2) return -1;
	
	return 0;	
}
/**
	Delete the white space in string
	Include LTrim And RTrim
	@param none
*/
// Begin Trim Function
function Trim(TRIM_VALUE)
{
		if(TRIM_VALUE.length < 1)
			{
				return "";
			}
				TRIM_VALUE = RTrim(TRIM_VALUE);
				TRIM_VALUE = LTrim(TRIM_VALUE);
		if(TRIM_VALUE=="")
			{
				return "";
			}
		else
			{
				return TRIM_VALUE;
			}
}
function RTrim(VALUE)
{
		var w_space = String.fromCharCode(32);
		var v_length = VALUE.length;
		var strTemp = "";
		if(v_length < 0)
			{
				return "";
			}
		var iTemp = v_length -1;

		while(iTemp > -1)
			{
				if(VALUE.charAt(iTemp) == w_space)
				{
				}
				else
				{
					strTemp = VALUE.substring(0,iTemp +1);
					break;
				}
				iTemp = iTemp-1;

			} 
		return strTemp;

} 

function LTrim(VALUE)
	{
		var w_space = String.fromCharCode(32);
		if(v_length < 1)
			{
				return "";
			}
		var v_length = VALUE.length;
		var strTemp = "";

		var iTemp = 0;

		while(iTemp < v_length)
			{
				if(VALUE.charAt(iTemp) == w_space)
					{
					}
				else
					{
						strTemp = VALUE.substring(iTemp,v_length);
						break;
					}
						iTemp = iTemp + 1;
			} 
		return strTemp;
} 
// End Trim Function
