// JavaScript Document
function Open_Agg(){
	if (window.showModalDialog) {
		window.showModalDialog("hrules.html#arriba","rules","status:no;dialogLeft:300px;dialogTop:290px;center:no;help:no;minimize:no;maximize:no;border:thin;statusbar:no;scroll:yes;dialogWidth:450px;dialogHeight:350px;unadorned=yes;");
	}else{
		window.open("hrules.html#arriba","rules","height=350,width=450left=350px,top=290px,toolbar=no,directories=no,status=no,linemenubar=no,scrollbars=yes,resizable=no,modal=yes,dialog=yes,minimizable=no");
	}
}
function GetHelpMsg(hlpmsg){
	ShowHelpMsg(true, hlpmsg);	
}
function HideHelpMsg(){
	ShowHelpMsg(false, "hlpFName");
	ShowHelpMsg(false, "hlpLName");
	ShowHelpMsg(false, "hlpEmail");
	ShowHelpMsg(false, "hlpPhone");
	ShowHelpMsg(false, "hlpFax");
	ShowHelpMsg(false, "hlpDOB");
	ShowHelpMsg(false, "hlpAdd");
	ShowHelpMsg(false, "hlpCity");
	ShowHelpMsg(false, "hlpState");
	ShowHelpMsg(false, "hlpZip");
	ShowHelpMsg(false, "hlpCountry");
	ShowHelpMsg(false, "hlpPWD1");
	ShowHelpMsg(false, "hlpPWD2");
	ShowHelpMsg(false, "hlpReferral");
	
}
function ShowHelpMsg(stat, msgname){
	aux = document.getElementById(msgname);
	if (stat == true) {
		aux.style.visibility = "visible";
	}
	else{
		aux.style.visibility = "hidden";
	}
}
function CheckMail(correo){
	val = 1;
	if ((correo == "") || (correo.indexOf('@') < 2) || (correo.lastIndexOf(".") <= (correo.indexOf("@") + 2))) { 
		val = 0;
	}
	return val;
}
function BirthCheck(){
	val = 1;
	m1 = 0;
	//var temp = new Array();
	//temp = dob.split('/');
	m =  document.getElementById("cboMonth").value;
	d =  document.getElementById("cboDay").value;
	y =  document.getElementById("cboYear").value;
	birthTime = new Date(y,m1,d);
	todaysTime = new Date();
	todaysYear = todaysTime.getYear();
	if (todaysYear < 2000) todaysYear += 1900;
		todaysMonth = todaysTime.getMonth();
		todaysDate = todaysTime.getDate();
		todaysHour = todaysTime.getHours();
		todaysMinute = todaysTime.getMinutes();
		todaysSecond = todaysTime.getSeconds();
		birthYear = birthTime.getYear();
		if (birthYear < 2000) birthYear += 1900;
		birthMonth = birthTime.getMonth();
		birthDate1 = birthTime.getDate();
		birthHour = birthTime.getHours();
		birthMinute = birthTime.getMinutes();
		birthSecond = birthTime.getSeconds();
		var monarr = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
		if (((todaysYear % 4 == 0) && (todaysYear % 100 != 0)) || (todaysYear % 400 == 0)) monarr[1] = "29";
		countMonth = monarr[todaysTime.getMonth()];
		if (todaysMinute > birthMinute) {
			diffMinute = todaysMinute - birthMinute;
			calcHour = 0;
		}
		else {
			diffMinute = todaysMinute + 60 - birthMinute;
			calcHour = -1;
		}
		if (todaysHour > birthHour) {
			diffHour = todaysHour - birthHour + calcHour;
			calcDate = 0;
		}
		else {
			diffHour = todaysHour + 24 - birthHour + calcHour;
			calcDate = -1;
		}
		if (todaysDate > birthDate1) {
			diffDate = todaysDate - birthDate1 + calcDate;
			calcMonth = 0;
		}
		else {
			diffDate = todaysDate + countMonth - birthDate1 + calcDate;
			calcMonth = -1;
		}
		if (todaysMonth > birthMonth) {
			diffMonth = todaysMonth - birthMonth + calcMonth;
			calcYear = 0;
		}
		else {
			diffMonth = todaysMonth + 12 - birthMonth + calcMonth;
			calcYear = -1;
		}
		diffYear = todaysYear - birthYear + calcYear;
		age = diffYear;
		if (age < 18) {
			alert("Error, No person under 18 years old is able to register");
			val = 0;
		}
	return val;
}
function CheckPWD1(pwd){
	val = 1;
	if ((pwd == "") || (pwd.length < 6)){
		val = 0;
	}
	return val;
}
function CheckPWD2(pwd){
	val = 1;
	//Get PWD2
	var pwd2 = document.getElementById("txtPwd2").value;
	if ((pwd2 == "") || (pwd2.length < 6)){
		val = 0;
	}
	return val;
}
function CheckPWD(pwd){
	val = 1;
	var pwd2 = document.getElementById("txtPwd2").value;
	if ((pwd != pwd2)){
		alert("Your password entries did not match")
		val = 0;
	}
	return val;
}
function CheckValSource(source){
	val = 1;
	if (source == ""){
		val = 0;
	}
	else{
		if ((source == 1) || (source == 3)){
			ref = document.getElementById("ref_friend").value;
			if (ref == ""){ 
				val = 0;
				aux = document.getElementById("ref_friend");
				aux.style.border = "2px solid #FF0000";
			}
		}
	}
	return val;
	
}
function CheckPhone(fono){
	var val = 1;
	if ((fono == "") || (fono.length < 5)){
		val = 0;
	}else{
		var ValidChars = "0123456789-";
		var Char;
		for (i = 0; i < fono.length && val == 1; i++){ 
    	  Char = fono.charAt(i); 
	      if (ValidChars.indexOf(Char) == -1){
        	 val = 0;
			}
	     }
	}
  	 return val;
}

