
//Select
function doResize(){

	//Select browser
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		bIE = true;
	} else {
		bIE = false;
	}
	
	//Defaults
	oleft = false;
	ocenter = false;
	oright = false;
	
	//Calc Refs, Width and Height
	if (bIE){
		
		//Refs
		if(document.all.leftColInner){oleft=document.all.leftColInner};
		if(document.all.centerColInner){ocenter=document.all.centerColInner};
		if(document.all.rightColInner){oright=document.all.rightColInner};
		
		//Height + Width
		iH = document.body.offsetHeight;
		
	} else {
		
		//Refs
		oleft = document.getElementById('leftColInner');
		ocenter = document.getElementById('centerColInner');
		oright = document.getElementById('rightColInner');
		
		//Resize colTable
		iH = window.innerHeight;
		document.body.style.height=iH+'px';
	}
	
	//Resize dynamic columns
	if (oleft!=false) {oleft.style.height = (iH - oleft.offsetTop - 4)+'px';}
	if (ocenter!=false) {ocenter.style.height = (iH - ocenter.offsetTop - 1)+'px';}
	if (oright!=false) {oright.style.height = (iH - oright.offsetTop - 4)+'px';}
	
}


function ToggleFTPLoginForm(o) {

	if (!o.checked) {
		document.addvhostform.User.disabled = true;	
		document.addvhostform.password.disabled = true;	
		document.addvhostform.confirmpassword.disabled = true;	
	} else {
		document.addvhostform.User.disabled = false;	
		document.addvhostform.password.disabled = false;	
		document.addvhostform.confirmpassword.disabled = false;	
	}
}

function statusShowDetails(o,divid){

	o.style.cursor = 'pointer';

	oHelp = document.getElementById('helptext');
	oHelp.style.display = 'none';
	oDiv = document.getElementById(divid);
	oShow = document.getElementById('showdetails');
	oShow.innerHTML = oDiv.innerHTML ;
	
}

function Toggle(v) {
	oHelp = document.getElementById(v);
	if (oHelp.style.display == 'none')
	{
		oHelp.style.display = 'block';
	} else {
		oHelp.style.display = 'none';
	}


}

function statusHideDetails(){
	oHelp = document.getElementById('helptext');
	oHelp.style.display = 'inline';
	oShow = document.getElementById('showdetails');
	oShow.innerHTML = "" ;
	
}

function goDomainSettings(key){
	oForm = document.getElementById('MailboxForm');
	oForm.settings.name = "settings-"+key;
	oForm.submit();
}

function goSettings(key){
	oForm = document.getElementById('MailboxForm');
	oForm.settings.name = "settings-"+key;
	oForm.submit();
}

function goAccount(key){
	oForm = document.getElementById('AccountForm');
	oForm.setting.name = "manage-"+key;
	oForm.submit();
}

function doRemoveAlias(key){
	oForm = document.getElementById('AliasForm');
	if(confirm("Are you sure? Click 'OK' to confirm.")){
		oForm.remove.name = "removealias-"+key;
		oForm.submit();
	}
}

function doDeleteMailbox(key){
	oForm = document.getElementById('SubmitForm');
	if(confirm("Are you sure? Click 'OK' to confirm.")){
		oForm.setting.name = "removemailbox-"+key;
		oForm.submit();
	}
}

function navOver(o){
	o.className='navButtonSel';
}

function navOut(o){
	o.className='navButton';
}

function gotoListAllAccounts(){
	o = document.getElementById('ListAllAccountsForm');
	o.submit();
}

function asubmit(formname){
	o = document.getElementById(formname);
	o.submit();
}

function doSubmit(formname,settingname){
	o = document.getElementById(formname);
	o.setting.name = settingname;
	o.submit();
}

function doSubmitConfirm(formname,settingname){
	if(confirm("Are you sure? Click 'OK' to confirm.")){
		doSubmit(formname,settingname);
	}
}

function selectAllMSGID(o){
var i;
var oForm = document.getElementsByTagName('input');

	x = oForm.chkitem.length;

	for (i = 0; i < x; i++){
		if(o.checked){
			oForm.chkitem[i].checked = true;
		} else {
			oForm.chkitem[i].checked = false;
		}
	}

}

function toggleFetchHost(o){
	oRow = document.getElementById('FetchHostRow');
	oHost = document.getElementById('mailhost');
	if(o.selectedIndex==1){
		oRow.style.display = "none";
		oHost.value = "hotmail";
	} else {
		oRow.style.display = "inline";
		oHost.value = "";		
	}
}

function checkEmail(o){
        oForm = document.getElementById('OrderForm');
        if (oForm.extrainfo.value == '')
        {
                alert("Please enter a valid email address.");
                return false;
        }
        if (oForm.extrainfo.value.indexOf("@")==-1)
        {
                alert("The format of the domain you have entered is incorrect.");   
                return false;
        }
        return true;
}

