/****************************************************************/ 
/* A L L T E L    C O P Y R I G H T    S T A T E M E N T        */ 
/****************************************************************/ 
/*                                                              */ 
/*  NOTICE: THIS SOFTWARE CONTAINS TRADE SECRETS THAT BELONG TO */ 
/*          ALLTEL COMMUNICATIONS, INC. AND IS LICENSED         */ 
/*          BY AN AGREEMENT.  ANY UNAUTHORIZED ACCESS, USE,     */ 
/*          DUPLICATION OR DISCLOSURE IS UNLAWFUL.              */ 
/*                                                              */ 
/*  COPYRIGHT (C) 2007 ALLTEL COMMUNICATIONS, INC.              */ 
/*  ALL RIGHTS RESERVED.                                        */ 
/****************************************************************/ 
/** 
/ * Revision History: 
/ * 03/26/2007   N9913589        Initial version. 
/ */

 function validateGiftForm(thisObj, thisEvent, namespace)
{
	var portletNamespaceForView='view'+ namespace;
	var serialNumber=document.getElementById(portletNamespaceForView+':GiftCardInfo:serialNumber').value;
    var pin=document.getElementById(portletNamespaceForView+':GiftCardInfo:pin').value;
	if(validSerialNumber(serialNumber))
	{
    }
	else
	{
       return false; 
    } 
   
   if(validPIN(pin))
		return true;
	else
		return false; 

  return true; 
}
 
function validSerialNumber(field)
{
   var temp;
   var validData = "0123456789"; 
   var valid = true;
		
      if(field.length==0 || field.length<16){
         alert("The Gift Card Number must be 16 digits long.");
		return false; 
   }
     
   for (var i=0; i<field.length; i++)
   {
	  temp = "" + field.substring(i, i+1);
	  if (validData.indexOf(temp) == "-1") 
	  valid= false;	   
   }

   if(valid == false)
   {
       alert("The Gift Card Number must contain only digits.");
       return false; 
    } 
   return true; 
}

function validPIN(field) 
{
	var temp;
	var validData = "0123456789"; 
	var valid = true;
	
	if (field.length==0 || field.length<6)
	{
		alert("The PIN must be 6 digits long.");
		return false; 
	}

	for (var i=0; i<field.length; i++)
	{
		temp = "" + field.substring(i, i+1);
		if (validData.indexOf(temp) == "-1") valid= false;	   
	}

	if (valid == false)
	{
		alert("PIN must contain only digits.");
		return false; 
	} 
	return true;        
} 
 
/** 
 *	This method is used to move the focus to the next field.
 */

var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function func_autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode;
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !func_containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
	input.form[(func_getIndex(input)+1) % input.form.length].focus();
}

function func_containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
		if(arr[index] == ele)
			found = true;
		else
			index++;
	return found;
}

function func_getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
		if (input.form[i] == input)
			index = i;
		else
			i++;
		return index;
	}
	return true;
}
 
