﻿
var imgAbout_off = new Image();
	imgAbout_off.src = strWebRoot + "img/gnav/about.gif";
var imgAbout_on = new Image();
	imgAbout_on.src = strWebRoot + "img/gnav/about_f2.gif";
	
var imgRacingNews_off = new Image();
	imgRacingNews_off.src = strWebRoot + "img/gnav/racing_news.gif";
var imgRacingNews_on = new Image();
	imgRacingNews_on.src = strWebRoot + "img/gnav/racing_news_f2.gif";	
	
var imgBettorsCorner_off = new Image();
 	imgBettorsCorner_off.src = strWebRoot + "img/gnav/bettors_corner.gif";
var imgBettorsCorner_on = new Image();
 	imgBettorsCorner_on.src = strWebRoot + "img/gnav/bettors_corner_f2.gif";
	
var imgAboutRacing_off = new Image();
 	imgAboutRacing_off.src = strWebRoot + "img/gnav/about_racing.gif";
var imgAboutRacing_on = new Image();
 	imgAboutRacing_on.src = strWebRoot + "img/gnav/about_racing_f2.gif";
	
var imgFanGear_off = new Image();
	imgFanGear_off.src = strWebRoot + "img/gnav/fan_gear.gif";
var imgFanGear_on = new Image();
	imgFanGear_on.src = strWebRoot + "img/gnav/fan_gear_f2.gif";
	
var imgOddsNEnds_off = new Image();
	imgOddsNEnds_off.src = strWebRoot + "img/gnav/odds_n_ends.gif";
var imgOddsNEnds_on = new Image();
	imgOddsNEnds_on.src = strWebRoot + "img/gnav/odds_n_ends_f2.gif";


function SwapImages(){
	var Args = arguments;
	
	for (var i = 0 ; i < Args.length ; i+=2){
		document.images[ Args[i] ].src = Args[i+1].src;
	}
}


// This opens a window with given arguments
function OpenWindow(strName, intWidth, intHeight, strAttributes){
	var strAtt = "";
	
	if (strAttributes.indexOf("scroll") >= 0){
		strAtt += ",scrollbars=yes";
	}
	if (strAttributes.indexOf("status") >= 0){
		strAtt += ",status=yes";
	}
	if (strAttributes.indexOf("resize") >= 0){
		strAtt += ",resizable=yes";
	}

	var Win = window.open("", strName, "width=" + intWidth + ",height=" + intHeight + strAtt);
	
	Win.document.focus();
}



// --- BEGIN Slide Show -------------------------------------------- //

SlideShow = function(strObjName, strPath, strList, strImageName, intStart){
	this.strObjName = strObjName;
	this.strPath = strPath;
	this.strList = strList;
	this.strImageName = strImageName;
	this.intStart = intStart;
	
	this.intCurrentSlide = 0;
	
	this.arrIDs = strList.split(",");
	
	for (var i = 0 ; i < this.arrIDs.length ; i++){
		if (this.arrIDs[i] == this.intStart){
			this.intCurrentSlide = i;
		}
	}
	
	this.imgLoading = new Image();
	this.imgLoading.src = (this.strPath + "image_loading.gif");
	
	this.imgSlide = null;
}
	
SlideShow.prototype.SetNewImage = function(){
	this.imgSlide = new Image();
	this.imgSlide.src = (this.strPath + this.arrIDs[this.intCurrentSlide] + "_sm.jpg");
	
	setTimeout(this.strObjName + ".CheckLoading()", 100);
}

SlideShow.prototype.CheckLoading = function(){
	if (this.imgSlide.complete){
		document.images[ this.strImageName ].src = this.imgSlide.src;
	} else {
		document.images[ this.strImageName ].src = this.imgLoading.src;
		setTimeout(this.strObjName + ".CheckLoading()", 100);
	}
}

SlideShow.prototype.Next = function(){
	this.intCurrentSlide++;
	
	if (this.intCurrentSlide >= this.arrIDs.length){
		this.intCurrentSlide = 0;
	}
	
	this.SetNewImage();
}

SlideShow.prototype.Prev = function(){
	this.intCurrentSlide--;
	
	if (this.intCurrentSlide < 0){
		this.intCurrentSlide = (this.arrIDs.length - 1);
	}
	
	this.SetNewImage();
}	

SlideShow.prototype.HiRes = function(){
	var Win = window.open(this.strPath + this.arrIDs[this.intCurrentSlide] + "_lg.jpg");
}

SlideShow.prototype.Thumb = function(){
	var strURL = (location.href.split("#"))[0];
	
	location.href = (strURL + "#thumb" + this.arrIDs[this.intCurrentSlide]);
}

// --- END Slide Show ---------------------------------------------- //


function ValidateForm(objForm){
	var blnValid = true;
	var objInput = null;
	var objCheckbox = null;
	var objSelect = null;
	var strErrors = "";
	var arrSubmits = new Array();
		
	for (var i = 0 ; i < objForm.elements.length ; i++){
		// Get current element
		objInput = objForm.elements[i];
		
		// Check to see if the getAttribute exists
		if (objInput.getAttribute){
			// Check for submit button
			if (objInput.getAttribute("type") == "submit"){
				arrSubmits[arrSubmits.length] = i;
				objInput.disabled = true;
			}
		
			if (objInput.getAttribute("required") == "1"){
				// Check to see which type of validation
				switch(objInput.getAttribute("validation")){
					case "NOTNULL":
						if (objInput.value == ""){
							strErrors += (objInput.getAttribute("error") + "\n");
							blnValid = false;
							ValidateForm_ShowError(objInput);
						} else {
							ValidateForm_HideError(objInput);
						}
						break;
				}
				
			} else if (objInput.getAttribute("requiredifnotchecked") != null){
				objCheckbox = objInput.form.elements[objInput.getAttribute("requiredifnotchecked")];
				
				if (!objCheckbox.checked){
					// Check to see which type of validation
					switch(objInput.getAttribute("validation")){
						case "NOTNULL":
							if (objInput.value == ""){
								strErrors += (objInput.getAttribute("error") + "\n");
								blnValid = false;
								ValidateForm_ShowError(objInput);
							} else {
								ValidateForm_HideError(objInput);
							}
							break;
					}
				}				
			
			} else if (objInput.getAttribute("requiredifnotselected") != null){
				objSelect = objInput.form.elements[objInput.getAttribute("requiredifnotselected")];
				
				if ((objSelect.value == "0") || (objSelect.value == "")){
					// Check to see which type of validation
					switch(objInput.getAttribute("validation")){
						case "NOTNULL":
							if (objInput.value == ""){
								strErrors += (objInput.getAttribute("error") + "\n");
								blnValid = false;
								ValidateForm_ShowError(objInput);
							} else {
								ValidateForm_HideError(objInput);
							}
							break;
					}
				}			
			}
			
		}		
	}
	
	if (strErrors.length > 0){
		alert(strErrors);
	}
	
	if (!blnValid){
		for (var i = 0 ; i < arrSubmits.length ; i++){
			objForm.elements[arrSubmits[i]].disabled = false;
		}
	}
	
	return(blnValid);	
}

function ValidateForm_HideError(objInput){
	objInput.runtimeStyle.backgroundColor = "";
}

function ValidateForm_ShowError(objInput){
	objInput.runtimeStyle.backgroundColor = "#FFDDDD";
}

// --- END Form Validation ----------------------------------------- //


