//************ Check Alias Availability ***********//
var xmlHttp // xmlHttp variable
	function GetXmlHttpObject()
	{
		// This function we will use to call our xmlhttpobject.
		var objXMLHttp = null // Sets objXMLHttp to null as default.
		if (window.XMLHttpRequest)
		{
			// If we are using Netscape or any other browser than IE lets use xmlhttp.
			objXMLHttp = new XMLHttpRequest() // Creates a xmlhttp request.
		}
		else if (window.ActiveXObject)
		{
			// ElseIf we are using IE lets use Active X.
			objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP") // Creates a new Active X Object.
		}
		// End ElseIf.
		return objXMLHttp // Returns the xhttp object.
	}
	// Close Function
	//Validate Email --START
	function CheckEmail(email_address)
	{
		// This function we will use to check to see if a username is taken or not.
		xmlHttp = GetXmlHttpObject() // Creates a new Xmlhttp object.
		if (xmlHttp == null)
		{
			// If it cannot create a new Xmlhttp object.
			alert ("Browser does not support HTTP Request") // Alert Them!
			return // Returns.
		}
		// End If.
		var url = "/checkuser.php?email_address=" + email_address // Url that we will use to check the username.
		xmlHttp.open("GET", url, true) // Opens the URL using GET
		xmlHttp.onreadystatechange = function () 
		{
			// This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.
			if (xmlHttp.readyState == 4) 
			{
				// If the onreadystatechange is equal to 4 lets show the response text.
				document.getElementById("checkEmail").innerHTML = xmlHttp.responseText;
				// Updates the div with the response text from check.php
			}
			// End If.
		};
		// Close Function
		xmlHttp.send(null);
		// Sends NULL instead of sending data.
	}
	//Validate Email -- END
	function CheckUsername(username)
	{
		// This function we will use to check to see if a username is taken or not.
		xmlHttp = GetXmlHttpObject() // Creates a new Xmlhttp object.
		if (xmlHttp == null)
		{
			// If it cannot create a new Xmlhttp object.
			alert ("Browser does not support HTTP Request") // Alert Them!
			return // Returns.
		}
		// End If.
		var url = "/checkuser.php?username=" + username // Url that we will use to check the username.
		xmlHttp.open("GET", url, true) // Opens the URL using GET
		xmlHttp.onreadystatechange = function () 
		{
			// This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.
			if (xmlHttp.readyState == 4) 
			{
				// If the onreadystatechange is equal to 4 lets show the response text.
				document.getElementById("checkalias").innerHTML = xmlHttp.responseText;
				// Updates the div with the response text from check.php
			}
			// End If.
		};
		// Close Function
		xmlHttp.send(null);
		// Sends NULL instead of sending data.
	}
	
//************ Check Alias Availability ***********//

