
var activoCx='start';
var activoTempCx='start';
var activoTp='start';
var activoTempTp='start';

function imgHiTp(imgName,imgDir,imgExt) {
	if (activoTp!=imgName || activoTempTp!=imgName) {
		if (imgDir!='') {
			document[imgName].src= "images/" + imgDir + "/" + imgName + "_hi." + imgExt;
		} else {
			document[imgName].src= "images/" + imgName + "_hi." + imgExt;
		}
	}
}

function imgLowTp(imgName,imgDir,imgExt) {
	if (activoTp!=imgName || activoTempTp!=imgName) {
		if (imgDir!='') {
			document[imgName].src= "images/" + imgDir + "/" + imgName + "_lo." + imgExt;
		} else {
			document[imgName].src= "images/" + imgName + "_lo." + imgExt;
		}
	}
}

function imgHiCx(imgName,imgDir,imgExt) {
	if (activoCx!=imgName || activoTempCx!=imgName) {
		if (imgDir!='') {
			document[imgName].src= "images/" + imgDir + "/" + imgName + "_hi." + imgExt;
		} else {
			document[imgName].src= "images/" + imgName + "_hi." + imgExt;
		}
	}
}

function imgLowCx(imgName,imgDir,imgExt) {
	if (activoCx!=imgName || activoTempCx!=imgName) {
		if (imgDir!='') {
			document[imgName].src= "images/" + imgDir + "/" + imgName + "_lo." + imgExt;
		} else {
			document[imgName].src= "images/" + imgName + "_lo." + imgExt;
		}
	}
}


function imgHiBall(imgName,imgDir,imgExt) {
	if (imgDir!='') {
		document[imgName].src= "images/" + imgDir + "/" + imgName + "_hi." + imgExt;
	} else {
		document[imgName].src= "images/" + imgName + "_hi." + imgExt;
	}
}

function imgLowBall(imgName,imgDir,imgExt) {
	if (imgDir!='') {
		document[imgName].src= "images/" + imgDir + "/" + imgName + "_lo." + imgExt;
	} else {
	alert(imgName);
		document[imgName].src= "images/" + imgName + "_lo." + imgExt;
	}
}

function CheckLayer(layerName) {
	if (activoCx!=layerName || activoTempCx!=layerName || activoCx!=activoTempCx) {
		ShowLayer('layer_' + layerName);

		if (layerName=='bt_dealers' || layerName=='bt_gear') {
			if (testIsValidObject(document.getElementById('pais_dealers_id'))) {
				document.getElementById('pais_dealers_id').style.display = 'none'; //**** HIDE COMBOBOX ****
			}
			if (testIsValidObject(document.getElementById('pais_tournaments_id'))) {
				document.getElementById('pais_tournaments_id').style.display = 'none'; //**** HIDE COMBOBOX ****
			}
			if (testIsValidObject(document.getElementById('pais_teams_id'))) {
				document.getElementById('pais_teams_id').style.display = 'none'; //**** HIDE COMBOBOX ****
			}
		}

		activoCx=layerName;
	} else {
		activoCx='start';
	}
}

function ChangeState(layerName) {
	HideLayer('layer_' + activoTempCx);
	HideLayer('layercombo');

	if (layerName=='bt_dealers' || layerName=='bt_gear') {
		if (testIsValidObject(document.getElementById('pais_dealers_id'))) {
			document.getElementById('pais_dealers_id').style.display = 'block'; //**** SHOW COMBOBOX ****
		}
		if (testIsValidObject(document.getElementById('pais_tournaments_id'))) {
			document.getElementById('pais_tournaments_id').style.display = 'block'; //**** SHOW COMBOBOX ****
		}
		if (testIsValidObject(document.getElementById('pais_teams_id'))) {
			document.getElementById('pais_teams_id').style.display = 'block'; //**** SHOW COMBOBOX ****
		}
	}

	if (activoCx!='start' && activoCx!="layer_" + layerName) {;
		document[activoCx].src= "images/" + activoCx + "_lo.jpg"; // **** POE A IMAGEM A OFF ****
	}

	activoTempCx=layerName;
}

function MudarMostrarLayers(layerName) {
	ChangeState(layerName);
	CheckLayer(layerName);
}

function ShowLayer(layerName) {
	//*********** SHOW LAYER ***********
	if (navigator.appName == 'Netscape') {
		if (navigator.appVersion.substring(0, 3) == '5.0' ) {
			eval("document.getElementById('" + layerName + "').style.visibility='visible'"); // **** MOSTRA LAYER ****
		} else {
			eval("document.layers['" + layerName + "'].visibility = 'show'"); // **** MOSTRA LAYER ****
		}
	} else {
		eval("document.all['" + layerName + "'].style.visibility = 'visible'"); // **** MOSTRA LAYER ****
	}
}

