// JavaScript Document

function MM_openBrWindow(theURL,winName,features) { //v2.0
  NewWindow=window.open(theURL,winName,features);
  NewWindow.focus()
}

function hidetext() {
  if (!document.getElementById) {
  
  alert('This link will not work in your browser')
  
  }
  
  
  var secretObj = document.getElementById("hidden");  

  if (secretObj.style.display == "block") {
    secretObj.style.display = "none";
  } else {
    secretObj.style.display = "block";
  }   
}

function chgImg(imgField,newImg) {
	if (document.images) {
		document[imgField].src= eval(newImg + ".src")
	}
}	
function OpenWin(url) {
		NewWindow = window.open(url,'results','resizable,width=350,height=510,left=0,top=0')
	
		NewWindow.focus()
	}
	
function OpenWinwide(url) {
		NewWindow1 = window.open(url,'results01','resizable,width=510,height=388,left=0,top=0')
	
		NewWindow1.focus()
	}
	
function OpenResultsWindow(url) {
		NewWindow1 = window.open(url,'results01','resizable,scrollbars,width=620,height=550,left=0,top=0')
	
		NewWindow1.focus()
	}

function pgwin(url) {
		NewWindow1 = window.open(url,'results','resizable,scrollbars,width=480,height=550,left=0,top=0')
	
		NewWindow1.focus()
	}
	
function jumpPage(newLoc) {

		newPage= newLoc.options[newLoc.selectedIndex].value

		if(newPage !="") {
		window.location.href = newPage

		}
	}


// end hiding script from old browsers -->

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.01
  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 && d.getElementById) x=d.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];}
}


// START Submit FOX TV Airtimes Form

var iButton, isSubmitting
function SubmitIronPointFormTv()
{ 
	if (iButton)
	{
		if (isSubmitting != true)
		{
			var iAction, iMethod
			iAction='http://msn.foxsports.com/tv/schedule';
			iMethod='POST';
			iTarget='_blank';
			if (iButton == 1)
			{	
				//document.getElementById('region2').name='xxx';
				//document.getElementById('date2').name='xxx';
				return DoIronPointFormSubmit(iAction, iMethod, iTarget);
			}
			else if (iButton == 2)
			{
				document.getElementById('region').value='';
				document.getElementById('date').value='';
				document.getElementById('region').name='regionCategoryId1';
				document.getElementById('date').name='date1';
				document.getElementById('region2').name='regionCategoryId';
				document.getElementById('date2').name='date';
				return DoIronPointFormSubmit(iAction, iMethod, iTarget);
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
};

function DoIronPointFormSubmit(iAction, iMethod, iTarget)
{
	if (isSubmitting != true)
	{
		if (document.forms[0].__VIEWSTATE != null) 
		{
			document.forms[0].__VIEWSTATE.value='NOVIEWSTATE';
		}
		document.forms.item('IronPointForm').method=iMethod;
		document.forms.item('IronPointForm').action=iAction;
		isSubmitting = true;
		document.forms.item('IronPointForm').target=iTarget; 				
		document.forms.item('IronPointForm').submit(); 
		return true;
	}
	else
	{
		return false;
	}
}

// END Submit FOX TV Airtimes Form


function validEmail(email) {
			invalidChars = " /:,;"
	
			for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
				badChar = invalidChars.charAt(i)
				if (email.indexOf(badChar,0) > -1) {
					return false
				}
			}
			atPos = email.indexOf("@",1)			// there must be one "@" symbol
			if (atPos == -1) {
				return false
			}
			if (email.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
				return false
			}
			periodPos = email.indexOf(".",atPos)
			if (periodPos == -1) {					// and at least one "." after the "@"
				return false
			}
			if (periodPos+3 > email.length)	{		// must be at least 2 characters after the "."
				return false
			}
			return true
		}
function isNum(value) {

for (i=0; i<value.length; i++) {
	if (value.charAt(i) < "0") { return false; }
	if (value.charAt(i) > "9") { return false; }
}	

return true;

}

function validateEmail(theForm) {
	
	var emailValue = theForm.from.value;
	if (!emailValue) {
		alert ('You must enter an email address');
		theForm.from.focus();
		return false;
	}
	if (!validEmail(emailValue)) {
		alert('' + emailValue + ' is not a valid email address');
		theForm.from.focus();
		return false;
	}
}

function validateForm(theForm)
{
	var race = theForm.race.value;
	var from = theForm.from.value;
	var phone = theForm.phone.value;
	var phoneLength = theForm.phone.value.length;
	var department = theForm.department.value;
	var message = theForm.message.value;
	
	//alert ('Phone Length = ' + phoneLength + '');
	
	// Start ------->

	if (race == "#") {
		alert('Please choose an Event');
		theForm.race.focus();
		return false;
	}

	if (department == "#") {
		alert('Please choose a category');
		theForm.department.focus();
		return false;
	}
	
	if (phone == "") {
		alert('Please enter a valid phone number so we may contact you\nin case we have any questions');
		theForm.phone.focus();
		return false;
	}
	

	if (!from == "") {
		if (!validEmail(from)) {
			alert('' + from + ' is not a valid email address');
			theForm.from.focus();
			return false;
		}
	}
	if (!phone == "") {
		if ((!isNum(phone)) || (phoneLength != 10)) {
			alert('' + phone + ' is not a valid phone number\nPlease enter a 10-digit nubmer without spaces');
			theForm.phone.focus();
			return false;
		}
	
	}
	
	if (message == "") {
		alert('Please enter your question');
		theForm.message.focus();
		return false;
	}	
	
	return true;
}