function CheckForm(form){
	var error;
	var errorm;
	var i;
	error = 1;
	errorm = "";
	var campos = new Array("txtFName","txtLName","txtEmail","txtPhone","txtFax","txtAdd1","txtCity","txtState","txtZip","cboCountry","txtPwd1","cboSource");
	var ncampos = new Array("First Name","Last Name","Email Address","Phone","Fax","Address","City","State","Zip","Country","Password","Referral Information");
	for (i in campos){
		campo = document.getElementById(campos[i]).value;
		aux = document.getElementById(campos[i]);
		switch (campos[i]){
			case "txtEmail":
					var resp = CheckMail(campo);
					if (resp == 0) {
						error = 0; 
						aux.style.border = "2px solid #FF0000";
						campo = "";
						errorm = errorm + ncampos[i] + ", ";
					}else{
						aux.style.border = "1px solid #666666";
						errorm = errorm;
					}
			break;
			case "txtPhone":
					var resp = CheckPhone(campo);
					if (resp == 0) {
						error = 0; 
						aux.style.border = "2px solid #FF0000";
						campo = "";
						errorm = errorm + ncampos[i] + ", ";
					}else{
						aux.style.border = "1px solid #666666";
						errorm = errorm;
					}
			break;
			case "txtFax":
					var resp = CheckPhone(campo);
					if (resp == 0) {
						error = 0; 
						aux.style.border = "2px solid #FF0000";
						campo = "";
						errorm = errorm + ncampos[i] + ", ";
					}else{
						aux.style.border = "1px solid #666666";
						errorm = errorm;
					}
			break;
			case "txtPwd1":
					var resp = CheckPWD1(campo);
					var resp2 = CheckPWD2(campo);
					aux2 = document.getElementById("txtPwd2");
					if (resp == 0) {
						error = 0; 
						aux.style.border = "2px solid #FF0000";
						campo = "";
						errorm = errorm + ncampos[i] + ", ";
					}else{
						aux.style.border = "1px solid #666666";
						errorm = errorm;
					}
					if (resp2 == 0) {
						error = 0; 
						aux2.style.border = "2px solid #FF0000";
						errorm = errorm + "Confirm Password, ";
					}else{
						aux2.style.border = "1px solid #666666";
						errorm = errorm;
					}
					if ((resp == 1) && (resp2 == 1)) {
						var resp3 = CheckPWD(campo);
						if (resp3 == 0){
							error = 0; 
							aux.style.border = "2px solid #FF0000";
							aux2.style.border = "2px solid #FF0000";
							errorm = errorm + ncampos[i] + ", ";
						}else{
							aux.style.border = "1px solid #666666";
							aux2.style.border = "1px solid #666666";
							errorm = errorm;
						}
					}
			break
			case "cboCountry":
				var resp = CheckValSource(campo);
				if (resp == 0) {
						error = 0; 
						aux.style.border = "2px solid #FF0000";
						campo = "";
						errorm = errorm + ncampos[i] + ", ";
				}else{
					aux.style.border = "1px solid #666666";
					errorm = errorm;
				}
			break;
			case "cboSource":
				var resp = CheckValSource(campo);
				if (resp == 0) {
						error = 0; 
						aux.style.border = "2px solid #FF0000";
						campo = "";
						errorm = errorm + ncampos[i] + ", ";
				}else{
					aux.style.border = "1px solid #666666";
					errorm = errorm;
				}
			break;
			default:
				if (campo == ""){
					error = 0; 
					aux.style.border = "2px solid #FF0000";
					campo = "";
					errorm = errorm + ncampos[i] + ", ";
				}else{
					aux.style.border = "1px solid #666666";
					errorm = errorm;
				}
			break;
		}	
		
	}
	var DOB = new Array("cboMonth","cboDay","cboYear");
	var MSJ = new Array("Month","Day","Year");
	//var flg = new Array();
	var flg;
	i = 0
	for (i in DOB){
		campo = document.getElementById(DOB[i]).value;
		aux = document.getElementById(DOB[i]);
		if (campo == MSJ[i]){
			error = 0;
			flg = 0;
			aux.style.border = "2px solid #FF0000";
		}
		else{
			aux.style.border = "1px solid #666666";
		}
	}
	if (flg == 0){
		errorm = errorm + "Date of Birth, ";
	}
	else{
		errorm = errorm;
		var resp = BirthCheck();
		if (resp == 0){
			error = 0;
			errorm = errorm + "Date of Birth, ";
		}
	}
	if (error == 0) { 
		len = errorm.length;
		cadena = errorm.substring(0, len - 2);
		alert("The following required field(s) must be checked: "+cadena);
		return false; 
	}
  	else { 
		var check = document.getElementById("chkAgree");
		if (check.checked == false){
			check.style.border = "2px solid #FF0000"; 
			alert("In order to continue with the Registration, you must accept the Terms and Conditions.");
			return false;
		}else{
			return true;
		}
	}
	
}
function CheckSource(object){
		var1 = object.options[object.selectedIndex].value;
		aux = document.getElementById("ref_friend");
		ref = document.getElementById("ref_friend").value;
		aux2 = document.getElementById("lblAcc");
		if ((var1 == 1) || (var1 == 3)){
			aux.style.visibility = "visible";
			aux2.style.visibility = "visible";
		}else{
			document.getElementById("ref_friend").value = "";
			aux.style.visibility = "hidden";
			aux2.style.visibility = "hidden";
		}
	}
