//*******************************************************
// Display Functions
//*******************************************************
function toggle(el){
  if( document.getElementById(el).style.display=='none' ) {
    document.getElementById(el).style.display = '';
  }else{
    document.getElementById(el).style.display = 'none';
  }
}

function NoPostBack(sNewFormAction)
{
	document.forms[0].action = sNewFormAction;
	document.forms[0].__VIEWSTATE.name = 'NOVIEWSTATE';
}

function showlaptop(theTable)
{
	if (document.getElementById(theTable).style.display == 'none')
	{
		document.getElementById(theTable).style.display = 'block';
	}
}

function hidelaptop(theTable)
{
	if (document.getElementById(theTable).style.display == 'none')
	{
		document.getElementById(theTable).style.display = 'none';
	}
	else
	{
		document.getElementById(theTable).style.display = 'none';
	}
}

function TrimString(sInString) 
{
  	sInString = sInString.replace( /^\s+/g, "" );
  	return sInString.replace( /\s+$/g, "" );
}

function isUrl(s) 
{
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}

function isPhone(aString) 
{
	var aChar = null;
	var status = true;

	if(aString.length == 0) 
	{
		status = false;
	}
	else
	{
		for(var i = 0; i <= aString.length; i++) 
		{
			aChar = aString.charAt(i);
			if (aChar == "("  || aChar == ")" || aChar == "-" || IsNumeric(aChar))
			{
				continue;
			}
			else
			{
				status = false;
				break;
			}
		}
	}
	return(status);
}

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 isEmail(str)
{
	var filter=/^.+@.+\..{2,3}$/;
	return (filter.test(str));
}

