var tr = true;
var item = new Array();
var svbullet = 0;

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function

function trim(TRIM_VALUE)
{
 if(TRIM_VALUE.length < 1)
  return"";
 TRIM_VALUE = RTrim(TRIM_VALUE);
 TRIM_VALUE = LTrim(TRIM_VALUE);
 if(TRIM_VALUE=="")
  return "";
 else
  return TRIM_VALUE;
} //End Function

function emailvalid(a)
{
 a = trim(a);
 if (a.length == 0) 
  return true; 
  // check for space in first position
 if (a.charAt(0) == " ")
  return false;
 // check for illegal chars
 myRE = new RegExp('[-[{}\|"£\$%\^&*#+/<>=:;\(\)¬` \n\r\t]',"i"); 
 r = a.match(myRE);
 if (r !== null)
  return false;
 myRE = new RegExp('\]',"i"); 
 r = a.match(myRE);
 if (r !== null)
  return false;
 myRE = new RegExp('\\\\',"i"); 
 r = a.match(myRE);
 if (r !== null)
  return false;
 // check for dot in first position  
 if (a.charAt(0) == ".")
  return false;
 // check for dot in last position
 if (a[a.length-1] == ".")  
  return false;
 // check for @ in first or last position
 if (a.charAt(0) == "@")
  return false;
 if (a[a.length-1] == "@")  
  return false;
 // check that last char is alpha 
 myRE = new RegExp('[a-z]$',"i"); 
 r = a.match(myRE);
 if (r == null)
   return false;
 // check for at least one dot
 j = 0;
 for (i=0;i<a.length;i++)
 {
 // alert(a);
 // alert( 'here, ' + i + ', ' + a[i]);
  if (a.charAt(i) == ".") j++;
 }  
 if (j == 0)
 {
  //alert (j);
  return false;   
 }// check for only one @
 j = 0;
 for (i=0;i<a.length;i++)
  if (a.charAt(i) == "@") j++; 
 if (j !== 1)
  return false;  
 // if all tests passed return true  
 return true;
}
function ssr()
{
 window.location.replace("index.php");   
}

function bck()
{
 history.go(-1);
}
function svv(a,b)
{
 document.getElementById(a).innerHTML = b;
}
function sv(a,b) // writes 'b' to 'a' named div field returns old value
{
x = document.getElementById(a).firstChild.nodeValue;
 svbullet++;
if (svbullet == 1)
{
 document.getElementById(a).innerHTML = "Please correct the following Errors: -<br>" + svbullet + ") " + b;
}
else
 document.getElementById(a).innerHTML = document.getElementById(a).innerHTML + "<br>" + svbullet + ") " + b;
//document.getElementById(a).appendChild(p);
return x;
}
function it(a,b) // writes 'b' to 'a' named div field returns old value
{
alert(b);
x = document.getElementById(a).innertext;
alert(x);
document.getElementById(a).innertext = b;
return x;
}
function info(b) // writes b to the cart info line at the top of the page
{
a = 'info1';
document.getElementById('infoimg').src = 'cart2.gif';
sv(a,b);
setTimeout("bs()",5000); 	 
}
function dr(a,b) // deletes a row
{
//alert('delete row ' + a);
//alert(document.getElementById('r'+a).sourceIndex);
//alert(document.all[document.getElementById('r'+a).sourceIndex + 1].outerHTML);
st(a,0); // set the line price to zero and update the total
document.all[document.getElementById('r'+a).sourceIndex + 1].outerText = '';
info(b + ' removed from shopping basket'); 
c = '|' + 'deleterow' + '~' + a;
item.push(c);
c = item.join('');
document.myform.basket.value = c.slice(1);	 
}
function eb()
{
document.myform.basket.value = 'emptybasket';	 
document.myform.mode.value='basket';
document.myform.action=r;
document.myform.submit();
}
function sd(a,b) // writes the alloc doamin
{
// format the basket variable items
c = '|' + 'allocdomain' + '~' + a + '~' + b;
item.push(c);
c = item.join('');
document.myform.basket.value = c.slice(1);	 
}
function st(a,b) // writes to the line price and updates grand 'tot'
{
var t = 1;
var x = b * 1;
y = Number(x).toFixed(2);
v = sv('t'+a,y); // update line price
t = sv('tot',0); // get current tot
//alert(t);
t = t - v;
t = (t + x);
t = Number(t).toFixed(2);
//alert(t);
t = sv('tot',t);
// format the basket variable items
c = '|' + 'rowvalue' + '~' + a + '~' + x;
item.push(c);
c = item.join('');
document.myform.basket.value = c.slice(1);	 
}
function bs() // blanks the info field at the top of the page
{
document.getElementById('infoimg').src = 'blank.gif';	  
sv('info1',' '); 
}
function al(a)
{
 sv('info2',a);
}
function bss() // blanks the info field at the top of the page
{
 sv('info2',' '); 
}
function lg(a,b,d) // adds item to basket. code (b) and descrip (d) are packed end to end in basket variable 
{ // if a is false, a match is sought in the items array, and then deleted 
//c.className='selected';
c = '|' + b + '~' + d;
if (a) {
item.push(c);
}
else {
found = -1;
for (i = 0; i < item.length; i++) {
if (item[i] == c) {
item[i] = '' } }	
}
c = item.join('');
document.myform.basket.value = c.slice(1);
if (a)
info(d + ' added to shopping basket')
else
info(d + ' removed from shopping basket'); 
//document.getElementById('info1').firstChild.nodeValue = d + ' added to shopping basket';
// alert(' Web Hosting ' + b + '\nAdded to shopping basket');
//alert(document.myform.basket.value);
}
function logg(a,b) // adds a single decription item to basket (not a domain) a is true
{
lg(a,b,b); 
}
function lt(a)
{
logg(true,a); // adds an item that doesn't have the true field
}
function ss(a) // goto page type a. reset domain search
{
document.myform.mode.value=a;
document.myform.submit();
}
function ssp(a,b,c) // goto page type a. reset domain search
{
document.myform.mode.value=a;
document.myform.param.value=b;
document.myform.param2.value=c;
document.myform.submit();
}
function ssx(a)
{
 //alert('here');
 svv('info2','Now Processing Request - Please Wait.');
 ss(a);
}
function vpass(a) // goto page type a. reset domain search
{
 if (document.myform.upass1.value != document.myform.upass2.value)
 {
  sv('info2','** Error: The two entered Passwords must match **');
  setTimeout("bss()",5000); 	 
 }
 else
 {   
  document.myform.mode.value=a;
  document.myform.action=r;
  document.myform.submit();
 }
}
function cl(a,b)
{
 document.myform.lan.value = a;
 document.myform.mode.value = b;
 document.myform.action=r;
 document.myform.submit();
}
function sss(a,b) // goto page type a. reset domain search
{
 if (a == '')
  alert('Enter page name')
 else
 {
// document.myform.mode.value='<?php echo $mode >';
 document.myform.wapac.value=b;
 document.myform.tpn.value=a;
 document.myform.action=r;
 document.myform.submit();
 }
}
function sst(a,b) // goto page type a. reset domain search
{
 if (a == '')
  alert('Enter page name')
 else
 {
 document.myform.mode.value='design';
 document.myform.wapac.value=b;
 document.myform.tpn.value=a;
 document.myform.action=r;
 document.myform.submit();
 }
}
function ssd(a,b) // goto page type a. reset domain search
{
document.myform.tpn.value=document.myform.tpnn.options[document.myform.tpnn.selectedIndex].text;
document.myform.mode.value=a;
document.myform.wapac.value=b;
document.myform.action=r;
document.myform.submit();
}
function ssc(a) // goto page type a. reset domain search
{
document.myform.tpn.value=document.myform.tpnn.options[document.myform.tpnn.selectedIndex].text;
document.myform.mode.value=a;
document.myform.action=r;
document.myform.submit();
}
function validate()
{
if (document.myform.lastname.value.length < 2)
{ alert('Please enter a Last Name'); return;}
if (document.myform.address1.value.length < 2)
{ alert('Please enter an Address'); return;}
if (document.myform.town.value.length < 2)
{ alert('Please enter a Town/City'); return;}
if (document.myform.postcode.value.length < 2)
{ alert('Please enter a Postcode/ZIP'); return;}
if (document.myform.country.value.length < 2)
{ alert('Please enter a Country'); return;}
if (document.myform.email.value.length < 2)
{ alert('Please enter an Email Address'); return;}
if (!document.myform.terms.checked)
{ alert('Please check the box to indicate you have read the Acceptable Use Policy'); return;}
ss('paypal');
}


