/*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;
   }
 	
 	/** to check double dot(..) in email */
 	/*if (str.indexOf(dot,(ldot+1))!=-1){      
      return true;
   	}*/
   
   if (str.indexOf('..')!=-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 ('0123456789'.indexOf(entry.charAt(1)) < 0) {return false;}
	if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.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 ('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(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 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);
	}	
}

	function isValidEmail(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 false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		  
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   
		    return false
		 }

		for (i = 0; i < specialCharArray.length; i++) {
				if(str.indexOf(specialCharArray[i])>0){
					return false
				}
		}
 		 return true					
	}


function isNumericValue(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 to check valid Phone*/
  
function validatePhone(field) 
{
	var re = /^([0-9]{3}\-){2}[0-9]{4}$/;
	if(!re.test(field))
		return false;
	else
		return true;
} 

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function compareOptionValues(a, b) 
{ 
  var sA = parseInt( a.value, 36 );  
  var sB = parseInt( b.value, 36 );  
  return sA - sB;
}

// Compare two options within a list by TEXT
function compareOptionText(a, b) 
{ 
  // Radix 10: for numeric values
  // Radix 36: for alphanumeric values
  var sA = parseInt( a.text, 36 );  
  var sB = parseInt( b.text, 36 );  
  return sA - sB;
}

//Dual list move function
function moveDualList( srcList, destList, moveAll,flag ) 
{
	// Do nothing if nothing is selected
  if (  ( srcList.selectedIndex == -1 ) && ( moveAll == false )   )
  {
    return;
  }
  newDestList = new Array( destList.options.length );
  var len = 0;
  for( len = 0; len < destList.options.length; len++ ) 
  {
    if ( destList.options[ len ] != null )
    {
      newDestList[ len ] = new Option( destList.options[ len ].text, destList.options[ len ].value, destList.options[ len ].defaultSelected, destList.options[ len ].selected );
    }
  }
  for( var i = 0; i < srcList.options.length; i++ ) 
  { 
    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )
    {
       // Statements to perform if option is selected
       // Incorporate into new list
       newDestList[ len ] = new Option( srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected );
       len++;
    }
  }
  // Sort out the new destination list
  newDestList.sort( compareOptionValues );   // BY VALUES
  // newDestList.sort( compareOptionText ); // BY TEXT
  // Populate the destination with the items from the new array
  arrNewBreed = new Array();
  for ( var j = 0; j < newDestList.length; j++ ) 
  {
    if ( newDestList[ j ] != null )
    {
      destList.options[ j ] = newDestList[ j ];
      
    }
  }
  
  // Erase source list selected elements
  for( var i = srcList.options.length - 1; i >= 0; i-- ) 
  { 
    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )
    {
       // Erase Source
       // srcList.options[i].value = "";
       // srcList.options[i].text = "";
       srcList.options[i]       = null;
    }
  }
  
  var objBreedSelected = document.getElementById('breedVO');
  var arrNewBreed = new Array();
  for(i=0;i<objBreedSelected.options.length;i++){
	  arrNewBreed[i] = objBreedSelected.options[i].value;
  }
  document.getElementById('newSelectedBreed').value = arrNewBreed;
} // End of moveDualList()


function onloadPopulateHdnBreed(oldSelectedBreedObj){
	
	breedArr = new Array(oldSelectedBreedObj.options.length);
	
	for(i=0;i<oldSelectedBreedObj.options.length;i++){
		breedArr[i] = oldSelectedBreedObj.options[i].value;
	}
	
	document.getElementById('oldSelectedBreed').value = breedArr;
	
}