function checkDomain(o){
	oForm = document.getElementById('OrderForm');
	if (oForm.extrainfo.value == '')
	{
		alert("Please enter a valid domain name.");
		return false;
	}
	if (oForm.extrainfo.value.indexOf(".")==-1)
	{
		alert("The format of the domain you have entered is incorrect.");
		return false;
	}
	return true;
}

function checkPW(){
	oForm = document.getElementById('FetchAddForm');
	if(oForm.passwd.value != oForm.confirmpw.value){
		alert("Password and confirmation do not match")
		return false;
	} else {
		return true;
	}
}

function checkPWMailbox(){
	oForm = document.getElementById('MailboxForm');
	if(oForm.password.value == "") {
		alert("You have not entered a password");
		return false;

	}
	if(oForm.password.value != oForm.confirmpassword.value){
		alert("Password and confirmation do not match")
		return false;
	} else {
		return true;
	}
}

function checkBulkPWMailbox(no){ 
       oForm = document.getElementById('MailboxForm');
	for(i=0;i <= no;i++) {

	sID = "password" + no;
	o = getElementById(sID);
	alert(sID);
	if (o.value == "")
	{
                alert("You have not entered a password for mailbox 1");
                return false;
	}

	}
        if(oForm.password1.value == "") {
                alert("You have not entered a password for mailbox 1");
                return false;
        }
        if(oForm.password1.value != oForm.confirmpassword1.value){
                alert("Password and confirmation do not match")
                return false;
        }

        if(oForm.password2.value == "") {
                alert("You have not entered a password for mailbox 2");
                return false;

        }
        if(oForm.password1.value != oForm.confirmpassword1.value){
                alert("Password and confirmation do not match")
		return false;
	}
	return true;
}

function showhideSpam(o){
	oSpam1 = document.getElementById('spam1');
	oSpam2 = document.getElementById('spam2');
	oSpam3 = document.getElementById('spam3');		
	oSpam4 = document.getElementById('spam4');		
	if(o.selectedIndex==0){
		oSpam1.style.display = 'none';
		oSpam2.style.display = 'none';
		oSpam3.style.display = 'none';				
		oSpam4.style.display = 'none';				
	} else {
		oSpam1.style.display = 'table-row';
		oSpam2.style.display = 'table-row';
		oSpam3.style.display = 'table-row';					
		oSpam4.style.display = 'table-row';					
	}
}

function updatedomaintext(o) {
	oHost = document.getElementById('domaintext1');
	oHost.innerHTML = o.options[o.selectedIndex].value;
	oHost = document.getElementById('domaintext2');
	oHost.innerHTML = o.options[o.selectedIndex].value;
	oHost = document.getElementById('domaintext3');
	oHost.innerHTML = o.options[o.selectedIndex].value;
	oHost = document.getElementById('domaintext4');
	oHost.innerHTML = o.options[o.selectedIndex].value;
}

function CopyBilling() {
	oform = document.getElementById('TransferOrder');
	var errormsg;

	if (oform.copybilling.value == "on") {
	
        oform1 = document.getElementById('field10');
        oform2 = document.getElementById('field21');
	oform1.value = oform2.value;

        oform1 = document.getElementById('field9');
        oform2 = document.getElementById('field20');
	oform1.value = oform2.value;

        oform1 = document.getElementById('field8');
        oform2 = document.getElementById('field19');
	oform1.value = oform2.value;

        oform1 = document.getElementById('field7');
        oform2 = document.getElementById('field18');
	oform1.value = oform2.value;

        oform1 = document.getElementById('field0');
        oform2 = document.getElementById('field11');
	oform1.value = oform2.value;

        oform1 = document.getElementById('field1');
        oform2 = document.getElementById('field12');
	oform1.value = oform2.value;

        oform1 = document.getElementById('field2');
        oform2 = document.getElementById('field13');
	oform1.value = oform2.value;

        oform1 = document.getElementById('field3');
        oform2 = document.getElementById('field14');
	oform1.value = oform2.value;

        oform1 = document.getElementById('field4');
        oform2 = document.getElementById('field15');
	oform1.value = oform2.value;

        oform1 = document.getElementById('field5');
        oform2 = document.getElementById('field16');
	oform1.value = oform2.value;

        oform1 = document.getElementById('field6');
        oform2 = document.getElementById('field17');
	oform1.value = oform2.value;

        oform1 = document.getElementById('field7');
        oform2 = document.getElementById('field18');
	oform1.value = oform2.value;

        oform1 = document.getElementById('field3');
        oform2 = document.getElementById('field14');
	oform1.value = oform2.value;


	}

}


