var appName = navigator.appName ;

{		mydate = new Date();
		year = mydate.getYear();
		if (year < 2000)    
        	year = year + 1900; 
		arday = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
		armonth = new Array("January ","February ","March ","April ","May ","June ","July ","August ","September ", "October ","November ","December ")
		ardate = new Array("0th","1st","2nd","3rd","4th","5th","6th","7th","8th","9th","10th","11th","12th","13th","14th","15th","16th","17th","18th","19th","20th","21st","22nd","23rd","24th","25th","26th","27th","28th","29th","30th","31st");
		var pagetime = ("<b>" + arday[mydate.getDay()] +"</b>"+", " + armonth[mydate.getMonth()] +" "+ardate[mydate.getDate()] + ", " + year);
		var pageyear = year;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
//TODO: Don Add all functions below this point to keep them separated from Jesse's.//
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////

function SetText(obj1, obj2)
{
	obj2.value = obj1.value;
}

function isValidDate(strDate) {

	var regDay 		= "(0?[1-9]|[12][0-9]|3[01])";
	var regMonth	= "(0?[1-9]|1[0-2])";
	var regYear		= "(20[0-9]{2}|[1-9]{2}[0-9]{2})"
	var regSep		= "[\/-]"
	var regPlus		= "+"
	
	var regDate 	= "^(0?[1-9]|1[0-2])+[\/-]+(0?[1-9]|[12][0-9]|3[01])[\/-](20[0-9]{2}|[1-9]{2}[0-9]{2})$"
	
	var Reg1 = "^" + regMonth + regPlus + regSep + regPlus + regDay + regSep + regYear + "$"
	return strDate.match(regDate);
}

function ProcessClick(obj)
{
	document.location.href=obj.value;
}

function Update()
{
	var bChecked = false;
	if (frm.txtEnable) frm.txtEnable.value = ""
	if (frm.txtDelete) frm.txtDelete.value = ""
	
	if (frm.txtEnable)
	{
		for (var i = 1; i < frm.chkEnable.length; i++) 
		{
			if (frm.chkEnable[i].checked) 
			{
				frm.txtEnable.value += frm.chkEnable[i].value + "|";
				bChecked = true;
				if (frm.txtSponsor)
				{
					frm.txtSponsor.value += frm.optSponsor[i].value + "|";
				}
			}
		}
	}
	if (frm.txtDelete)
	{
		for (var i = 1; i < frm.chkDelete.length; i++) 
		{
			if (frm.chkDelete[i].checked) 
			{
				frm.txtDelete.value += frm.chkDelete[i].value + "|";
				bChecked = true;
			}
		}
	}
	if (bChecked)
		document.frm.submit();
	else
		return false;
}

function SetObject(obj1, obj2)
{
	if (obj1.checked)	
		obj2.value = "True";
	else
		obj2.value = "False";
}

function checkBoxChanged(obj1, obj2)
{
	if (obj1.checked)
		obj2.disabled = false;
	else
		obj2.disabled = true;
}

function checkClearCombo(obj1, obj2, obj3)
{
	if (!obj1.checked)
	{
		obj2.value = "";
		obj3.value = "";
	}
}


function SetMonth(cboDay, cboMonth, cboYear, txtDay)
{
	if (appName != "Microsoft Internet Explorer")
		return;
		

	var iNumElements = parseInt(cboDay.length, 10);
	var iSelectedMonth = cboMonth.value;
	var iSelectedYear = cboYear.value;
	var iSelectedDay = cboDay.selectedIndex;
	var iIndex;
	switch (iSelectedMonth )
	{
		case "01":
		case "03":
		case "05":
		case "07":
		case "08":
		case "10":
		case "12":
			for (iIndex = iNumElements; iIndex < 32; iIndex++)
			{
				cboDay.options[iIndex] = new Option(iIndex ,iIndex)
			}
			break;
		case "04":
		case "06":
		case "09":
		case "11":
			if (iNumElements < 31)
			{
				for (iIndex = iNumElements; iIndex < 31; iIndex++)
				{
					cboDay.options[iIndex] = new Option(iIndex ,iIndex)
				}
			}
			else if (iNumElements > 31)
			{
				cboDay.options.remove(31);
			}
			break;
		case "02":
			var iMakeMonth = 28;
			if (eval(iSelectedYear) != undefined)
			{
				iSelectedYear = parseInt(iSelectedYear, 10);
				if ((iSelectedYear % 4) == 0)
					iMakeMonth = 29;
			}
			if (iNumElements == iMakeMonth + 1)
				return;
			if (iNumElements > iMakeMonth + 1)
			{
				for (iIndex = iMakeMonth+1; iIndex < iNumElements; iIndex++)
				{
					cboDay.options.remove(iMakeMonth+1);
				}
			}
			else
			{
				for (iIndex = iNumElements; iIndex < iMakeMonth+1; iIndex++)
				{
					cboDay.options[iIndex] = new Option(iIndex ,iIndex)
				}
			}
			break;		
	}
	if (iSelectedDay > cboDay.length)
		cboDay.selectedIndex = 0;
}

function isYearling(month, day, year, yearlingStartDate, yearlingEndDate)
{
	var alpacaDate = new Date(year, month-1, day);
	var startDate = new Date(yearlingStartDate);
	var endDate = new Date(yearlingEndDate);
	
	if ((alpacaDate <= endDate) && (alpacaDate >= startDate))
	{
//		alert("the alpaca is a yearling");
		return true;
	}
//	alert("the alpaca is not a yearling");	
	return false;
}

function isTooYoung(month, day, year, cutOffDate)
{
	if (month.length == 0 || day.length == 0 || year.length == 0)
		return false;
	var alpacaDate = new Date(year, month-1, day);
	var endDate = new Date(cutOffDate);
	//alert("alpacaDate: " + alpacaDate + "\nendDate: " + endDate);
	
	if ((alpacaDate <= endDate))
	{
//		alert("the alpaca is old enough");
		return false;
	}
//	alert("the alpaca is not old enough");
	return true;
}

function isYearling2(month, day, year, yearlingStartDate, yearlingEndDate)
{
	if (month.length == 0) return 2;
	if (day.length == 0) return 2;
	if (year.length == 0) return 2;
	
	var alpacaDate = new Date(year, month-1, day);
	var startDate = new Date(yearlingStartDate);
	var endDate = new Date(yearlingEndDate);
	
	if ((alpacaDate <= endDate) && (alpacaDate >= startDate))
	{
//		alert("the alpaca is a yearling");
		return 0;
	}
//	alert("the alpaca is not a yearling");	
	return 1;
}

function isBreedSet(strBreed)
{
	if (strBreed == "S")
		return 0;
	if (strBreed == "H")
		return 1;
	
	return 2;	
}

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
else // otherwise, update 'characters left' counter
	countfield.value = maxlimit - field.value.length;
}