function validateProfile()
{
	var firstname = window.document.editprofile.firstname.value;
	var lastname = window.document.editprofile.lastname.value;
	var bmon = window.document.editprofile.bmon.value;
	var byear = window.document.editprofile.byear.value;
	var bday = window.document.editprofile.bday.value;
	var address = window.document.editprofile.address.value;
	var city = window.document.editprofile.city.value;
	var country = window.document.editprofile.country.value;
	var zip = window.document.editprofile.zip.value;
	var phone = window.document.editprofile.phone.value;
	
	var myRegxp = /[0-9]/;
	var myRegxpPhone = /[A-Za-z]/;
	if(firstname == "")
	{
		alert(" First Name can't be Blank");
		window.document.editprofile.firstname.focus();
		return false;
	}
	if(lastname == "")
	{
		alert("Last Name can't be Blank");
		window.document.editprofile.lastname.focus();
		return false;
	}
	if(bmon == "" || byear =="" || bday == "")
	{
		alert("Please Enter Date of Birth");
		window.document.editprofile.bmon.focus();
		return false;
	}
	if(address == "")
	{
		alert("Address can't be Blank");
		window.document.editprofile.address.focus();
		return false;
	}
	if(city == "")
	{
		alert("City can't be Blank");
		window.document.editprofile.city.focus();
		return false;
	}
	if(country == "")
	{
		alert("Country can't be Blank");
		window.document.editprofile.country.focus();
		return false;
	}
	if(zip == "")
	{
		alert("Zip/Postal Code can't be Blank");
		window.document.editprofile.firstname.focus();
		return false;
	}
	if(phone == "")
	{
		alert("Phone  can't be Blank");
		window.document.editprofile.phone.focus();
		return false;
	}
	

	
	if(myRegxp.test(document.editprofile.firstname.value))
	{
		alert("First name cannot contain a numerical 0-9 value.");
		return false;
	}
	if(myRegxp.test(document.editprofile.lastname.value))
	{
		alert("Last name cannot contain a numerical 0-9 value.");
		return false;
	}
	if(myRegxpPhone.test(document.editprofile.phone.value))
	{
		alert("Telephone number must be a numerical 0-9 value.");
		return false;
	}
}
//*************** Validate Password ***************//
function validatePwd() 
{
	var invalid = " "; // Invalid character is a space
	var minLength = 6; // Minimum length
	if (document.myForm.currentpasswd)//RAJESH PAGADALA
	{	
		var ctp = document.myForm.currentpasswd.value;
		if(ctp == '') 
		{
			alert('Enter your Current Password');
			document.myForm.currentpasswd.focus();
			return false;
		}
	}
	
	var pw1 = document.myForm.newpasswd1.value;
	var pw2 = document.myForm.newpasswd2.value;

	
	// Check for a Value in Both Fields.
	if (pw1 == '' || pw2 == '') 
	{
		alert('Please enter a new password in both the fields.');
		document.myForm.newpasswd1.focus();
		return false;
	}
	// Check for Minimum Length
	if (pw1.length < minLength) 
	{
		alert('Your password must be at least ' + minLength + ' characters long. Please Try again.');
		document.myForm.newpasswd1.focus();
		return false;
	}
	// Check for Spaces
	if (pw1.indexOf(invalid) > -1) 
	{
		alert("Spaces are not allowed as Password. Please re-enter again.");
		document.myForm.newpasswd1.focus();
		return false;
	}
	else 
	{
		if (pw1 != pw2) 
		{
			alert ("You did not enter the same new password in both the fields. Please Try again.");
			document.myForm.newpasswd1.focus();
			return false;
		}
	}
}


//var swear_words_arr=new Array("fuck","bloody","war","terror");
var swear_words_arr=new Array("ass","asses","asshole","assholes","bastard","beastial","beastiality","beastility","bestial","bestiality","bitch","bitcher","bitchers","bitches","bitchin","bitching","blowjob","blowjobs","clit","cock","cocks","cocksuck","cocksucked","cocksucker","cocksucking","cocksucks","cum","cummer","cumming","cums","cumshot","cunilingus","cunillingus","cunnilingus","cunt","cuntlick ","cuntlicker","cuntlicking","cunts","cyberfuc","cyberfuck","cyberfucked","cyberfucker","cyberfuckers","cyberfucking","damn ","dildo","dildos","dink","dinks","ejaculate","ejaculated","ejaculates","ejaculating","ejaculatings","ejaculation","fag","fagging","faggot","faggs","fagot","fagots","fags","fart","farted","farting","fartings","farts","farty","felatio","fellatio","fingerfuck","fingerfucked","fingerfucker","fingerfuckers","fingerfucking","fingerfucks","fistfuck","fistfucked","fistfucker","fistfuckers","fistfucking","fistfuckings","fistfucks","fuck","fucked","fucker","fuckers","fuckin","fucking","fuckings","fuckme ","fucks","fuk","fuks","gangbang","gangbanged","gangbangs","gaysex","goddamn","hardcoresex","hell","horniest","horny","hotsex","jack-off","jerk-off","jism","jiz ","jizm ","kock","kondum","kondums","kum","kummer","kumming","kums","kunilingus","lust","lusting","mothafuck","mothafucka","mothafuckas","mothafuckaz","mothafucked ","mothafucker","mothafuckers","mothafuckin","mothafucking","mothafuckings","mothafucks","motherfuck","motherfucked","motherfucker","motherfuckers","motherfuckin","motherfucking","motherfuckings","motherfucks","nigger","niggers","orgasim","orgasims","orgasm","orgasms","phonesex","phuk","phuked","phuking","phukked","phukking","phuks","phuq","piss","pissed","pisser","pissers","pisses","pissin","pissing","pissoff","porn","porno","pornography","pornos","prick","pricks","pussies","pussy","pussys","shit","shited","shitfull","shiting","shitings","shits","shitted","shitter","shitters ","shitting","shittings","shitty","slut","sluts","smut","spunk","twat","idiot","rogue", "rascal","scoundrel");
var swear_alert_arr=new Array;
var swear_alert_count=0;