function checkTransferOrder() {
	oform = document.getElementById('TransferOrder');
	var errormsg;
	var type;
	
	errormsg = '';

	if (oform.origin.value == "") {
		oform.origin.style.border = '1px solid red';
		errormsg = errormsg + 'the domain name you wish to transfer to Fluent\n';
	} else {
		oform.origin.style.border = '1px solid green';
	}
	if (oform.origin.value.match(/.info$/)) {
       		type = 'INFO' 
        }
	oform = document.getElementById('field10');
	if (oform.value == "") {
		oform.style.border = '1px solid red';
		errormsg = errormsg + 'the email address of the domain owner\n';
	} else {
                oform.style.border = '1px solid green';
	}

	oform = document.getElementById('field21');
	if (oform.value == "") {
		oform.style.border = '1px solid red';
		errormsg = errormsg + 'the email address of the billing contact\n';
	} else {
                oform.style.border = '1px solid green';
	}

        oform = document.getElementById('field9');
        if (oform.value == "") {
                oform.style.border = '1px solid red';
                errormsg = errormsg + 'the phone number of the domain owner\n';
        } else {
		if (type == 'INFO') {
			if (oform.value.match(/^\+\d+\.\d+$/)) {
                	   oform.style.border = '1px solid green';
			} else	{
		           oform.style.border = '1px solid red';
                	   errormsg = errormsg + 'The owner phone number should be in the form: +44.1296434146\n';
			}
		} else {
                	oform.style.border = '1px solid green';
		}
        }

        oform = document.getElementById('field20');
        if (oform.value == "") {
                oform.style.border = '1px solid red';
                errormsg = errormsg + 'the phone number of the domain billing contact\n';
        } else {
                if (type == 'INFO') {
                        if (oform.value.match(/^\+\d+\.\d+$/)) {
                           oform.style.border = '1px solid green';
                        } else  {
                           oform.style.border = '1px solid red';
                           errormsg = errormsg + 'The billing phone number should be in the form: +44.1296434146\n';
                        }
                } else {
                        oform.style.border = '1px solid green';
                }
        }

        oform = document.getElementById('field8');
        if (oform.value == "") {
                oform.value = 'UK';
        } 
	if (oform.value.length > 2) {
		errormsg = errormsg + 'The country should be 2 characters eg. UK\n';
                oform.style.border = '1px solid red';
	} else {
                oform.style.border = '1px solid green';      
	}

        oform = document.getElementById('field13');   
        if (oform.value == "") {
                oform.style.border = '1px solid red';
                errormsg = errormsg + 'an organisation name\n';
        } else {
                oform.style.border = '1px solid green';      
        }

	oform = document.getElementById('field3');
	if (oform.value == "") {
                oform.style.border = '1px solid red';
                errormsg = errormsg + 'an organisation name\n';
	} else { 
                oform.style.border = '1px solid green';
	}

        oform = document.getElementById('field19');
        if (oform.value == "") {
                oform.value = 'UK';
        } 
	if (oform.value.length > 2) {
		errormsg = errormsg + 'The country field can only be 2 characters eg. UK';
	}

        oform = document.getElementById('field7');
        if (oform.value == "") {
                oform.style.border = '1px solid red';
                errormsg = errormsg + 'the post code of the domain owner\n';
        } else {
                oform.style.border = '1px solid green';
        }

        oform = document.getElementById('field18');
        if (oform.value == "") {
                oform.style.border = '1px solid red';
                errormsg = errormsg + 'the post code of the billing contact\n';
        } else {
                oform.style.border = '1px solid green';
        }

        oform = document.getElementById('field11');
        if (oform.value == "") {
                oform.style.border = '1px solid red';
                errormsg = errormsg + 'the first name of the billing contact\n';
        } else {
                oform.style.border = '1px solid green';
        }

        oform = document.getElementById('field0');
        if (oform.value == "") {
                oform.style.border = '1px solid red';
                errormsg = errormsg + 'the first name of the domain owner\n';
        } else {
                oform.style.border = '1px solid green';
        }



        oform = document.getElementById('field12');
        if (oform.value == "") {
                oform.style.border = '1px solid red';
                errormsg = errormsg + 'the last name of the billing contact\n';
        } else {
                oform.style.border = '1px solid green';
        }

        oform = document.getElementById('field1');
        if (oform.value == "") {
                oform.style.border = '1px solid red';
                errormsg = errormsg + 'the last name of the domain owner\n';
        } else {
                oform.style.border = '1px solid green';
        }

        oform = document.getElementById('field3');
        if (oform.value == "") {
                oform.style.border = '1px solid red';
                errormsg = errormsg + 'the first line of the address of the domain owner\n';
        } else {
                oform.style.border = '1px solid green';
        }
        oform = document.getElementById('field14');
        if (oform.value == "") {
                oform.style.border = '1px solid red';
                errormsg = errormsg + 'the first line of the address of the domain billing contact\n';
        } else {
                oform.style.border = '1px solid green';
        }

        oform = document.getElementById('field16');
        if (oform.value == "") {
                oform.style.border = '1px solid red';
                errormsg = errormsg + 'the city or post town of the domain billing contact\n';
        } else {
                oform.style.border = '1px solid green';
        }

        oform = document.getElementById('field5');
        if (oform.value == "") {
                oform.style.border = '1px solid red';
                errormsg = errormsg + 'the city or post town of the domain owner\n';
        } else {
                oform.style.border = '1px solid green';
        }


	if (errormsg != '')
	{
		alert('Please enter :\n' + errormsg);
		return false;
	}
	return true;
}

