var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function 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 && !containsElement(filter,keyCode)) 
    {
        input.value = input.value.slice(0, len);
		theItem = (getIndex(input)+1) % input.form.length;
		if (!input.form[theItem].disabled) input.form[theItem].focus();
    }
    function containsElement(arr, ele) 
    {
        var found = false, index = 0;
        while(!found && index < arr.length)
            if(arr[index] == ele)
                found = true;
            else
                index++;
        return found;
    }
    function 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;
}


function confirm_delete()
{
  if (confirm("Are you sure you want to delete these loan details?")==true)
    return true;
  else
    return false;
}

/////
// Holder populate
/////
function addSelectedItemsToParent()
{
    self.opener.addToParentList(window.document.forms[0].destList);
    window.close();
}

// Fill the selcted item list with the items already present in parent.
function fillInitialDestList()
{
    var destList = window.document.forms[0].destList; 
    var srcList = self.opener.window.document.forms[0].parentList;
    for (var count = destList.options.length - 1; count >= 0; count--)
    {
        destList.options[count] = null;
    }

    for(var i = 0; i < srcList.options.length; i++)
    { 
        if (srcList.options[i] != null)
            destList.options[i] = new Option(srcList.options[i].text);
   }
}

// Add the selected items from the source to destination list
function addSrcToDestList()
{
    destList = window.document.forms[0].destList;
    srcList = window.document.forms[0].srcList; 
    var len = destList.length;
    for(var i = 0; i < srcList.length; i++)
    {
        if ((srcList.options[i] != null) && (srcList.options[i].selected))
        {
            //Check if this value already exist in the destList or not
            //if not then add it otherwise do not add it.
            var found = false;
            for(var count = 0; count < len; count++)
            {
                if (destList.options[count] != null)
                {
                    if (srcList.options[i].text == destList.options[count].text)
                    {
                        found = true;
                        break;
                    }
               }
        }
        
        if (found != true)
        {
            destList.options[len] = new Option(srcList.options[i].text); 
            len++;
        }
      }
   }
}

// Deletes from the destination list.
function deleteFromDestList()
{
    var destList  = window.document.forms[0].destList;
    var len = destList.options.length;
    for(var i = (len-1); i >= 0; i--)
    {
        if ((destList.options[i] != null) && (destList.options[i].selected == true))
        {
            destList.options[i] = null;
        }
   }
}

function holder_code_window()
{
    var newWindow;
    var props = 'scrollBars=yes,resizable=yes,toolbar=no,menubar=no,location=no,directories=no,width=400,height=400';
    newWindow = window.open("InstitutionSelector.jsp", "Add_from_Src_to_Dest", props);
}

// Creates a popup window with specified 
// dimensions


function popHelpScreen(url,height)
{
	popup(url, 730, height);
}

function popup(url, width, height)
{
	options = "menubar=no, status=no, titlebar=no, width="+width+", height="+height;
	window.open(url,"_blank",options,false);
}

 function SetCookie(cookieName,cookieValue,nHours) {
                // var today = new Date();
                 //var expire = new Date();
                 try {
                        // if (nHours==null || nHours==0) nHours=1;
                        // expire.setTime(today.getTime() + 3600000*nHours);
                         document.cookie = cookieName+"="+escape(cookieValue);
                     } catch (e) {
                       // Non persistant cookie
                     }
            }// SetCookie
            
    function SetCulture(culture) {
				SetCookie("uiCulture", culture, 1)       
          }
                
// Custom Validator for CreateAccount2 only
function CheckBoxIsChecked(source, args)
    {  // Is agree checked?
		  var oSource = source;
			var oArgs = args; 
       args.IsValid = document.getElementById("ctl00_cpMain_ctl00_chkAgree").checked;
    }
// Custom Validator for CreateAccount only
function CheckDOB(source, args)
    {  // Is agree checked?
		  var oSource = source;
			var oArgs = args;                                            
       //var oDOBMonth = document.forms[0].elements['<%=tbDOBMonth%>'];
       //var oDOBDay = document.forms[0].elements['<%=tbDOBDay%>'];
       //var oDOBYear = document.forms[0].elements['<%=tbDOBYear%>'];
       var oDOBMonth = document.getElementById("ctl00_cpMain_ctl00_tbDOBMonth")
       var oDOBDay = document.getElementById("ctl00_cpMain_ctl00_tbDOBDay")
       var oDOBYear = document.getElementById("ctl00_cpMain_ctl00_tbDOBYear")
       
       if (oDOBMonth.value.length == 0)
       {
       		 args.IsValid = false;
       }
       else if  (oDOBDay.value.length == 0)
            {
              		 args.IsValid = false; 		 
      		 }
      		 else if  (oDOBYear.value.length < 4)
					{
		  		   args.IsValid = false;  
      		 }
      		 else
      		 {
      		  	return args.IsValid = true;
      		}
    }

// Check that a string contains only letters and numbers
function isAlphanumeric(string, ignoreWhiteSpace) {
   if (string.search) {
      if ((ignoreWhiteSpace && string.search(/[^\w\s]/) != -1) || (!ignoreWhiteSpace && string.search(/\W/) != -1)) return false;
   }
   return true;
}

// Check that a string contains only letters
function isAlphabetic(string, ignoreWhiteSpace) {
   if (string.search) {
      if ((ignoreWhiteSpace && string.search(/[^a-zA-Z\s]/) != -1) || (!ignoreWhiteSpace && string.search(/[^a-zA-Z]/) != -1)) return false;
   }
   return true;
}

// Check that a string contains only numbers
function isNumeric(string, ignoreWhiteSpace) {
   if (string.search) {
      if ((ignoreWhiteSpace && string.search(/[^\d\s]/) != -1) || (!ignoreWhiteSpace && string.search(/\D/) != -1)) return false;
   }
   return true;
}