function reset_alert_count()
{
     swear_alert_count=0;
}

function validate_user_text(comp_obj)
{
     reset_alert_count();
     var compare_text = comp_obj.value;
     for(var i=0; i<swear_words_arr.length; i++)
     {
        for(var j=0; j<(compare_text.length); j++)
        {
            if(swear_words_arr[i]==compare_text.substring(j,(j+swear_words_arr[i].length)).toLowerCase())
            {
                swear_alert_arr[swear_alert_count]=compare_text.substring(j,(j+swear_words_arr[i].length));
                swear_alert_count++;
            }
        }
     }
/*     var alert_text="";
     for(var k=1; k<=swear_alert_count; k++)
     {
        alert_text+="\n" + "(" + k + ")  " + swear_alert_arr[k-1];
     }
*/	 
     if(swear_alert_count>0)
     {
		alert("The alias you have selected is not permitted. Please change and try again.");
        comp_obj.select();
		return 0;
     }
     else
     {
        return 1;
     }
}

function select_area()
{
     document.form1.user_text.select();
}

//window.onload=reset_alert_count;



//*************** Validate Registration ***************//
function register_val(register) 
{
	var als = window.document.register.alias.value;
	var pw1 = window.document.register.passwd.value;
	var pw2 = window.document.register.confirm_passwd.value;
	var invalid = " "; // Invalid character is a space
	var minLength = 6; // Minimum length
	
	if(als == "")
	{
		alert("Please enter an Alias.");
		window.document.register.alias.focus();
		return false;
	}
	if(als.length < 4)
	{
			alert('Alias must be at least  4 characters long. Please Try again.');
			window.document.register.alias.focus();
			return false;
	}
	
	if (pw1 == '' || pw2 == '') 
	{
		alert('Please enter a  password in both the fields.');
		window.document.register.passwd.focus();
		return false;
	}
	// Check for Minimum Length
	if (pw1.length < minLength) 
	{
		alert('Your password must be at least ' + minLength + ' characters long. Please Try again.');
		window.document.register.passwd.focus();
		return false;
	}
	// Check for Spaces
	if (pw1.indexOf(invalid) > -1) 
	{
		alert("Spaces are not allowed as Password. Please re-enter again.");
		window.document.register.passwd.focus();
		return false;
	}
	else 
	{
		if (pw1 != pw2) 
		{
			alert ("You did not entered the same password in both the fields. Please Try again.");
			window.document.register.passwd.focus();
			return false;
		}
	}
	
	
	
	var e1 = document.register.email.value;
	if (e1 == '') 
	{
		alert('Please enter your email.');
		window.document.register.email.focus();
		return false;
	}
			
	var testresults;
	var str=window.document.register.email.value;
	var iChars = "!#$%^&*()+=[]\\\';,/{}|\":<>?";

	for (var i = 0; i < str.length; i++) {
  	if (iChars.indexOf(str.charAt(i)) != -1) {
  	alert ("Your email has special characters. \nThese are not allowed.\n Please remove them and try again.");
  	return false;
  	}
	}
	var filter=/^\w+([\.\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
		
	if (filter.test(str))
	{
		testresults=true;
	}else {
		alert("Please input a valid email address!")
		window.document.register.email.select();
		testresults=false;
	}
	return (testresults);
	
}


//*************** Validate Email ***************//
function checkEmail(myForm)
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.emailid.value))
	{
		return (true)
	}
	alert("Invalid E-mail Address! Please re-enter.")
	return (false)
}


//*************** Process Logout ***************//
function logout()
{	
	var name=confirm("Are you sure you to want Logout ?")
	if (name==true)
	{
		window.location.href="/logout.php";
	}
	else 
	{
		
	}
}


//*************** Validate Login Form ***************//
function validate(formCheck) 
{
	var invalid = " ";
	if(formCheck.login.value=="")
	{
		alert("Please enter your Name");
		formCheck.login.focus();
		return false;
	}
	if(formCheck.passwd.value=="")
	{
		alert("Please enter Your Password");
		formCheck.passwd.focus();
		return false;
	}
	
	if (formCheck.login.value.indexOf(invalid) > -1 || formCheck.passwd.value.indexOf(invalid) > -1) 
	{
		alert("Spaces are not allowed as Password. Please re-enter again.");
		Form1.passwd.select();
		return false;
	}
}