function checkdnscontact() {
	oform = document.getElementById('dnscontactform');
	var errormsg;
	var type;
	
	errormsg = '';

	oform = document.getElementById('field10');
	if (oform.value == "") {
		oform.style.border = '1px solid red';
		errormsg = errormsg + 'the email address of the contact\n';

	} else {
		oform.style.border = '1px solid green';
	}

        oform = document.getElementById('field9');
        if (oform.value == "") {
                oform.style.border = '1px solid red';
                errormsg = errormsg + 'the telephone number of the contact\n';

        } else {
                oform.style.border = '1px solid green';
        }

        oform = document.getElementById('field8');
        if (oform.value == "") {
                oform.style.border = '1px solid red';
                errormsg = errormsg + 'the country code eg. UK\n';

        } else if (oform.value.length > 2) {
                errormsg = errormsg + 'The country should be 2 characters eg. UK\n';
                oform.style.border = '1px solid red';
        } else {
                oform.style.border = '1px solid green';
        }


        oform = document.getElementById('field7');
        if (oform.value == "") {
                oform.style.border = '1px solid red';
                errormsg = errormsg + 'the postcode \n';

        } else {
                oform.style.border = '1px solid green';
        }

        oform = document.getElementById('field0');
        if (oform.value == "") {
                oform.style.border = '1px solid red';
                errormsg = errormsg + 'the first name \n';

        } else {
                oform.style.border = '1px solid green';
        }

        oform = document.getElementById('field1');
        if (oform.value == "") {
                oform.style.border = '1px solid red';
                errormsg = errormsg + 'the last name \n';

        } else {
                oform.style.border = '1px solid green';
        }

        oform = document.getElementById('field2');
        if (oform.value == "") {
                oform.style.border = '1px solid red';
                errormsg = errormsg + 'the organisation name \n';

        } else {
                oform.style.border = '1px solid green';
        }

        oform = document.getElementById('field3');
        if (oform.value == "") {
                oform.style.border = '1px solid red';
                errormsg = errormsg + 'the first line of the address\n';

        } else {
                oform.style.border = '1px solid green';
        }



	if (errormsg != '')
	{
		alert('Please enter :\n' + errormsg);
		return false;
	}
	return true;
}

function suggestPassword()
{
	var pass;
	pass = makeapassword();
	alert("Suggested Password is: " + pass);
}

function makeapassword() {
  var passwordlength = 6; 
  var specialsokay = "no";
  var pwdchars = new Array();
  pwdchars[0] = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
  pwdchars[1] = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
  pwdchars[2] = new Array("0","1","2","3","4","5","6","7","8","9");
  if (specialsokay == "yes") {
	pwdchars[3] = new Array("!","@","#","$","%","^","&","*","(",")","+");
  }
  var rannum1;
  var rannum2;
  var rannum3;
  var pickelem;
  var loopcounter;
  var passwordelement;
  var finalpassword = "";
  var passwordarray = new Array();
  for (loopcounter = 0; loopcounter < passwordlength; loopcounter++)
  {
	do {
		rannum1 = Math.floor(Math.random() * pwdchars.length);
		if ((loopcounter == 0) && (specialsokay == "yes")) {
			rannum1=Math.floor(Math.random() * (pwdchars.length - 1))
		}
		pickelem = Math.floor(Math.random() * pwdchars[rannum1].length)
		passwordelement = pwdchars[rannum1][pickelem];
	}
	while ((rannum1 == rannum2) && (rannum1 == rannum3))
	finalpassword = finalpassword + passwordelement;
  }
  return finalpassword;
}

function areSure() {

  return confirm("Are you sure?");

}


function focusNext(id, evt) {
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
	if (charCode == 13 | charCode == 3 | charCode == 9 | charCode == 39) {
		div = document.getElementById(id);
		div.focus();
		return false;
	}
	return true;
} 