function ShowDate(mes,dia,ano,cDate){
	window.open("seldates.asp?backm="+mes+"&backd="+dia+"&backy="+ano+"&cDate="+cDate,"window","height=190,width=190,resizeable=no,toolbar=no,menubar=no,location=no,scrollbars=no,status=no,titlebar=no");

}
function Change_Style(sp){
	var i;
	for (i=1; i <= 8; i++){
		if (i != sp){ 
			aux = document.getElementById(i);
			aux.style.display = "none";
		}else{
			aux = document.getElementById(i);
			aux.style.display = "";
		}
	}
	aux = document.getElementById("bline");
	aux2 = document.getElementById("bg2");
	aux.style.display = "";
	aux2.className = "bg_td1";
	aux3 = document.getElementById("promo");
	aux3.style.display = "none";
	//aux4 = document.getElementById("promo2");
	//aux4.style.display = "none";
	//alert(sp);
	//alert(document.getElementById(HyperLink9));
	//aux2.style.background = "url(./images/bg_td.gif); background-repeat: no-repeat; background-position:bottom right;";
}
function val_log(){
	var error;
	error = "";
	user = document.getElementById("ctl00_LoginForm1__UserName");
	pwd = document.getElementById("ctl00_LoginForm1__Password");
	
	if (user.value == ""){
		error = error + " Username is a required field.\n";
	} 
	if  (pwd.value == ""){
		error = error + " Password is a required field."
	}
	if ((user.value == "") || (pwd.value == "")){
	alert(error);
	return false;
	}
}
function win(){
	var str;
	var forml;
	forml = document.aspnetForm.action;
	str = forml.substring(8, forml.length);
	str = 'http://www.betsbi.com/Print'  + str;
	window.open(str,"BetSBI","height=600,width=800,resizeable=no,toolbar=no,menubar=no,location=no,scrollbars=yes,status=no,titlebar=no");
}
function NoPrintButtons(){
	var str;
	var forml;
	forml = document.frmPrint.elements.length - 1;
	for (i=0; i<=forml; i++){
		document.frmPrint.elements[i].style.visibility = 'hidden'; 
	}
	window.print();
	for (i=0; i<=forml; i++){
		document.frmPrint.elements[i].style.visibility = 'visible'; 
	}
}