//*************** Validate Deposits ***************//
function validate_deposit(mainform) 
{
	var amount = window.document.mainform.amount.value;
	if (amount=='') 
	{
		alert('Please enter an amount to Deposit');
		window.document.mainform.amount.select();
		return false;
	}
	else if(amount <=0)
	{
		alert('The amount you have entered is invalid, Please re-enter again.');
		window.document.mainform.amount.select();
		return false;
	}
	else if(amount >1000)
	{
		alert('You cannot deposit more than 1000 per transaction.');
		window.document.mainform.amount.select();
		return false;
	}
}


//*********************** Validate LPS ***********************//
function minimum_deposit() {
	var amount = document.cashier.amount.value;
	if (amount < 20) {
		alert("Minimum deposit amount is $20");
		window.document.cashier.amount.focus();
		return false;
	}
	if (isNaN(amount)) {
		alert("Minimum deposit amount is $20");
		window.document.cashier.amount.focus();
		return false;
	}	
}


//*************** Return to Status Page from POS ***************//
function openBlankWindow(trackid, paymenttype)
{
	window.open('','POS', 'width=700, height=600, left=200, top=40, scrollbars=yes, toolbar=no, status=yes, resizable=no');
	parent.location.href=paymenttype+'/status.php?trackid='+trackid;
	return true;
}


//*************** Return to Status Page from UMB ***************//
function openUMBWindow(trackid, paymenttype)
{
	window.open('','UMB', 'width=516, height=600, left=253, top=40, scrollbars=yes, toolbar=no, status=yes, resizable=no');
	parent.location.href=paymenttype+'/status.php?trackid='+trackid;
	return true;
}


//*************** Return to Status Page from AlertPay ***************//
function openAPWindow(trackid, paymenttype)
{
	parent.location.href=paymenttype+'/status.php?trackid='+trackid;
	return true;
}


//*************** Display Bingo Timer ***************//
function init()
{
	setTimeout('refreshTimer()', 1000);
}

function refreshTimer()
{
	var streams = document.getElementById("streams");
	var timers = document.getElementById("streams").value ;

	var i=1 ;
	for ( i=1 ; i < timers ;i++)
	{
		time = document.getElementById("time"+i);
		seconds = time.value ;
		seconds = seconds - 1 ; 
		time.value=seconds ;
		message = document.getElementById("message"+i);
		if ( seconds < 1 ) 
			message.innerHTML="Started" ;
		else
		{
			min = (seconds - seconds % 60) / 60 ; 
			sec = seconds%60 ;
			if ( sec < 10 ) 
				str = min+":0"+sec ;
			else
				str = min+":"+sec ; 
			message.innerHTML = str ;
		}

	}
	setTimeout('refreshTimer()', 1000); 
}


//*************** Open POPUP Window ***************//
function MM_openBrWindow(theURL,winName,features) 
{ 
	window.open(theURL,winName,features);
}


//*************** Getting Started ***************//
function newImage(arg) {
	
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() 
{
	
	if (document.images && (preloadFlag == true)) 
	{
		for (var i=0; i<changeImages.arguments.length; i+=2) 
		{
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}


//*************** Getting Started   TOOL TIP***************//
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function prepareInputsForHints() {
	var inputs = document.getElementsByTagName("td");
	for (var i=0; i<inputs.length; i++){
		// test to see if the hint span exists first
		if (inputs[i].parentNode.getElementsByTagName("small")[0]) {
			// the span exists!  on focus, show the hint
			inputs[i].onmouseover= function () {
				this.parentNode.getElementsByTagName("small")[0].style.display = "inline";
			}
			
			
			// when the cursor moves away from the field, hide the hint
			inputs[i].onmouseout = function () {
				this.parentNode.getElementsByTagName("small")[0].style.display = "none";
			}
		}
	}
	/*  // repeat the same tests as above for selects
	var selects = document.getElementsByTagName("select");
	for (var k=0; k<selects.length; k++){
		if (selects[k].parentNode.getElementsByTagName("span")[0]) {
			selects[k].onclick = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			selects[k].mouseout = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
	*/
}
addLoadEvent(prepareInputsForHints);
