function setLang(lang) {
	document.getElementById("lang").value = lang;
}
function setCountry() {
	document.getElementById("country").value = document.getElementById("countrySelect").value;
}
function setPage(pg) {
	document.getElementById("page").value = pg;
}
function setBiller(biller) {
	document.getElementById("allbiller").value = biller;
}
function setPass() {
	document.getElementById("passwd").value = document.getElementById("passwdbox").value;
}
function setFinal(payment){
	var embed = document.getElementById('embed').value;
	var campaign = document.getElementById('mpcID').value;
	var referer = '';
		
	if(document.getElementById('referer').value != ''){
		referer = '&referer='+document.getElementById('referer').value;
	}
	
	//Done so that older versions of mENABLE will still be backward compatible
	if(document.getElementById('secure')){
		var secure = document.getElementById('secure').value;
		
		if(secure != ''){
			window.location.href = '?secure=' + secure + '&pay=' + payment + '&page=help&embed=' + embed;
		}else{
			window.location.href = '?mpcID=' + campaign + referer + '&pay=' + payment + '&page=help&embed=' + embed;
		}
	}else{
		window.location.href = '?mpcID=' + campaign + referer + '&pay=' + payment + '&page=help&embed=' + embed;
	}
}
function submitDaopay() {
	document.getElementById("passcheck").value = document.getElementById('daopay_order').value;
	document.getElementById("mEnableFrm").submit();
}
function selectInput(object){
	object.style.backgroundColor = '#FFFFCC';
}
function deselectInput(object){
	object.style.backgroundColor = '#FFFFFF';
}
function submitForm() {
	try {
		if(document.getElementById('passwd').value != document.getElementById('password').value){
			document.getElementById('passwd').value = '';
		}
	} catch(e) {
		document.getElementById('passwd').value = '';
	}
	
	document.getElementById("mEnableFrm").submit();
}
function submitPassword(){
	if(document.getElementById('password').value == ''){
		document.getElementById('passwd').value = 'null';
		submitForm();
	}else{
		document.getElementById('passwd').value = document.getElementById('password').value;
		submitForm();
	}
}
function showHelp(name){
	document.getElementById(name).style.display = 'block';
}
function hideHelp(name){
	document.getElementById(name).style.display = 'none';
}
function showLoader(){
	Form.disable('billerForm');
	Element.update('billerDiv', '<div id="loading"><img src="images/loading.gif" alt="loading" \/><p>Loading<\/p><\/div>');
}
function hideLoader(){
	Form.enable('billerForm');
}
function updateBiller(resp){
	var html = resp.responseText;
	Element.update('billerDiv', html);
}
function errorBiller(){
	Element.update('billerDiv', '<div id="loadingError"><img src="images/info.png" alt="error" \/><p>This billing option<br \/>is currently unavailable<\/p><\/div>');
}
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

// Validation functions 
function checkPhone(number, form){
	var length = number.length;
	
	if (length == 0) {
		alert('Please enter Phone number');
		return false
	}
	if (!IsNumeric(number)) {
		alert('Phone number has to be numeric');
		return false;
	}
	if (length > 13) {
		alert('Phone number is too long');
		return false;
	}
	if (length < 7) {
		alert('Phone number is too short');
		return false;
	}
	
	var submitForm = form + 'Form';
	eval('document.' + submitForm + '.submit()'); 
	setFinal(form); 
	return false;
}

function checkEmail(email, form){
	if (email == null || email.length == 0) {
		alert('Please enter an email address');
		return false;
	}
	
	if (!allValidChars(email)) {  // check to make sure all characters are valid
		alert('Email contains illegal caracters');
		return false;
	}
	
	if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
		alert('Email invalid');
		return false;
	} else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
		alert('Email invalid');
		return false;
	} else if (email.indexOf("@") == email.length) {  // @ must not be the last character
		alert('Email invalid');
		return false;
	} else if (email.indexOf("..") >=0) { // two periods in a row is not valid
		alert('Email invalid');
		return false;
	} else if (email.indexOf(".") == email.length) {  // . must not be the last character
		alert('Email invalid');
		return false;
	}
	
	var submitForm = form + 'Form';
	eval('document.' + submitForm + '.submit()'); 
	setFinal(form); 
	return false;
}

function IsNumeric(strString) {
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;
	
	if (strString.length == 0) return false;
	
	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) {
			blnResult = false;
		}
	}
	return blnResult;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}

