/**
 * Copyright (c) 2000-2003 Liferay Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
 
 
 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;
}
} //End Function

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;

} //End While
return strTemp;

} //End Function

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;
} //End While
return strTemp;
} //End Function
 

function isEMailAddr(elem) 
{
    var str = elem.value;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
//        setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')", 0);
        return false;
    } else {
        return true;
    }
}

function isValidEMailAddr(value) 
{
    var str = value;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        return false;
    } else {
        return true;
    }
}


function alphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
	{
	  var alphaa = numaric.charAt(j);
	  var hh = alphaa.charCodeAt(0);
	  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
	  {
	  }
	  else	
	  {
		 return false;
	  }
	}
 return true;
}



function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
 
 function IsValidNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
 
 
   
   function IsRollNo(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }



function validateImageFileName(fileName) {
	if (fileName == null || fileName == "") {
		return false;
	}

	if (fileName.toLowerCase().indexOf(".gif") == fileName.length - 4 ||
		fileName.toLowerCase().indexOf(".jpg") == fileName.length - 4 ||
		fileName.toLowerCase().indexOf(".png") == fileName.length - 4) {

		return true;
	}

	return false;
}


// 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 compareDates (value1, value2) {
   var date1, date2;
   var month1, month2;
   var year1, year2;

   date1  = value1.substring (0, value1.indexOf ("-"));
   month1 = value1.substring (value1.indexOf ("-")+1, value1.lastIndexOf ("-"));
   year1 = value1.substring (value1.lastIndexOf ("-")+1, value1.length);

  date2  = value2.substring (0, value2.indexOf ("-"));
  month2 = value2.substring (value2.indexOf ("-")+1, value2.lastIndexOf ("-"));
  year2 = value2.substring (value2.lastIndexOf ("-")+1, value2.length);
  
   	date1 = parseInt(date1, 10);
  	month1= parseInt(month1, 10);
  	year1= parseInt(year1, 10);
  	
  	date2 = parseInt(date2, 10);
  	month2= parseInt(month2, 10);
  	year2= parseInt(year2, 10);

   if (year1 > year2) return 1;
   else if (year1 < year2) return -1;
   else if (month1 > month2) return 1;
   else if (month1 < month2) return -1;
   else if (date1 > date2) return 1;
   else if (date1 < date2) return -1;
   else return 0;
}

function compareDatewithCurrent (value1) 

{

var date1, date2;

var month1, month2;

var year1, year2;

date1 = value1.substring (0, value1.indexOf ("-"));

month1 = value1.substring (value1.indexOf ("-")+1, value1.lastIndexOf ("-"));

year1 = value1.substring (value1.lastIndexOf ("-")+1, value1.length);


var todaydate = new Date();

var todayday = todaydate.getDate();

var todaymonth = todaydate.getMonth() + 1;

var todayyear = todaydate.getYear() + 1900;

var date2 =todayday;

var month2=todaymonth;

var year2 =todayyear;


if (year1 > year2) return 1;

else if (year1 < year2) return -1;

else if (month1 > month2) return 1;

else if (month1 < month2) return -1;

else if (date1 > date2) return 1;

else if (date1 < date2) return -1;

else return 0;

}


function disableElements()
{
    for(var i=0;i<document.forms.length;i++)
    {
        for(var j=0;j<document.forms[i].length;j++)
        { 
        if(document.forms[i].elements[j].type != 'submit' && document.forms[i].elements[j].type == 'button'){
            document.forms[i].elements[j].disabled=true;
        }    
        }
    }
}


function IsMobileNumber(strString)
{
   var strValidChars = "0123456789+";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}