function HideLayer(layerName) {
	//*********** HIDE LAYER ***********
	if (navigator.appName == 'Netscape') {
		if (navigator.appVersion.substring(0, 3) == '5.0' ) {
			eval("document.getElementById('" + layerName +"' ).style.visibility='hidden'"); // **** ESCONDE LAYER ****
		} else {
			eval("document.layers['" + layerName + "'].visibility = 'hide'"); // **** ESCONDE LAYER ****
		}
	} else {
		eval("document.all['" + layerName + "'].style.visibility = 'hidden'"); // **** ESCONDE LAYER ****
	}
}

function PopulateComboBox(layerName,comboobject,indexcombo) {
	var strOption, strOp1, strOp2, strOp3, strOp4;
	var i;
	var iIni, iIni1, iIni2, iIni3, iIni4
	var vOption;

	iIni1=0;
	strOp1="Tournament|Jersey Pro|Jersey Marshal|Pants Pro|Battlepack Pro|Gloves Pro|Barrel Sock Pro 2008|Knee Pad Pro|Elbow Pad Pro";
	iIni2=8;
	strOp2="Field Equipment|Battlepack 4 Pod|Battlepack 4 Pod Camo|Battlepack 2 Pod Leg|Full Finger Rental Gloves|Half Finger Rental Gloves|Neopren Tank Cover|Marker Bag|Retro|Field Chest Protector|Referee Chest Protector|Neck Protector";
	iIni3=19;
	strOp3="Casual|Hat|Headband|T-shirt|T-shirt Camo|T-shirt Skullz|T-shirt Draco|Hoddie Skullz|Jacket Draco";
	iIni4=27;
	strOp4="Merchandising|Key Chain|Lanyard|Stickers Sheet|Trade Stand";

	if (indexcombo==1) {
		strOption=strOp1;
		iIni=iIni1;
	}
	if (indexcombo==2) {
		strOption=strOp2;
		iIni=iIni2;
	}
	if (indexcombo==3) {
		strOption=strOp3;
		iIni=iIni3;
	}
	if (indexcombo==4) {
		strOption=strOp4;
		iIni=iIni4;
	}

	ShowLayer('layercombo');

	comboobject.options.length=0;
	for(i=0;i<strOption.split("|").length;i++) {
		vOption = strOption.split("|")[i];

		if (i==0) {
			comboobject.options[i]=new Option(vOption,0,false,false);
		} else {
			comboobject.options[i]=new Option(vOption,i+iIni,false,false);
		}
	}
}
function testIsValidObject(objToTest) {
	if (null == objToTest) {
		return false;
	}
	if ("undefined" == typeof(objToTest) ) {
		return false;
	}
	return true;
}
function ShowText(objname,strtext) {
	if (document.getElementById) {
		document.getElementById(objname).innerHTML = strtext;
	}
	else if (document.all) {
		document.all[objname].innerHTML = strtext;
	}
}

//************* VALIDATE FORMS ******************
function IsNumeric(sText) {
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
 
	for (i = 0; i < sText.length && IsNumber == true; i++) { 
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;
}
	
function isDate(dateStr, fieldName) {
	
	var datePat = /^(\d{4})(\/|-)(\d{1,2})(\/|-)(\d{1,2})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?
		
	if (matchArray == null) {
		alert("The date format in the field '" + fieldName + "' must be yyyy/mm/dd or yyyy-mm-dd.");
		return false;
	}
			
	year = matchArray[1]; // p@rse date into variables
	month = matchArray[3];
	day = matchArray[5];
		
	if (month < 1 || month > 12) { // check month range
		alert("The month of the field '" + fieldName + "' must be between 1 and 12.");
		return false;
	}
			
	if (day < 1 || day > 31) {
		alert("The day must be between 1 and 31.");
		return false;
	}
			
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("The month "+month+" doesn't have 31 days!")
		return false;
	}
			
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
			alert("February " + year + " doesn't have " + day + " dias!");
			return false;
		}
	}
	return true; // date is valid
}
	
function isEmail(argvalue) {
	if (argvalue.indexOf(" ") != -1)
		return false;
	else if (argvalue.indexOf("@") == -1)
		return false;
	else if (argvalue.indexOf("@") == 0)
		return false;
	else if (argvalue.indexOf("@") == (argvalue.length-1))
		return false;

	arrayString = argvalue.split("@");

	if (arrayString[1].indexOf(".") == -1)
		return false;
	else if (arrayString[1].indexOf(".") == 0)
		return false;
	else if (arrayString[1].charAt(arrayString[1].length-1) == ".") {
		return false;
	}
	return true;// email is valid
}