function loadWebSites()
{	
	var i = 1;
	var maxWebSites = 0;
	
	maxWebSites = document.getElementById("ctl03_cboURLs").value;
	
	for (i=1; i <= 8; i++)
	{
		hidelaptop('tblWS' + i);
	}
		
	for (i=1; i <= maxWebSites; i++)
	{
		showlaptop('tblWS' + i);
	}

	return true;		
}

	function loadDefaultPayments(payType)
	{		
		switch (payType) 
		{				
			case "ACH": 
				showlaptop('tbAchPayment');
				hidelaptop('tbNetellerPayment');
				hidelaptop('tbCasinoPayment');
				hidelaptop('tbATMPayment');
				hidelaptop('tbFirepayPayment');
				hidelaptop('tbMoneybookers');				
				break;
				
			case "NETELLER": 
				hidelaptop('tbAchPayment');
				showlaptop('tbNetellerPayment');
				hidelaptop('tbCasinoPayment');
				hidelaptop('tbATMPayment');
				hidelaptop('tbFirepayPayment');
				hidelaptop('tbMoneybookers');				
				break;

			case "CASINO": 
				hidelaptop('tbAchPayment');
				hidelaptop('tbNetellerPayment');
				showlaptop('tbCasinoPayment');
				hidelaptop('tbATMPayment');
				hidelaptop('tbFirepayPayment');
				hidelaptop('tbMoneybookers');				
				break;

			case "ATM": 
				hidelaptop('tbAchPayment');
				hidelaptop('tbNetellerPayment');
				hidelaptop('tbCasinoPayment');
				showlaptop('tbATMPayment');
				hidelaptop('tbFirepayPayment');
				hidelaptop('tbMoneybookers');				
				break;

			case "FIREPAY": 
				hidelaptop('tbAchPayment');
				hidelaptop('tbNetellerPayment');
				hidelaptop('tbCasinoPayment');
				hidelaptop('tbATMPayment');
				showlaptop('tbFirepayPayment');
				hidelaptop('tbMoneybookers');				
				break;				

			case "MONEYBOOKERS": 
				hidelaptop('tbAchPayment');
				hidelaptop('tbNetellerPayment');
				hidelaptop('tbCasinoPayment');
				hidelaptop('tbATMPayment');
				hidelaptop('tbFirepayPayment');
				showlaptop('tbMoneybookers');				
				break;				
												
			default: 
				hidelaptop('tbAchPayment');
				hidelaptop('tbNetellerPayment');
				hidelaptop('tbCasinoPayment');
				hidelaptop('tbATMPayment');
				hidelaptop('tbFirepayPayment');
				hidelaptop('tbMoneybookers');
				break;
		}		
		return true;		
	}
	
	function CheckSignUpAffiliateInfo()
	{
		var toReturn = true;
		var errorMsj = "";
		
		hidelaptop("dvError");

		if (document.getElementById("ctl03_affUsername").value == "") 
		{
			errorMsj = "Please write a correct 'User Name' field.<br>";
			document.getElementById("ctl03_affUsername").focus();	
			toReturn = false;	
		}
		
		if (document.getElementById("ctl03_affPassword").value == "") 
		{
			errorMsj = "Please write a correct 'Password' field.<br>";
			document.getElementById("ctl03_affPassword").focus();	
			toReturn = false;	
		}	
		
		if (document.getElementById("ctl03_affRePassword").value == "") 
		{
			errorMsj = "Please write a correct 'Re-type password' field.<br>";
			document.getElementById("ctl03_affRePassword").focus();	
			toReturn = false;	
		}				
								
		if (document.getElementById("ctl03_affFName").value == "") 
		{
			errorMsj = "Please write a correct 'First Name' field.<br>";
			document.getElementById("ctl03_affFName").focus();	
			toReturn = false;	
		}
		
		if (document.getElementById("ctl03_affLName").value == "") 
		{
			errorMsj = errorMsj + "Please write a correct 'Last Name' field.<br>";
			document.getElementById("ctl03_affLName").focus();
			toReturn = false;		
		}		
		
		if ( (document.getElementById("ctl03_affEmail").value == "") || ( !isEmail(document.getElementById("ctl03_affEmail").value) ) )
		{
			errorMsj = errorMsj + "Please write a correct 'E-mail' field.<br>";
			document.getElementById("ctl03_affEmail").focus();
			toReturn = false;
		}
		
		if (document.getElementById("ctl03_affHomePhone").value == "") 
		{
			errorMsj = errorMsj + "Please write a correct 'Home Phone' field.<br>";
			document.getElementById("ctl03_affHomePhone").focus();
			toReturn = false;
		}		
		
		if (document.getElementById("ctl03_affAddress1").value == "") 
		{
			errorMsj = errorMsj + "Please write a correct 'Address' field.<br>";
			document.getElementById("ctl03_affAddress1").focus();
			toReturn = false;
		}
				
		if (document.getElementById("ctl03_affCity").value == "") 
		{
			errorMsj = errorMsj + "Please write a correct 'City' field.<br>";
			document.getElementById("ctl03_affCity").focus();
			toReturn = false;
		}		
		
		if (document.getElementById("ctl03_affZipCode").value == "") 
		{
			errorMsj = errorMsj + "Please write a correct 'Post Code' field.<br>";
			document.getElementById("ctl03_affZipCode").focus();
			toReturn = false;
		}
		
		//if (document.getElementById("ctl03_affCompany").value == "") 
		//{
		//	errorMsj = errorMsj + "Please write a correct 'Company' field.<br>";
		//	document.getElementById("ctl03_affCompany").focus();
		//	toReturn = false;
		//}
		
		//if (document.getElementById("ctl03_affDescribeSite").value == "") 
		//{
		//	errorMsj = errorMsj + "Please write a correct 'Describe Site' field.<br>";
		//	document.getElementById("ctl03_affDescribeSite").focus();
		//	toReturn = false;
		//}
		
		//if (document.getElementById("ctl03_affBussinesPhone").value == "") 
		//{
			//errorMsj = errorMsj + "Please write a correct 'Bussines Phone' field.<br>";
			//document.getElementById("ctl03_affBussinesPhone").focus();
			//toReturn = false;
		//}
		
		if (document.getElementById("ctl03_affPayeeName").value == "") 
		{
			errorMsj = errorMsj + "Please write a correct 'Payee Name' field.<br>";
			document.getElementById("ctl03_affPayeeName").focus();
			toReturn = false;
		}		
		
		//if (document.getElementById("ctl03_affWebSiteName").value == "") 
		//{
		//	errorMsj = errorMsj + "Please write a correct 'WebSite Name' field.<br>";
		//	document.getElementById("ctl03_affWebSiteName").focus();
		//	toReturn = false;
		//}		
	
		//if ( (document.getElementById("ctl03_affWebSite").value == "") || (!isUrl(document.getElementById("ctl03_affWebSite").value ) ) )
		//{			
		//	errorMsj = errorMsj + "Please write a correct 'WebSite URL' field. Ex: http://www.gamblingewages.com <br>";
		//	document.getElementById("ctl03_affWebSite").focus();
		//	toReturn = false;
		//}
		
		if (toReturn == false)
		{
			document.getElementById("ErrorInfoMsj").innerHTML = errorMsj + "<br>";
			showlaptop("dvError");
		}
		else
			NoPostBack("index.aspx?TabId=regdne");						
		
		return toReturn;
	}	
