//
//
// 25 Jan 2003

function round(number,X) {
// rounds number to X decimal places, defaults to 2
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function currency_format(V) {
	V          = Math.floor((V * 100) + 0.50000000001);
	var pence  = V%100;
	if (pence < 10)
		pence = "0" + pence;
	var pounds = Math.floor(V/100).toString();
	V          = pounds + '.' + pence;
	return V;
}
	

var testFill  = 0;
var focusflag = 0;

function Bizness_Selection(svalue) {
	var hostTotal                                 = currency_format((svalue*.49));
	document.biznessSelection.current_total.value = ' ' + hostTotal;
	document.biznessSelection.order_total.value   = ' ' + hostTotal;
	
	browser=BrowserChecker();
	
	if (browser) {
	
	
	Tcell011.bgColor=Tcell012.bgColor=Tcell014.bgColor='';
	Tcell021.bgColor=Tcell022.bgColor=Tcell024.bgColor='';
	Tcell031.bgColor=Tcell032.bgColor=Tcell034.bgColor='';
	Tcell041.bgColor=Tcell042.bgColor=Tcell044.bgColor='';
	Tcell051.bgColor=Tcell052.bgColor=Tcell054.bgColor='';
	Tcell061.bgColor=Tcell062.bgColor=Tcell063.bgColor=Tcell064.bgColor='';
	Tcell071.bgColor=Tcell072.bgColor=Tcell073.bgColor=Tcell074.bgColor='';
	Tcell081.bgColor=Tcell082.bgColor=Tcell083.bgColor=Tcell084.bgColor='';
	Tcell091.bgColor=Tcell092.bgColor=Tcell093.bgColor=Tcell094.bgColor='';
	Tcell101.bgColor=Tcell102.bgColor=Tcell103.bgColor=Tcell104.bgColor='';
	Tcell111.bgColor=Tcell112.bgColor=Tcell113.bgColor=Tcell114.bgColor='';
	Tcell121.bgColor=Tcell122.bgColor=Tcell123.bgColor=Tcell124.bgColor='';
	Tcell131.bgColor=Tcell132.bgColor=Tcell133.bgColor=Tcell134.bgColor='';
	Tcell141.bgColor=Tcell142.bgColor=Tcell143.bgColor=Tcell144.bgColor='';
	Tcell151.bgColor=Tcell152.bgColor=Tcell153.bgColor=Tcell154.bgColor=Tcell156.bgColor='';

	Tcell161.bgColor=Tcell162.bgColor=Tcell163.bgColor=Tcell164.bgColor=Tcell166.bgColor='';
	Tcell171.bgColor=Tcell172.bgColor=Tcell173.bgColor=Tcell174.bgColor=Tcell176.bgColor='';
	Tcell181.bgColor=Tcell182.bgColor=Tcell183.bgColor=Tcell184.bgColor=Tcell186.bgColor='';
	Tcell191.bgColor=Tcell192.bgColor=Tcell193.bgColor=Tcell194.bgColor=Tcell196.bgColor='';
	Tcell201.bgColor=Tcell202.bgColor=Tcell203.bgColor=Tcell204.bgColor=Tcell206.bgColor='';
	Tcell211.bgColor=Tcell212.bgColor=Tcell213.bgColor=Tcell214.bgColor=Tcell216.bgColor='';

	Tcell221.bgColor=Tcell222.bgColor=Tcell223.bgColor=Tcell224.bgColor=Tcell226.bgColor='';
	Tcell231.bgColor=Tcell232.bgColor=Tcell233.bgColor=Tcell234.bgColor=Tcell236.bgColor='';
	Tcell241.bgColor=Tcell242.bgColor=Tcell243.bgColor=Tcell244.bgColor=Tcell246.bgColor='';
	Tcell251.bgColor=Tcell252.bgColor=Tcell253.bgColor=Tcell254.bgColor=Tcell256.bgColor='';
	
	if (svalue == 1) {
		Tcell011.bgColor=Tcell012.bgColor=Tcell014.bgColor='#98E8FF';
	} else if (svalue == 2) {
		Tcell021.bgColor=Tcell022.bgColor=Tcell024.bgColor='#98E8FF';
	} else if (svalue == 3) {
		Tcell031.bgColor=Tcell032.bgColor=Tcell034.bgColor='#98E8FF';
	} else if (svalue == 4) {
		Tcell041.bgColor=Tcell042.bgColor=Tcell044.bgColor='#98E8FF';
	} else if (svalue == 5) {
		Tcell051.bgColor=Tcell052.bgColor=Tcell054.bgColor='#98E8FF';
	} else if (svalue == 6) {
		Tcell061.bgColor=Tcell062.bgColor=Tcell063.bgColor=Tcell064.bgColor='#98E8FF';
	} else if (svalue == 7) {
		Tcell071.bgColor=Tcell072.bgColor=Tcell073.bgColor=Tcell074.bgColor='#98E8FF';
	} else if (svalue == 8) {
		Tcell081.bgColor=Tcell082.bgColor=Tcell083.bgColor=Tcell084.bgColor='#98E8FF';
	} else if (svalue == 9) {
		Tcell091.bgColor=Tcell092.bgColor=Tcell093.bgColor=Tcell094.bgColor='#98E8FF';
	} else if (svalue == 10) {
		Tcell101.bgColor=Tcell102.bgColor=Tcell103.bgColor=Tcell104.bgColor='#98E8FF';
	} else if (svalue == 11) {
		Tcell111.bgColor=Tcell112.bgColor=Tcell113.bgColor=Tcell114.bgColor='#98E8FF';
	} else if (svalue == 12) {
		Tcell121.bgColor=Tcell122.bgColor=Tcell123.bgColor=Tcell124.bgColor='#98E8FF';
	} else if (svalue == 13) {
		Tcell131.bgColor=Tcell132.bgColor=Tcell133.bgColor=Tcell134.bgColor='#98E8FF';
	} else if (svalue == 14) {
		Tcell141.bgColor=Tcell142.bgColor=Tcell143.bgColor=Tcell144.bgColor='#98E8FF';
	} else if (svalue == 15) {
		Tcell151.bgColor=Tcell152.bgColor=Tcell153.bgColor=Tcell154.bgColor=Tcell156.bgColor='#98E8FF';
	} else if (svalue == 16) {
		Tcell161.bgColor=Tcell162.bgColor=Tcell163.bgColor=Tcell164.bgColor=Tcell166.bgColor='#98E8FF';
	} else if (svalue == 17) {
		Tcell171.bgColor=Tcell172.bgColor=Tcell173.bgColor=Tcell174.bgColor=Tcell176.bgColor='#98E8FF';
	} else if (svalue == 18) {
		Tcell181.bgColor=Tcell182.bgColor=Tcell183.bgColor=Tcell184.bgColor=Tcell186.bgColor='#98E8FF';
	} else if (svalue == 19) {
		Tcell191.bgColor=Tcell192.bgColor=Tcell193.bgColor=Tcell194.bgColor=Tcell196.bgColor='#98E8FF';
	} else if (svalue == 20) {
		Tcell201.bgColor=Tcell202.bgColor=Tcell203.bgColor=Tcell204.bgColor=Tcell206.bgColor='#98E8FF';
	} else if (svalue == 21) {
		Tcell211.bgColor=Tcell212.bgColor=Tcell213.bgColor=Tcell214.bgColor=Tcell216.bgColor='#98E8FF';
	} else if (svalue == 22) {
		Tcell221.bgColor=Tcell222.bgColor=Tcell223.bgColor=Tcell224.bgColor=Tcell226.bgColor='#98E8FF';
	} else if (svalue == 23) {
		Tcell231.bgColor=Tcell232.bgColor=Tcell233.bgColor=Tcell234.bgColor=Tcell236.bgColor='#98E8FF';
	} else if (svalue == 24) {
		Tcell241.bgColor=Tcell242.bgColor=Tcell243.bgColor=Tcell244.bgColor=Tcell246.bgColor='#98E8FF';
	} else if (svalue == 25) {
		Tcell251.bgColor=Tcell252.bgColor=Tcell253.bgColor=Tcell254.bgColor=Tcell256.bgColor='#98E8FF';
	}
//	window.status='';
	
	}
}

function SubmitTheEmailForm(form)
{
	var Mailid = [form.luxmiEmails [form.luxmiEmails.selectedIndex].value];

	if (Mailid == 'nothing'){
		alert("Please select the Mail To address.");
		form.luxmiEmails.focus();
		return false;
	}
	else if (Mailid == 'support'){
		top.location.href='http://www.luxmi.net/support/';
		return true;
	}
	else if (form.FromName.value.length < 5){
		alert("Please enter your full name.");
		form.FromName.focus();
		return false;
	}
	else if (form.FromEmail.value.length < 8){
		alert("Please enter your valid email address.");
		form.FromEmail.focus();
		return false;
	}
	else if ((form.Subject.value.length < 2) && (Mailid != 'info')){
		alert("Please enter the subject of your e-mail.");
		form.Subject.focus();
		return false;
	}
	else if ((form.Message.value.length < 5) && (Mailid != 'info')){
		alert("Please enter your e-mail message.");
		form.Message.focus();
		return false;
	}
	form.submit();
}


function SameAsContact(form) {
	if ((form.affiliate_id.value == "testuser") && (testFill == 0)) {
		testFill_entries(form);
		form.flag_use_contact_info.checked = false;
		testFill = 1;  // testfill is done
	} else {
		FillCompany(form);
		FillBillingInfo(form, "clicked");
	}
}
function testFill_entries(form) {
	form.owner_first_name.value  = "Testone";
	form.owner_last_name.value   = "Usertwo";
	form.owner_org_name.value    = "ABC Trading Ltd";
	form.owner_address1.value    = "124 High Street";
	form.owner_city.value        = "Bigcity";
	form.owner_state.value       = "Goodstate";
	form.owner_postal_code.value = "SW1 2AB";
	form.owner_phone.value       = "0121 12345678";
	form.domain.value            = "testdomain.com";
}
function check_Qentry(form, element) {		// checking quick entry
	if (element == "ô") {		// using 147
		testFill_entries(form);
	}
}
function FillCompany(form) {
	if (form.owner_org_name.value.length < 3)
		form.owner_org_name.value = form.owner_first_name.value + ' ' + form.owner_last_name.value;

	if (form.billing_org_name.value.length < 3)
		form.billing_org_name.value = form.billing_first_name.value + ' ' + form.billing_last_name.value;
}
function FillBillingInfo(form, caller) {
	var first   = form.billing_first_name;
	var last    = form.billing_last_name;
	var org     = form.billing_org_name;
	var add1    = form.billing_address1;
	var add2    = form.billing_address2;
	var add3    = form.billing_address3;
	var city    = form.billing_city;
	var state   = form.billing_state;
	var postal  = form.billing_postal_code;
	var phone   = form.billing_phone;
	var fax     = form.billing_fax;
	var email   = form.billing_email;
	var country = form.billing_country;

	if (((form.flag_use_contact_info.checked) && (caller == "submit")) || ((form.flag_use_contact_info.checked) && (caller == "clicked"))) {
		first.value           = form.owner_first_name.value;
		last.value            = form.owner_last_name.value;
		org.value             = form.owner_org_name.value;
		add1.value            = form.owner_address1.value;
		add2.value            = form.owner_address2.value;
		add3.value            = form.owner_address3.value;
		city.value            = form.owner_city.value;
		state.value           = form.owner_state.value;
		postal.value          = form.owner_postal_code.value;
		phone.value           = form.owner_phone.value;
		fax.value             = form.owner_fax.value;
		email.value           = form.owner_email.value;
		country.selectedIndex = form.owner_country.selectedIndex;
	} else if (caller == "clicked") {
		country.selectedIndex = 0;
		first.value=last.value=org.value=add1.value=add2.value=add3.value=city.value=state.value=postal.value=phone.value=fax.value=email.value="";
	}
}


function form_submitter(f) {

	var ErrMssg="";

	FillCompany(f);
	FillBillingInfo(f,"submit")

	if ((f.domain.value.length < 6) || (f.domain.value == "(enter your domain here)")) {
//		if (focusflag != 1){
			focusflag=1;
			f.domain.focus();
			f.domain.select();
//		}
		ErrMssg += "\n     >  domain - Your domain name\n";
	}

	if (f.owner_first_name.value == ""){
		if (focusflag != 1){
			f.owner_first_name.focus();
			f.owner_first_name.select();
		}
		focusflag=1;
		ErrMssg += "\n     >  contact - First Name";
	}
	if (f.owner_last_name.value.length < 2){
		if (focusflag != 1){
			f.owner_last_name.focus();
			f.owner_last_name.select();
		}
		focusflag=1;
		ErrMssg += "\n     >  contact - Last Name";
	}
	if (f.owner_address1.value.length < 3){
		if (focusflag != 1){
			f.owner_address1.focus();
			f.owner_address1.select();
		}
		focusflag=1;
		ErrMssg += "\n     >  contact - Address Line 1";
	}
	if (f.owner_city.value.length < 2){
		if (focusflag != 1){
			f.owner_city.focus();
			f.owner_city.select();
		}
		focusflag=1;
		ErrMssg += "\n     >  contact - City";
	}
	if (f.owner_postal_code.value == ""){
		if (focusflag != 1)
			f.owner_postal_code.focus();
		focusflag=1;
		ErrMssg += "\n     >  contact - Postal Code";
	}
	if (f.owner_phone.value.length < 7){
		if (focusflag != 1){
			f.owner_phone.focus();
			f.owner_phone.select();
		}
		focusflag=1;
		ErrMssg += "\n     >  contact - Telephone";
	}
	if ((f.owner_email.value.length < 6) || (f.owner_email.value.indexOf('@') == -1) || (f.owner_email.value.indexOf('.') == -1)) {
		if (focusflag != 1){
			f.owner_email.focus();
			f.owner_email.select();
		}
		focusflag=1;
		ErrMssg += "\n     >  contact - E-mail";
	}

	if (!(f.flag_use_contact_info.checked))
	{
		ErrMssg += "\n";

		if (f.billing_first_name.value == ""){
			if (focusflag != 1)
				f.billing_first_name.focus();
			focusflag=1;
			ErrMssg += "\n     >  billing - First Name";
		}
		if (f.billing_last_name.value.length < 2){
			if (focusflag != 1){
				f.billing_last_name.focus();
				f.billing_last_name.select();
			}
			focusflag=1;
			ErrMssg += "\n     >  billing - Last Name";
		}
		if (f.billing_address1.value.length < 3){
			if (focusflag != 1){
				f.billing_address1.focus();
				f.billing_address1.select();
			}
			focusflag=1;
			ErrMssg += "\n     >  billing - Address Line 1";
		}
		if (f.billing_city.value.length < 2){
			if (focusflag != 1){
				f.billing_city.focus();
				f.billing_city.select();
			}
			focusflag=1;
			ErrMssg += "\n     >  billing - City";
		}
		if (f.billing_postal_code.value == ""){
			if (focusflag != 1)
				f.billing_postal_code.focus();
			focusflag=1;
			ErrMssg += "\n     >  billing - Postal Code";
		}
		if (f.billing_phone.value.length < 7){
			if (focusflag != 1){
				f.billing_phone.focus();
				f.billing_phone.select();
			}
			focusflag=1;
			ErrMssg += "\n     >  billing - Telephone";
		}
		if ((f.billing_email.value.length < 6) || (f.billing_email.value.indexOf('@') == -1) || (f.billing_email.value.indexOf('.') == -1)) {
			if (focusflag != 1){
				f.billing_email.focus();
				f.billing_email.select();
			}
			focusflag=1;
			ErrMssg += "\n     >  billing - E-mail";
		}
	}

	if (focusflag==1){
		ErrMssg ="__________________________________\n" + " You failed to correctly fill in the following:\n" + ErrMssg + "\n__________________________________" + "\n Please re-enter and submit again!";
		alert(ErrMssg);
		focusflag=0;
		return false;
	}
	f.submit();
}

function enterDomain(form) {
	if ((form.domain.value == "(enter your domain here)") && (focusflag == 0)) {
		form.domain.value = '';
	}
}


var PasswordNotValid='Your password contains Non-(standard) Keyboard\ncharacters or spaces. Please choose another.';

function ValidatePassword(element) {
	
	for (i=0; i<element.value.length; i++) {
		
		var ch=element.value.charAt(i);
		
		if (!( ( ch>='a' && ch<='z' ) || ( ch>='A' && ch<='Z' ) || ( ch>='0' && ch<='9' ) || ch=='`' || ch=='¬' || ch=='!' || ch=='"' || ch=='£' || ch=='$' || ch=='%' || ch=='^' || ch=='&' || ch=='*' || ch=='(' || ch==')' || ch=='_' || ch=='-' || ch=='+' || ch=='=' || ch=='{' || ch=='[' || ch=='}' || ch==']' || ch==':' || ch==';' || ch=='@' || ch=='\'' || ch=='#' || ch=='~' || ch=='?' || ch=='/' || ch=='>' || ch=='.' || ch=='<' || ch==',' || ch=='\\' ))
		{
			element.focus();
			element.select();
			alert(PasswordNotValid);
			return false;
// || ch=='|' - we no longer want to accept this character in the password
		}
	}
	return true;;
}

function TandCcheck(element) {
	if (!(element.checked))	{
		alert("Terms and Conditions\n\nYour order will not be accepted if you do not agree to our Terms\nand Conditions. Please tick the check box to accept the terms.");
		return false;
	}
	return true;
}

function cardSelected(f)
{
	f.amount_below_limit.value = "card_selected";  // one of the radio button is clicked
	return true;
}

function Submitorderform(f)
{
	if (!ValidatePassword(f.M_sub_password))
		return false;

	if ((f.M_sub_password.value.length < 6) || (f.M_sub_password.value.length > 8))
	{
		f.M_sub_password.focus();
		f.M_sub_password.select();
		alert("Password must be between six and eight characters long.");
		return false;
	}

	if (f.M_sub_password.value != f.M_confirm_sub_password.value)
	{
		f.M_confirm_sub_password.focus();
		f.M_confirm_sub_password.select();
		alert("Password confirmation did not\nmatch.  Please re-enter.");
		return false;
	}
	
//	if ((f.amount_below_limit) && ((f.paymentType != "VISA") || (f.paymentType != "MSCD") || (f.paymentType != "VISP") || (f.paymentType != "JCB")))
	if (f.amount_below_limit.value == "yes") // && (!(f.paymentType.checked)))
	{
		alert("Please select credit card type");
		return false;
	}
//	alert("Debug line= proceed OK");
	f.submit();
}


// Browser check

function BrowserChecker() {

	var useragent = navigator.userAgent;
	var bName = (useragent.indexOf('Opera') > -1) ? 'Opera' : navigator.appName;

	var pos = useragent.indexOf('MSIE');
	if (pos > -1) {
		bVer = useragent.substring(pos + 5);
		var pos = bVer.indexOf(';');
		var bVer = bVer.substring(0,pos);
	}

	var pos = useragent.indexOf('Opera');
	if (pos > -1) {
		bVer = useragent.substring(pos + 6);
		var pos = bVer.indexOf(' ');
		var bVer = bVer.substring(0, pos);
	}

	if (bName == "Netscape") {
		var bVer = useragent.substring(8);
		var pos = bVer.indexOf(' ');
		var bVer = bVer.substring(0, pos);
	}
	if (bName == "Netscape" && parseInt(navigator.appVersion) >= 5) {
		var pos = useragent.lastIndexOf('/');
		var bVer = useragent.substring(pos + 1);
	}
	if (bVer < 5) {
		return false;
	} else {
		return true;
	}
// document.writeln('<b>Browser Name: </b>' + bName + '<br>');
// document.writeln('<b>Browser Version: </b>' + bVer + '<br>');
}


// Domain characters check

function submit_domain_form() {
	var form = document.domainForm;
	var cnt,checkchar,errorcnt=0, overrmes, errorpltext="", dotignore=1, errorblock1=0, errorblock2=0;
	
	var errorarray = new Array();
	var tldarray = [".com",".net",".info",".biz",".org",".uk",".me",".co",".ca",".tv",".us",".cn",".au"];
//	var webw = "www.";

	form.domain.value=form.domain.value.toLowerCase();

	for(cnt=0; cnt < tldarray.length; cnt++) {
		if(form.domain.value.indexOf(tldarray[cnt]) !=-1) {
			form.domain.value=form.domain.value.replace(tldarray[cnt],"");
		}
	}
//	if(form.domain.value.indexOf('www.') !=-1) {
//		form.domain.value=form.domain.value.replace('www.','');
//	}
//	wwind = form.domain.value.lastindexOf("www.");
//	if (wwind != -1) {
//		form.domain.value=wwind;
//	}

	if(form.domain.value.length == 0) {
		errorarray[errorcnt] = "No domain name entered.\n\n";
		errorcnt++;
	} else if(form.domain.value.length < 2) {
		errorarray[errorcnt] = "Your domain is less than 2 characters.\n\n";
		errorcnt++;
	} else if(form.domain.value.length < 3) {
		firstchar  = form.domain.value.charAt(0);
		secondchar = form.domain.value.charAt(1);
		if((!firstchar.match(/[0-9]/)) && (!secondchar.match(/[0-9]/))) {
			errorarray[errorcnt] = "Two character domain must contain at least one number (0-9).\n     Or choose a domain name with more than two characters.\n\n";
			errorcnt++;
		}
	}

	for(cnt=0; cnt < form.domain.value.length; cnt++) {
		checkchar = form.domain.value.charAt(cnt);

		if(!checkchar.match(/[a-zA-Z0-9\-]/) && errorblock1==0) {
			if(checkchar.match(/\./) && dotignore==1) {
				dotignore=0;
			} else {
				errorblock1=1;
				errorarray[errorcnt]="Domain names can only contain numbers (0-9), letters (a-z) or hyphens (-).\n     No blank spaces, dots or other characters.\n\n";	
				errorcnt++;
			}
		}

		if((cnt==form.domain.value.length-1 || cnt==0) && errorblock2==0) {
			if(checkchar.match(/-/)) {
				errorblock2=1;
				errorarray[errorcnt]="Domains cannot start or end with a hyphen (-).\n\n";
				errorcnt++;
			}
		}
	}

	if(errorcnt > 0) {
		if(errorcnt>1)
		{
			errorpltext="s";
		}

//		overrmes="You have " + errorcnt + " error" + errorpltext + " in your search:\n\n";
		overrmes="You searched for: " + form.domain.value + "\n\nPlease correct the following errors in your search:\n\n";
		
		for(cnt=0;cnt<errorarray.length;cnt++)
		{
			overrmes = overrmes + (cnt+1) + ". " + errorarray[cnt];
		}

		form.domain.focus();
		form.domain.select();
		alert(overrmes);
		return false;
	} else {
//		alert("good");
		return true;
	}
}

function login_form(form) {
	var message = "";
	if (form.thisaction.value == "lostpass") {
		if ((form.domain.value.indexOf(" ") != -1) || (form.domain.value.length < 6) || (form.domain.value.indexOf(".") == -1)) {
			message = "Domain name you entered is not correct. Please check and try again. It should contain no spaces.\nThe domain must be currently hosted with 49p Biz.\n";
			form.domain.focus();
			form.domain.select();
		}
	} else {
		if ((form.userid.value.indexOf(" ") != -1) || (form.userid.value.length < 10)) {
			message = "Account reference you entered is not valid, or it is not complete.\nPlease check and try again. It should contain no spaces.\n";
			form.userid.focus();
			form.userid.select();
		} else if ((form.password.value.indexOf(" ") != -1) || (form.password.value.length < 6)) {
			message = "Password you entered is not valid.\nPlease check and try again. It should contain no spaces.\n";
			form.password.focus();
			form.password.select();
		}
	}
	if (message) {
		alert(message);
		return false;
	} else {
		return true; //form.submit();
	}
}