//ecscript - copyright Evolution Creative 2004.
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function P7_Snap() { //v2.67 by PVII
 var g,x,y,ox,bx,oy,p,tx,a,b,k,d,da,e,el,tw,q0,xx,yy,w1,pa='px',args=P7_Snap.arguments;a=parseInt(a);
 
 if(document.layers||window.opera){pa='';}
 
 for(k=0;k<(args.length);k+=4){
 	if((g=MM_findObj(args[k]))!=null){
		if((el=MM_findObj(args[k+1]))!=null){
 		a=parseInt(args[k+2]);b=parseInt(args[k+3]);x=0;y=0;ox=0;oy=0;p="";tx=1;
 		da="document.all['"+args[k]+"']";
			if(document.getElementById){
 			d="document.getElementsByName('"+args[k]+"')[0]";
				if(!eval(d)){
 				d="document.getElementById('"+args[k]+"')";
					if(!eval(d)){d=da;}
				}
 	}else if(document.all){d=da;}if(document.all||document.getElementById){
		while(tx==1){
 		p+=".offsetParent";
		if(eval(d+p)){x+=parseInt(eval(d+p+".offsetLeft"));y+=parseInt(eval(d+p+".offsetTop"));
 		}
		else{tx=0;}
	}
	
	ox=parseInt(g.offsetLeft);oy=parseInt(g.offsetTop);tw=x+ox+y+oy;
 if(tw==0||(navigator.appVersion.indexOf("MSIE 4")>-1 && navigator.appVersion.indexOf("Mac")>-1)){
  ox=0;oy=0;if(g.style.left){x=parseInt(g.style.left);y=parseInt(g.style.top);}else{
  w1=parseInt(el.style.width);bx=(a<0)?-5-w1:-10;a=(Math.abs(a)<1000)?0:a;b=(Math.abs(b)<1000)?0:b;
  x=document.body.scrollLeft+event.clientX+bx;y=document.body.scrollTop+event.clientY;}}
 }else if(document.layers){x=g.x;y=g.y;q0=document.layers,dd="";for(var s=0;s<q0.length;s++){
  dd='document.'+q0[s].name;if(eval(dd+'.document.'+args[k])){x+=eval(dd+'.left');y+=eval(dd+'.top');
  break;}}}e=(document.layers)?el:el.style;xx=parseInt(x+ox+a),yy=parseInt(y+oy+b);
 if(navigator.appVersion.indexOf("MSIE 5")>-1 && navigator.appVersion.indexOf("Mac")>-1){
  xx+=parseInt(document.body.leftMargin);yy+=parseInt(document.body.topMargin);}
 e.left=xx+pa;e.top=yy+pa;showFloatMenuAt('menu2f87',xx,yy +320);}}}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function addUpWSH() {
	if (document.forms[0].hosting.value != '0') {
	document.forms[0].domain.disabled = 0;
	var total = parseFloat(document.forms[0].hosting.value) + parseFloat(document.forms[0].domain.value);
	}
	else {
		document.forms[0].domain.disabled = 1;
		document.forms[0].domain.value = '0';
		var total = 0;
	}
	total = aRound(total);
	document.getElementById('wshTotal').innerHTML = total;
	doTotals();
}

function addUpWSD() {
	if (document.forms[0].wsdYesNo.value != '0') {
		document.forms[0].wsdPageCount.disabled = 0;
		document.forms[0].wsdDb.disabled = 0;
		document.forms[0].wsdItemCount.disabled = 0;
		document.forms[0].wsdEcomm.disabled = 0;
		
		//web pages £50 per page
		if (document.forms[0].wsdPageCount.value == '') {
			var pages = 0;
		}
		else {
			var pages = parseFloat(document.forms[0].wsdPageCount.value);
			if (pages == 0) {
				alert('your site needs at least one page');
				document.forms[0].wsdPageCount.value = '1';
			}
			pages = (pages * 50);
		}

		if (document.forms[0].wsdDb.value != '0') {
			document.forms[0].wsdItemCount.disabled = 0;
			document.forms[0].wsdImageCount.disabled = 0;
			document.forms[0].wsdAdmin.disabled = 0;
		//database items £1 each
			if (document.forms[0].wsdItemCount.value == '') {
				var items = 0;
			}
			else {var items = parseFloat(document.forms[0].wsdItemCount.value);
				if (items > 0) {
					items = items + 150;
					//item images .50p each + £150 setup fee
					if (document.forms[0].wsdImageCount.value == '') {
						var images = 0;
					}
					else {
						var images = parseFloat(document.forms[0].wsdImageCount.value);
						if (images > 0) {
							var itc = (items -150) / 2;
							images = (images * itc) + 150;
						}
					}
			}
			else {
				images = 0;
				document.forms[0].wsdImageCount.value = '0';
			}
		}
	}
	else {
		var images = 0;
		var items = 0;
		document.forms[0].wsdItemCount.disabled = 1;
		document.forms[0].wsdImageCount.disabled = 1;
		document.forms[0].wsdAdmin.disabled = 1;
		document.forms[0].wsdItemCount.value = '0';
		document.forms[0].wsdImageCount.value = '0';
		document.forms[0].wsdAdmin.value = '0';
	}
	var total = pages + parseFloat(document.forms[0].wsdDb.value) + parseFloat(document.forms[0].wsdAdmin.value) + parseFloat(document.forms[0].wsdEcomm.value) + images + items;
	total = aRound(total);
	document.getElementById('wsdTotal').innerHTML = total;
	}
	else {
	document.forms[0].wsdPageCount.disabled = 1;
	document.forms[0].wsdDb.disabled = 1;
	document.forms[0].wsdItemCount.disabled = 1;
	document.forms[0].wsdImageCount.disabled = 1;
	document.forms[0].wsdAdmin.disabled = 1;
	document.forms[0].wsdEcomm.disabled = 1;
	document.forms[0].wsdPageCount.value = '5';
	document.forms[0].wsdDb.value = '0';
	document.forms[0].wsdItemCount.value = '0';
	document.forms[0].wsdImageCount.value = '0';
	document.forms[0].wsdAdmin.value = '0';
	document.forms[0].wsdEcomm.value = '0';
	document.getElementById('wsdTotal').innerHTML = '0.00';
	}
	doTotals();
}

function addUpWSP() {
	if (document.forms[0].wspYesNo.value != '0') {
		document.forms[0].wspReview.disabled = 0;
	}
	else {
		document.forms[0].wspReview.disabled = 1;
		document.forms[0].wspReview.value = '0';
	}
	var total = parseInt(document.forms[0].wspYesNo.value) + parseFloat(document.forms[0].wspReview.value);
	total = aRound(total);
	document.getElementById('wspTotal').innerHTML = total;
	doTotals();
}

function addUpEmail() {
	if (document.forms[0].emailCount.value == '0' || isNaN(parseFloat(document.forms[0].emailCount.value)) ) {
		document.forms[0].emailSpam.disabled = 1;
		document.forms[0].emailSpam.value = '0';
		var ecount = 0;
	}
	else {
		document.forms[0].emailSpam.disabled = 0;
		var ecount = parseInt(document.forms[0].emailCount.value) * 10
	}
	var total = ecount + parseFloat(document.forms[0].emailSpam.value);
	total = aRound(total);
	document.getElementById('emailTotal').innerHTML = total;
	doTotals();
}

function addUpNET() {
	if (document.forms[0].netBB.value == '0') {
		document.forms[0].netInstall.disabled = 1;
		document.forms[0].netInstall.value = '0';
		var BBsetup = 0;
	}
	else {
		document.forms[0].netInstall.disabled = 0;
		var BBsetup = 50;
	}
	//£50 setup
	var total = parseFloat(document.forms[0].netBB.value) + parseFloat(document.forms[0].netInstall.value) + BBsetup;
	total = aRound(total);
	document.getElementById('netTotal').innerHTML = total;
	doTotals();
}

function doTotals() {
	var wshT = parseFloat(document.getElementById('wshTotal').innerHTML);
	var wsdT = parseFloat(document.getElementById('wsdTotal').innerHTML);
	var wspT = parseFloat(document.getElementById('wspTotal').innerHTML);
	var emailT = parseFloat(document.getElementById('emailTotal').innerHTML);
	var netT = parseFloat(document.getElementById('netTotal').innerHTML);
	var total = aRound(wshT + wsdT + wspT + emailT + netT);
	document.getElementById('Total').innerHTML = fComma(total);
	
	var mWsp = 0.00;
	
	if (document.forms[0].netBB.value != '0') {
		var mBB = parseFloat(document.forms[0].netBB.value);
	}
	else {
		var mBB = 0.00;
	}
	
	var mtotal = aRound(mWsp + mBB);
	document.getElementById('monthlyTotal').innerHTML = fComma(mtotal);
	
	if (document.forms[0].hosting.value != '0') {
	var y2WshH = parseFloat(document.forms[0].hosting.value);}
	else {var y2WshH = 0.00;}
	
	if (document.forms[0].domain.value != '0') {
	var y2WshD = parseFloat(document.forms[0].domain.value);}
	else {var y2WshD = 0.00;}
	
	if (document.forms[0].wspYesNo.value != '0') {
	var y2Wsp = parseFloat(document.forms[0].wspReview.value); }
	else {var y2Wsp = 0.00;}
	
	if (document.forms[0].emailSpam.value != '0') {
	var y2emailSpam = parseFloat(document.forms[0].emailSpam.value);}
	else {var y2emailSpam = 0.00;}
	
	var y2total = aRound(y2WshH + y2WshD + y2Wsp + y2emailSpam);
	document.getElementById('year2Total').innerHTML = fComma(y2total);
}

function aRound(X) {
	var S, P
  S = String((Math.round(X * 100)) / 100);
  P = S.length-3;
  if (S.charAt(P) != '.') S += (S.charAt(++P) == '.') ? "0" : ".00";
  return S;
}

function fComma(SS) {
	var T='', S=String(SS), L=S.length-1, C, j, P = S.indexOf('.')-1
  if (P<0) P=L
  for (j=0; j<=L; j++) {
    T+=C=S.charAt(j)
    if ((j < P) && ((P-j)%3 == 0) && (C != '-')) T+=',' 
	}
  return T;
}

function EmailValidate(form_id,email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.forms[form_id].elements[email].value;
   if(reg.test(address) == false) {
      return false;
   }
}

function testOK() {
	var isok = true;
	if (document.forms[0].subName.value == '') {
		alert('Please enter your Name');		
		isok = false;
	}
	else if (document.forms[0].subPhone.value == '') {
		alert('Please enter a contact Phone number');		
		isok = false;
	}
	else if (EmailValidate(0,'subEmail') == false) {
		alert('Please enter a valid email address');		
		isok = false;
	}
	else if (document.getElementById('Total').innerHTML == '0.00') {
			alert('You do not appear to have selected any options');
			isok = false;
	}
	if (isok == true) {
		document.forms[0].submit();
		alert('Thanks, your enquiry was sent. We\'ll get back to you as soon as possible');
	}
}

function genemail(address) {
	//function to hide the email addresses from the site
	var mailto = 'mailto:'+address+'@jesk.co.uk?subject=Web Site Enquiry';
	win = window.open(mailto,'emailWindow');
	if (win && win.open &&!win.closed) win.close(); 
}