var strMotion = "sink";
var strInitilise;
var wSpeed = 8;
var hSpeed = 5;
var speedTime = 10;
var finalWidth = 500;
var finalHeight = 275;
var overCount = 0;

function useFloater(){
	if(strMotion == "sink"){
		strInitilise = 1;
		strMotion = "float"
		setTimeout('infoBoxFloater_float()',10);
		document.getElementById('infoBoxFloater').style.border = "1px solid #CCCCCC";
	}else{
		strInitilise = 2;
		strMotion = "sink";
		setTimeout('infoBoxFloater_sink()',10);
	}
}

function infoBoxFloater_float(){
	
	var width = (document.getElementById('infoBoxFloater').style.width.replace(/px/, '') * 1);
	var height = (document.getElementById('infoBoxFloater').style.height.replace(/px/, '') * 1);
	
	if(width < finalWidth && strMotion == "float"){
		document.getElementById('infoBoxFloater').style.width = width + wSpeed + "px";
		
		if(height < finalHeight){
			document.getElementById('infoBoxFloater').style.height = height + hSpeed + "px";
		}else{
			overCount++;
		}
		
		setTimeout('infoBoxFloater_float()',speedTime);
		if(width > 100 && strInitilise == 1){
			document.getElementById('infoBoxFloater').innerHTML = "<div class='floaterLoadHeading'><img src='images/wbo/icon_info2.gif' alt='Info' title='Information' /> Loading ...</div><div class='infoBoxFloater2'></div>";
			strInitilise = 0;
		}
	}else{
		document.getElementById('infoBoxFloater').innerHTML = "<div class='heading'><img src='images/wbo/icon_info2.gif' alt='Info' title='Information' />&nbsp;&nbsp;&nbsp;mENABLE Information Centre</div><div class='infoBoxFloater2'>Welcome to mENABLE Information Centre, please follow the instructions below to help you make a successful payment.<br /><br /><b>Step By Step Payment Guide:</b><ul><li>1. Select your country from the dropdown list.</li><li>2. Choose the method in which you wish to pay.&nbsp;&nbsp;&nbsp;&nbsp;<i>i.e. Credit / Debit Card</i></li><li>3. Choose the payment processor that you wish to pay with.&nbsp;&nbsp;&nbsp;&nbsp;<i>i.e. PayPal</i></li><li>4. Make your payment and wait for a confirmation message.&nbsp;&nbsp;&nbsp;&nbsp;<i>via Email or SMS</i></li><li>5. Enter your access Pin Code / Password you received.</li></ul><br />For further assistance or help with any issues you may have using mENABLE please us our interactive support system.<br /><br /><a href='http://www.txtnation.com/sd/' target='_new'>mENABLE Support</a></div>";
	}
}

function infoBoxFloater_sink(){
	
	var width = (document.getElementById('infoBoxFloater').style.width.replace(/px/, '') * 1);
	var height = (document.getElementById('infoBoxFloater').style.height.replace(/px/, '') * 1);
	
	if(width > 0 && strMotion == "sink"){
		
		if(overCount > 0){
			overCount = overCount - 1;
		}else{
			document.getElementById('infoBoxFloater').style.height = height - hSpeed + "px";
		}
		
		document.getElementById('infoBoxFloater').style.width = width - wSpeed + "px";
		
		setTimeout('infoBoxFloater_sink()',speedTime);
		
		
		if(width < 12){
			document.getElementById('infoBoxFloater').style.border = "0px";
		}else if(width < 100 && strInitilise == 1){
			document.getElementById('infoBoxFloater').innerHTML = "";
			strInitilise = 0;
		}else if(width < (finalWidth - 20) && strInitilise == 2){
			document.getElementById('infoBoxFloater').innerHTML = "<div class='floaterLoadHeading'><img src='images/wbo/icon_info2.gif' alt='Info' title='Information' />Closing ...</div><div class='infoBoxFloater2'></div>";
			strInitilise = 1;
		}
	}
}

function changeShortcodeByNetwork(newShortcode){
	
	document.getElementById('smsBillerNumber').innerHTML = newShortcode;
}

function PABallonTip(){
	
	if(document.getElementById('embed') && document.getElementById('embed').value == 1){
		document.getElementById('PABallon').className='showPinAccessBallon';
	}else{
		document.getElementById('PABallon').className='showPinAccessBallonTall';
	}
}

function PABallonTipHide(){
	document.getElementById('PABallon').className='hidePinAccessBallon';
}

function CBBallonTipHide(){
	document.getElementById('CBBallon').className='hideClickBuyBallon';
}