function checkCC(s) {

	if (s == "4111111111111111")
	{
		return true;
	}
  var i, n, c, r, t;

  // First, reverse the string and remove any non-numeric characters.
  r = "";
  for (i = 0; i < s.length; i++) {
    c = parseInt(s.charAt(i), 10);
    if (c >= 0 && c <= 9)  r = c + r;
  }

  // Check for a bad string.
  if (r.length <= 1)   return false;

  // Now run through each single digit to create a new string. Even digits
  // are multiplied by two, odd digits are left alone.
  t = "";
  for (i = 0; i < r.length; i++) {
    c = parseInt(r.charAt(i), 10);
    if (i % 2 != 0)  c *= 2;
    t = t + c;
  }

  // Finally, add up all the single digits in this string.
  n = 0;
  for (i = 0; i < t.length; i++) {
    c = parseInt(t.charAt(i), 10);
    n = n + c;
  }

  // If the resulting sum is an even multiple of ten (but not zero), the
  // card number is good.
  if (n != 0 && n % 10 == 0)    return true;
  else						    return false;
}

var m_pWindow=null;
var m_pWindow2=null;
function popWin(bm)	{
	var w = 625;
	var h = 600;
	
	var strFlags = "scrollbars=yes,nostatus,resizable=yes,width=" + w.toString(10) + ",height=" +h.toString(10) + ",top=10,left=10"
	var strURL = "help.asp#" + bm;
	m_pWindow = open(strURL,"windowName",strFlags);
	m_pWindow.focus();
}
function popWinCounty()	{
	var w = 550;
	var h = 800;
	
	var strFlags = "scrollbars=yes,status,resizable=yes,width=" + w.toString(10) + ",height=" +h.toString(10) + ",top=10,left=10"
	var strURL = "NYCounties.htm";
	m_pWindow2 = open(strURL,"windowName",strFlags);
}

function popWindow(strURL, w, h)	{
	
	var strFlags = "scrollbars=yes,nostatus,resizable=yes,width=" + w.toString(10) + ",height=" +h.toString(10) + ",top=10,left=10"
	m_pWindow2 = window.open(strURL,"windowName",strFlags);
	m_pWindow2.focus()
}


function swapimage(obj, imgURL)
{
	document.getElementById(obj).src = imgURL;
}

function myInnerText(obj, textToWrite)
{
	if (!obj)
		return;
	if (document.all) 
	{ // IE;
		obj.innerText = textToWrite;
	}
	else
	{
		if (obj.textContent)
		{
			obj.textContent = textToWrite;
		}
	}
}