function validate2()
{
e = false;
svbullet = 0;
//alert('here');
if (document.myform.lastname.value.length < 2)
{ al('You must enter a Last Name'); e=true;}
if (document.myform.gender.selectedIndex == 0)
{ al('You must select a Gender'); e=true;}
if (document.myform.un.value.length < 2)
{ al('You must enter an Account name'); e=true;}
if (document.myform.pw.value.length < 2)
{ al('You must enter a Password'); e=true;}
if (document.myform.password2.value.length < 2)
{ al('You must enter the same Password twice'); e=true;}
if (document.myform.pw.value !== document.myform.password2.value)
{ al('Password does not match in both entries'); e=true;}
if (!emailvalid(document.myform.email.value))
{ al('The Email Address is not a valid format'); e=true;}
if (document.myform.email.value.length < 2)
{ al('You must enter an Email Address'); e=true;}
//if (!document.myform.terms.checked)
//{ al('** Error: You must check the box to indicate you have read the Acceptable Use Policy **'); return;}
if (!e) 
{
 ssx('newaccount');
}
}
function validate3()
{
e = false;
svbullet = 0;
//alert('here');
if (document.myform.lastname.value.length < 2)
{ al('You must enter a Last Name'); e=true;}
if (document.myform.gender.selectedIndex == 0)
{ al('You must select a Gender'); e=true;}
if (document.myform.un.value.length < 2)
{ al('You must enter an Account name'); e=true;}
if (document.myform.pw.value.length < 2)
{ al('You must enter your existing Password'); e=true;}
if (document.myform.pw2.value !== document.myform.pw3.value)
{ al('New Password does not match in both entries'); e=true;}
if (!emailvalid(document.myform.email.value))
{ al('The Email Address is not a valid format'); e=true;}
if (document.myform.email.value.length < 2)
{ al('You must enter an Email Address'); e=true;}
//if (!document.myform.terms.checked)
//{ al('** Error: You must check the box to indicate you have read the Acceptable Use Policy **'); return;}
if (!e) 
{
 ssx('newaccount');
}
}function paypal(a) // goto page type a. reset domain search
{
document.myform.action='https://www.paypal.com/cgi-bin/webscr';
document.myform.submit();
}	
function ss1(a) // goto page type  a. leave last domain search in box
{
document.myform.mode.value=a;
document.myform.action=r;
document.myform.submit();
}
function ud()
{
document.myform.basket.value = '';
document.myform.mode.value='basket';
document.myform.action=r;
document.myform.submit();
}
function upg(a)
{
document.myform.upgr.value = a;
document.myform.mode.value='paypal';
document.myform.action=r;
document.myform.submit();
}
