﻿var daysInMonth = makeArray(12);
	daysInMonth[1] = 31;
	daysInMonth[2] = 29;
	daysInMonth[3] = 31;
	daysInMonth[4] = 30;
	daysInMonth[5] = 31;
	daysInMonth[6] = 30;
	daysInMonth[7] = 31;
	daysInMonth[8] = 31;
	daysInMonth[9] = 30;
	daysInMonth[10] = 31;
	daysInMonth[11] = 30;
	daysInMonth[12] = 31;


// functions....
	
	function isNumeric(s)   
	{
		var i;
		for (i=0; i<s.length; i++)
		{
			var c = s.charAt(i);
			if (!isDigit(c)) return false;
		}
		return true;
	}
 	
	function isDate(month, day, year)
	{
		//if (!(isMonth(month,false)&&isDay(day,false)&&isYear(year,false)))return false;
	
		if (!(isMonth(month,false)))return false;	
		var intYear = parseInt(year);
		var intMonth = parseInt(month);
		var intDay = parseInt(day);
		
		if (intDay > daysInMonth[intMonth])return false;
		
		if ((intMonth ==2)&&(intDay>daysInFeb(intYear)))return false;
		
		if (!(isNumeric(year)&&year.length == 4))return false;
		
		return true;
	} //end of isDate function
	
	function isMonth(s)
	{
		var num = parseInt(s);
		return ((num>=1)&&(num<=12));
	}
	
	function makeArray(n)
	{
		for (var i=1; i<=n; i++)
		{
			this[i] = 0;
		}
		return this;
	} //end of makeArray function
 	
   function isDigit(c)
   {
   		return ((c>="0")&&(c<="9"));
   } //end of function
   

//<!--function validates the required input fields -->
function validate_sp()
{
	//dms - modified to work with sharepoint
	/* window.document.all does not work in firefox */
	//var x = window.document.all["firstname"];
	//var y = window.document.all["lastname"];
	//var z = window.document.all["BirthDate"];
	var x = window.document.getElementById("firstname");
	var y = window.document.getElementById("lastname");
	var z = window.document.getElementById("BirthDate");

    //if (document.voterInfo.firstname.value == "")
    if (x.value == "")
    {
        alert("El Primer Nombre es obligatorio.");
        //document.voterInfo.firstname.focus();
        x.focus();
        return false;
    }
    //else if (document.voterInfo.lastname.value == "")
    else if (y.value == "")
    {
        alert("El Apellido es obligatorio.");
        //document.voterInfo.lastname.focus();
        y.focus();
        return false;
    }
    //else if (document.voterInfo.BirthDate.value == "" || document.voterInfo.BirthDate.value == "MM/DD/YYYY")
    else if (z.value == "" || z.value == "MM/DD/YYYY")
    {
		alert("La Fecha de Nacimiento es obligatoria.");
		//document.voterInfo.BirthDate.focus();
		z.focus();
		return false;
    }
    
    //validate date  - inc67888 - 09/23/2009
    if (z.value != "" || z.value != "MM/DD/YYYY")
    {
    	if (!validateDate(z.value,'U','A'))
    	{
    		alert("Fecha de nacimiento inválida.")
    		z.focus();
    		return false;
    	}
    }
    
    return true;
}


function validatePollInfo_sp(which)
{
	var x;
	//dms - modified to work with sharepoint
	/* window.document.all does not work in firefox */
	if (which == "1")
		//x = window.document.all["precinct1"];
		x = window.document.getElementById("precinct1");
	else
		//x = window.document.all["precinct2"];
		x = window.document.getElementById("precinct2");
		
    if (x.value == "")
    {
        alert("El número del precinto es obligatorio.");
        x.focus();
        return false;
    }
    else
    {
    	if (!isNumeric(x.value) || (x.value.length != 4))
    	{
    		alert("El precinto debe ser un número de 4 dígitos.");
    		x.focus();
    		return false;
    	}
    	//return true;
    }
    return true;
}

//<!-- Begin Autotab
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);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
	return true;
}

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;
}

//<!-- This script and many more are available free online at -->
//<!-- The JavaScript Source!! http://javascript.internet.com -->
//<!-- Original:  Premshree Pillai (premshree@hotmail.com ) -->
//<!-- Web Site:  http://www.qiksearch.com -->
//<!-- Begin

window.onerror = null;
 var bName = navigator.appName;
 var bVer = parseInt(navigator.appVersion);
 var NS4 = (bName == "Netscape" && bVer >= 4);
 var IE4 = (bName == "Microsoft Internet Explorer"  && bVer >= 4);
 var NS3 = (bName == "Netscape" && bVer < 4);
 var IE3 = (bName == "Microsoft Internet Explorer"  && bVer < 4);
 var blink_speed=100;
 var i=0;
 
if (NS4 || IE4) 
{
	if (navigator.appName == "Netscape") 
	{
		layerStyleRef="layer.";
		layerRef="document.layers";
		styleSwitch="";
	}
	else
	{
		layerStyleRef="layer.style.";
		layerRef="document.all";
		styleSwitch=".style";
	}
}

//BLINKING
function Blink(layerName)
{
	if (NS4 || IE4) 
	{ 
		if(i%2==0)
		{
			eval(layerRef+'["'+layerName+'"]'+
			styleSwitch+'.visibility="visible"');
		}
		else
		{
			eval(layerRef+'["'+layerName+'"]'+
			styleSwitch+'.visibility="hidden"');
		}
	} 
	
	if(i<1)
	{
		i++;
	} 
	else
	{
		i--;
	}
	
	setTimeout("Blink('"+layerName+"')",blink_speed);
}
//  End -->



/*bring in another javascript file - part of inc67888 - 09/23/2009*/
document.write('<script type="text/javascript" src="/depts/election/_scripts/validatedate.js"></script>');