function popSurvWin()	{
	var w = 780;
	var h = 800;
	
	var strFlags = "scrollbars=yes,nostatus,resizable=yes,width=" + w.toString(10) + ",height=" +h.toString(10) + ",top=10,left=10"
	var strURL = "http://www.surveymonkey.com/s.asp?u=717253340504";
	m_pWindow = open(strURL,"windowName",strFlags);
	m_pWindow.focus();
	if (!m_pWindow)
	{
		alert("Please turn your popup blocker off and try again.");
	}
}
function ToggleObject(obj1, obj2)
{
	if (obj1.checked)
	{
		obj2.checked = false;
		var txtObj = "txt" + obj2.name.substring(3);
		SetObject(obj2, document.getElementById(txtObj));
	}
}

function SetFleeceCatCombo(month, day, year, yearlingStartDate, yearlingEndDate, strBreed, objFC, bHalterShorn, bHalterFullFleece, bFleeceShow, strEmptyText, bDiplayFleeceShowOption)
{
	var iYearling = isYearling2(month, day, year, yearlingStartDate, yearlingEndDate);
	var iBreed = isBreedSet(strBreed);
//	alert(iBreed + " " + iYearling);
	SetFleeceCombo(iYearling, iBreed, objFC, bHalterShorn, bHalterFullFleece, bFleeceShow, strEmptyText, bDiplayFleeceShowOption)	
}

function SetFleeceCombo(iYearling, iBreed, objFC, bHS, bHFF, bFL, strEmptyText, bDiplayFleeceShowOption)
{
	var fleeceCat = objFC.value;
	var options = objFC.options;
	var iIndex = 0;
	
	for (i = options.length-1; i >= 0; i--) 
	{
		options[i] = null;
	}
	if (iYearling ==2 || iBreed == 2)
	{
		options[iIndex] = new Option(strEmptyText);
		options[iIndex].value = ""
		objFC.selectedIndex = 0;
	}
	else
	{
		options[iIndex] = new Option("--Fleece Category--");
		options[iIndex++].value = ""
		if (bHS)
		{
			options[iIndex] = new Option("Shorn");
			options[iIndex++].value = "SH";
		}
		if (bHFF)
		{
			if (iYearling == 0 && iBreed == 0)
			{
				options[iIndex] = new Option("Full Fleece (3\" - 8\")");
				options[iIndex++].value = "FF3";
				options[iIndex] = new Option("Full Fleece (8\"+)");
				options[iIndex++].value = "FF8"
			}
			else
			{
				options[iIndex] = new Option("Full Fleece");
				options[iIndex++].value = "FF";
			}			
		}
		if (bFL && bDiplayFleeceShowOption)
		{
			options[iIndex] = new Option("Fleece Show");
			options[iIndex++].value = "FL";
		}
	}
	objFC.value = fleeceCat;
	if (objFC.selectedIndex == -1)
	{
		objFC.selectedIndex = 0;
	}
}

function isBreed(objBreed)
{
	if (objBreed.value == "")
	{
		return 2;
	}
	else if (objBreed.value == "S")
	{
		return 0;
	}
	return 1;
}
function isYearling3(objAge)
{
	if (objAge.value == "")
	{
		return 2;
	}
	else if (objAge.value == "Y")
	{
		return 0;
	}
	return 1;
}


function CheckCCData()
{
	var strMsg = "";
	if (document.getElementById("card-name").value == "")	strMsg += "Name on credit card\n";
	if (document.getElementById("card-number").value == "")	strMsg += "Credit card number\n";
	if (document.getElementById("card-type").value == "")		strMsg += "Credit card type\n";
//	if (document.getElementById("card-cvv").value == "")		strMsg += "Security Code\n";
	if (document.getElementById("month-exp").value == "" || document.getElementById("year-exp").value == "")	strMsg += "Expiration Date";

	if (strMsg != "")	{	
		alert("The following values need to be entered before continuing:\n\n" + strMsg);	
		return false;	
	}
	if (!checkCC(document.getElementById("card-number").value)){
		alert("The credit card number you entered does is not valid.\nPlease check the number and make the necessary correction");	
		return false;	
	}
	var iMonth = document.getElementById("month-exp").value;
	var iYear = document.getElementById("year-exp").value;
	var iDay;
	switch (iMonth)
	{
		case "02":
			iDay = 28;
			break;
		case "04":
		case "06":
		case "09":
		case "11":
			iDay = 30;	
			break;
		default:
			iDay = 31;
	}
	var iDate = iMonth + "/" + iDay + "/20" + iYear;
	var mDate = new Date(iDate);
	var mNowDate = new Date();
	
	if (mDate < mNowDate)
	{
		alert("Unable to use the credit card. The date has expired.");
		return false;	
	}
	//document.getElementById("btnNext").enabled = false;
	return true;
}

function SyncComboAndText(cboName, txtName)
{
	var strValue = document.getElementById(cboName).value;
	if (strValue != document.getElementById(txtName).value)
	{
		document.getElementById(txtName).value = strValue;
	}
}

