/*GENERAL METHODS*/
/*Check for Empty String*/
function isEmptyString(chkStr) {

	if (chkStr == "") {
		return true;
	}
	else {
		var numWhiteSpaces = 0;
		for (var i=0; i < chkStr.length; i++) {
			if (chkStr.substring(i, i+1) == " ") {
				numWhiteSpaces++;
			}
		}
		if (numWhiteSpaces == chkStr.length) {
			return true;
		}
		else {
			return false;
		}
	}
}

/*Function to check only Alphabets*/
function chkAlphabetChr(codeValue)
{
	var validChars1="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz \'’"; //Allow single quote for Irish names (For ex, O'Brien)
	var validChars2="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	
    if(codeValue=="")
        return false;
	
	if (validChars2.indexOf(codeValue.charAt(0))<0)
	{
		return true;
	}
	for(i=0;i<codeValue.length;i++)
    {		
		if (validChars1.indexOf(codeValue.charAt(i))<0)
			return true;
	}
}

/*function chkAlphabetChr(codeValue)
{
    var flag="true";
    if(codeValue=="")
        return false;
    for(i=0;i<codeValue.length;i++)
    {
    	if(((codeValue.charAt(i)>='A') && (codeValue.charAt(i)<='Z'))||((codeValue.charAt(i)>='a') && (codeValue.charAt(i)<='z')))
        {
    		flag="false";
    	}
        else
        {
            flag="true";
		    break;
        }
    }
    if(flag=="false")
    {
        return false;
    }
    else
    {
        return true;
    }
}*/

/*Function to check valid EMail Address*/
function eMailIDcheck(str) {
 
  var at="@";
  var dot=".";
  var lat=str.indexOf(at);
  var lstr=str.length;
  var ldot=str.indexOf(dot);
  var specialCharArray=new Array('~', '!', '%', '^', '*', '+', '=', '{',
     '}', '|', '/', ':', ';', '<', '>', '?', ',', '(', ')', '\\',
     '\'');
  if (str.indexOf(at)==-1){
     
     return true;
  }
 
  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
    
     return true;
  }
 
  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
     
      return true;
  }
 
   if (str.indexOf(at,(lat+1))!=-1){
      
      return true;
   }
 
   if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
     
      return true;
   }
 
   if (str.indexOf(dot,(lat+2))==-1){
     
      return true;
   }
  
   if (str.indexOf(" ")!=-1){
     
      return true;
   }
 
  for (i = 0; i < specialCharArray.length; i++) {
    if(str.indexOf(specialCharArray[i])>0){
     //alert("Special charecters not allowed");
     return true;
    }
  }
    return false ;    
 }
 
 /*Function to get Current Date*/
/* EXPLANATION FOR WHY 38
Fortunately there is a simple solution to this extremely complex problem. 
Since it is supported by all browsers, always use getYear(). 
Divide the outcome by 100 and take the modulus, so that now we have a number from 0 to 99. 
If this number is smaller than 38, add 2000, if it's larger add 1900. This always gives the correct year.
So always use the function below when you have to calculate a year:
(Why 38? Because Epoch Time will end in 2038. You can also use 
(y > 69) ? 1900: 2000;
because in the Epoch Time system no date can be before 1970).
*/
var Days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var today = new Date();
var Year = takeYear(today);
var Month = leadingZero(today.getMonth()+1);
var DayName = Days[today.getDay()];
var Day = leadingZero(today.getDate());
var Hours = leadingZero(today.getHours());
var Minutes = leadingZero(today.getMinutes());
var Seconds = leadingZero(today.getSeconds());

function takeYear(theDate)
{
	x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}

function leadingZero(nr)
{
	if (nr < 10) nr = "0" + nr;
	return nr;
}


/*Function to check valid Canadian ZIP CODE*/
function isPostCode(entry)
{ 
	strlen = entry.length; if (strlen != 6) {return false;}
	entry=entry.toUpperCase();        // in case of lowercase characters
	// Check for legal characters in string - note index starts at zero
	//if ('ABCEHJKLMNPRSTVXY'.indexOf(entry.charAt(0)) < 0) {return false;}
	if ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.indexOf(entry.charAt(0)) < 0) {return false;}
	if ('0123456789'.indexOf(entry.charAt(1)) < 0) {return false;}
	//if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(2)) < 0) {return false;}
	if ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.indexOf(entry.charAt(2)) < 0) {return false;}
	if ('0123456789'.indexOf(entry.charAt(3)) < 0) {return false;}
	//if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(4)) < 0) {return false;}
	if ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.indexOf(entry.charAt(4)) < 0) {return false;}
	if ('0123456789'.indexOf(entry.charAt(5)) < 0) {return false;}
	return true; 
}

/*Function to check valid USA ZIP CODE*/
function validateZIP(field) {
var valid = "0123456789-";
var hyphencount = 0;

if (field.length!=5 && field.length!=10) {
return false;
}
for (var i=0; i < field.length; i++) {
temp = "" + field.substring(i, i+1);
if (temp == "-") hyphencount++;
if (valid.indexOf(temp) == "-1") {
	return false;
}
if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {
	return false;
   }
}
return true;
}

/*Function to check Radio Button Selection*/
function radio_button_checker(radio_button)
{
	var radio_choice = false;
	for (counter = 0; counter < radio_button.length; counter++)
	{
	// If a radio button has been selected it will return true
	// (If not it will return false)
		if (radio_button[counter].checked)
			radio_choice = true; 
	}
	if (!radio_choice)
	{
	// If there were no selections made display an alert box 
		return (false);
	}
	return (true);
}

function checkEqualString(str1,str2)
{
	if (str1.length != str2.length)
		return true;
}

/*Function will return true/false based 
on whether the passed non-blank 
value is a number or not*/
function isNumeric(testValue)
{
	pat=/^[0-9]*$/gi;
	return pat.test(testValue);
}


/*
    function to limit the amount of text that can be
    typed inside a textarea.
*/
function textLimit(field, maxlength)
{
	if (field.value.length > maxlength)
	{
		field.value = field.value.substring(0, maxlength);
	}
}

