<!--
var once_here = false;

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
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_findObj(n, d) { //v4.0
  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 && document.getElementById) 
  	x=document.getElementById(n); 
  return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
  HideLayer('PCTech');
}

function NewWindow(mypage, myname, w, h) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	//winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=no,resizable=no,fullscreen=no,toolbar=no,menubar=no,status=no,location=no,directories=no'
	winprops = 'height='+h+',width='+w+',fullscreen=yes'
//	alert (winprops);
	win = window.open(mypage, myname, winprops)
	win.blur
	win.resizeTo( w, h );
	win.MoveTo( winl, wint );
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function ShowProdWindow(mypage, myname, products_id, w, h) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	var prod_href = mypage + products_id;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=no,resizable=no,fullscreen=no,toolbar=no,menubar=no,status=no'
	if ( products_id != 999)  
	{
		win = window.open(prod_href, myname, winprops);
		if (parseInt(navigator.appVersion) >= 4) 
		{ 
			win.window.focus(); 
		}
	}
}

function MenuStuff() {
	var d=document;
	d.MM_p=new Array();
	d.MM_p[0]=new Image;
	d.MM_p[0].src='images/home_but_on.gif';
	d.MM_p[1]=new Image;
	d.MM_p[1].src='images/products_but_on.gif';
	d.MM_p[2]=new Image;
	d.MM_p[2].src='images/support_but_on.gif';
	d.MM_p[3]=new Image;
	d.MM_p[3].src='images/about_but_on.gif';
}

function ShowPCTech()
{
	HideLayer('Content');
	HideLayer('PCTech');
	var obj = document.getElementById('ContentArea');
	var newX = findPosX(obj);
	var newY = findPosY(obj);
	var x = new getObj('PCTech');
	x.style.top = newY;
	x.style.left = newX;
	ShowLayer('PCTech');
}

function ShowContent()
{
	HideLayer('Content');
	HideLayer('PCTech');
	var obj = document.getElementById('ContentArea');
	var newX = findPosX(obj);
	var newY = findPosY(obj);
	var x = new getObj('Content');
	x.style.top = newY;
	x.style.left = newX;
	ShowLayer('Content');
}

function HideLayer(lyr)
{
	var x = new getObj(lyr)
	x.style.visibility = 'hidden'
}
function ShowLayer(lyr)
{
	var x = new getObj(lyr)
	x.style.visibility = 'visible'
}

function setLayer(obj,lyr)
{
	HideLayer('APPCPUdrop');
	HideLayer('MAGECPUdrop');
	HideLayer('SORCCPUdrop');
	var newX = findPosX(obj);
	var newY = findPosY(obj);
	var x = new getObj(lyr);
	x.style.top = newY - 10;
	x.style.left = newX + 108;
	x.style.visibility = 'visible'
}

function setLayerInfo(obj,lyr)
{
	HideLayer('DEFInfo');
	HideLayer('APPInfo');
	HideLayer('MAGEInfo');
	HideLayer('SORCInfo');
	var newX = findPosX(obj);
	var newY = findPosY(obj);
	var x = new getObj(lyr);
	x.style.top = newY;
	x.style.left = newX + 10;
	x.style.visibility = 'visible'
}

function findPosX(obj)
{

	var curleft = 0;
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curtop += obj.y;
	return curtop;
}

function getObj(name)
{
 if (document.getElementById)
 {
	   this.obj = document.getElementById(name);
	   this.style = document.getElementById(name).style;
 } 
 else if (document.all)
 {
	   this.obj = document.all[name];
	   this.style = document.all[name].style;
 }
 else if (document.layers)
 {
	   if (document.layers[name])
	   {
	   	this.obj = document.layers[name];
	   	this.style = document.layers[name];
	   }
	   else
	   {
	    this.obj = document.layers.testP.layers[name];
	    this.style = document.layers.testP.layers[name];
	   }
 }
}

function round(number,decimals) {
// rounds number to X decimal places, defaults to 2
    decimals = (!decimals ? 2 : decimals);
    return Math.floor(number*Math.pow(10,decimals))/Math.pow(10,decimals);
}

function ChangeinnerHTML(layerid, text) {
    var statement = '';
    
    if (document.all) 
	  statement += "document.all['" + layerid + "'].innerHTML = '" + text + "';";	     
    else if (document.getElementById)           
	  statement += "document.getElementById('" + layerid + "').innerHTML = '" + text + "';"; 
    
    eval(statement);    
}

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function UpdatePrice( product, products_id, real_product_id ) {
	// cat array consts
	var CatNumRows = 0, CatDefRow = 1, CatArray = 2, OrigCatDefRow = 3;
	// product array consts
	var ProductId = 0, ProductDesc = 1, ProductPrice = 2, ProductDef =3;
	var calctotalprice = totalprice;
	// get default value row num
	var defrow = technocat[product][CatDefRow];
	// get default item price
	var def_product_price = (technocat[product][CatArray][defrow][ProductPrice]);
//	alert (def_product_price);
	// get choosen product price
	var new_product_price = (technocat[product][CatArray][products_id][ProductPrice]);
//	alert (new_product_price);

	switch ( product ) {
	case 'ram':
		var qty = document.forms[0].ram_qty.value;
		calctotalprice += (new_product_price * qty) - (def_product_price * qty);
		break;
	case 'hdd1':
		var qty = document.forms[0].hdd1_qty.value;
		calctotalprice += (new_product_price * qty) - (def_product_price * qty);
		break;
	case 'hdd2':
		var qty = document.forms[0].hdd2_qty.value;
		calctotalprice += (new_product_price * qty) - (def_product_price * qty);
		break;
	default:
		calctotalprice += new_product_price - def_product_price;
	}	
//	alert (calctotalprice);
	// write new def product ie selected product
	technocat[product][CatDefRow] = products_id;
	ChangeinnerHTML ( 'totalpricetop', formatCurrency(round(calctotalprice,2) ) );
	ChangeinnerHTML ( 'totalpricebot', formatCurrency(round(calctotalprice,2) ) );
	totalprice = round(calctotalprice, 2);
	document.forms[0].totalpricesub.value = totalprice;
	// set def qty to 1 if used to be zero
	if ( product == 'ram' )
		if ( def_ram_qty == 0 ) {
			def_ram_qty++;
			document.forms[0].ram_qty.value = def_ram_qty;
		}
	if ( product == 'hdd1' )
		if ( def_hdd1_qty == 0 ) {
			def_hdd1_qty++;
			document.forms[0].hdd1_qty.value = def_hdd1_qty;
		}
	if ( product == 'hdd2' )
		if ( def_hdd2_qty == 0 ) {
			def_hdd2_qty++;
			document.forms[0].hdd2_qty.value = def_hdd2_qty;
		}	
}

function formatprices( ) {
	if ( once_here ) {
		var cpu_type = document.forms[0].cpu_select.options[document.forms[0].cpu_select.selectedIndex].text;
		var system_type = document.forms[0].system_select.options[document.forms[0].system_select.selectedIndex].text;
		document.location = 'customise_system.php?system_type=' + system_type + '&cpu_type=' + cpu_type;
		once_here = false;	
	}
	ChangeinnerHTML ( 'totalpricetop', formatCurrency(round(totalprice,2) ) );
	ChangeinnerHTML ( 'totalpricebot', formatCurrency(round(totalprice,2) ) );
}

function UpdateRamPrice( product_name ) {
	var qty = document.forms[0].ram_qty.value;
	var maxqty;

	if ( product_name.indexOf( 'TWINX' , 0 ) == -1 )
		maxqty = 4;
	else
		maxqty = 2;
		
	if ( qty > maxqty ) {
		document.forms[0].ram_qty.value = maxqty;
		qty = maxqty;
		alert ('Maximum ram slots for this motherboard is ' + maxqty);
	}
	if ( qty == 0 ) {
		document.forms[0].ram_qty.value = 1;
		qty = 1;
		alert ('System must have at least one memory module');
	}
	// get ram price
	var CatNumRows = 0, CatDefRow = 1, CatArray = 2, OrigCatDefRow = 3;
	// product array consts
	var ProductId = 0, ProductDesc = 1, ProductPrice = 2, ProductDef =3;
	var calctotalprice = totalprice;
	// get default value row num
	var defrow = technocat["ram"][CatDefRow];
	// get item price
	var product_price = (technocat["ram"][CatArray][defrow][ProductPrice]);
	// get ram cost * qty - cost * def_qty
	calctotalprice += (product_price * qty) - (product_price * def_ram_qty);
	// write new def ram qty 
	def_ram_qty = qty;
	ChangeinnerHTML ( 'totalpricetop', formatCurrency(round(calctotalprice,2) ) );
	ChangeinnerHTML ( 'totalpricebot', formatCurrency(round(calctotalprice,2) ) );
	totalprice = round(calctotalprice, 2);
	document.forms[0].totalpricesub.value = totalprice;
}

function UpdateHDD1Price( mainboard_name, product_name ) {
	var qty = document.forms[0].hdd1_qty.value;
	if ( product_name.indexOf("SATA") == -1 ) {
		if ( qty > 2 ) {
			document.forms[0].hdd1_qty.value = 2;
			qty = 2;
			alert ("Maximum HDD''s for this motherboard is 2 for the primary channel");
		}
	} else {
		if ( mainboard_name.indexOf("IC7-G") == -1 ) {
			if ( qty > 1 ) {
				document.forms[0].hdd1_qty.value = 1;
				qty = 1;
				alert ("Maximum SATA HDD''s for this motherboard is 1 for the primary channel");
			}	
		} else {		
			if ( qty > 2 ) {
				document.forms[0].hdd1_qty.value = 2;
				qty = 2;
				alert ("Maximum SATA HDD''s for this motherboard is 2 for the primary channel");
			}
		}
	} 
	// get hdd1 price
	var CatNumRows = 0, CatDefRow = 1, CatArray = 2, OrigCatDefRow = 3;
	// product array consts
	var ProductId = 0, ProductDesc = 1, ProductPrice = 2, ProductDef =3;
	var calctotalprice = totalprice;
	// get default value row num
	var defrow = technocat["hdd1"][CatDefRow];
	// get item price
	var product_price = (technocat["hdd1"][CatArray][defrow][ProductPrice]);
	// get hdd1 cost * qty - cost * def_qty
	calctotalprice += (product_price * qty) - (product_price * def_hdd1_qty);
	// write new def ram qty 
	def_hdd1_qty = qty;
	ChangeinnerHTML ( 'totalpricetop', formatCurrency(round(calctotalprice,2) ) );
	ChangeinnerHTML ( 'totalpricebot', formatCurrency(round(calctotalprice,2) ) );
	totalprice = round(calctotalprice, 2);
	document.forms[0].totalpricesub.value = totalprice;
	if ( def_hdd1_qty == 0 ) {
		document.forms[0].hdd1.selectedIndex = 0;
		technocat["hdd1"][CatDefRow] = 0;	
	}
}

function UpdateHDD2Price( mainboard_name, product_name ) {
	var qty = document.forms[0].hdd2_qty.value;
	if ( product_name.indexOf("SATA") == -1 ) {
		if ( qty > 2 ) {
			document.forms[0].hdd2_qty.value = 2;
			qty = 2;
			alert ("Maximum HDD''s for this motherboard is 2 for the secondary channel");
		}
	} else {
		if ( qty > 1 ) {
			document.forms[0].hdd2_qty.value = 1;
			qty = 1;
			alert ("Maximum HDD''s for this motherboard is 1 for the secondary channel");
		}	
	}
	// get hdd2 price
	var CatNumRows = 0, CatDefRow = 1, CatArray = 2, OrigCatDefRow = 3;
	// product array consts
	var ProductId = 0, ProductDesc = 1, ProductPrice = 2, ProductDef =3;
	var calctotalprice = totalprice;
	// get default value row num
	var defrow = technocat["hdd2"][CatDefRow];
	// get item price
	var product_price = (technocat["hdd2"][CatArray][defrow][ProductPrice]);
	// get hdd2 cost * qty - cost * def_qty
//	alert ( product_price );
	calctotalprice += (product_price * qty) - (product_price * def_hdd2_qty);
	// write new def ram qty 
	def_hdd2_qty = qty;
	ChangeinnerHTML ( 'totalpricetop', formatCurrency(round(calctotalprice,2) ) );
	ChangeinnerHTML ( 'totalpricebot', formatCurrency(round(calctotalprice,2) ) );
	totalprice = round(calctotalprice, 2);
	document.forms[0].totalpricesub.value = totalprice;
	if ( def_hdd2_qty == 0 ) {
		document.forms[0].hdd2.selectedIndex = 0;
		technocat["hdd2"][CatDefRow] = 0;	
	}
}

function ResetPrices( ) {
	if ( confirm("Are you sure you want to reset the price?") )
	{
		var cpu_type = document.forms[0].cpu_select.options[document.forms[0].cpu_select.selectedIndex].text;
		var system_type = document.forms[0].system_select.options[document.forms[0].system_select.selectedIndex].text;
		document.location = 'customise_system.php?system_type=' + system_type + '&cpu_type=' + cpu_type;
	}
}

function Submit( ) {
	document.forms[0].submit();	
}

function jumptosystempage( ) {

	var cpu_type = document.forms[0].cpu_select.options[document.forms[0].cpu_select.selectedIndex].text;
	var system_type = document.forms[0].system_select.options[document.forms[0].system_select.selectedIndex].text;
	document.location = 'customise_system.php?system_type=' + system_type + '&cpu_type=' + cpu_type;
	
}

function validateandsubmit() {
    var Sendit=confirm("Are you sure you want to send this order to Technomancer");
    if( !Sendit )
		return false;
		
	if ( document.forms[0].firstname.value == '' ) {
		alert ('Please enter your first name');
		document.forms[0].firstname.focus();
		return false;
	}
	if ( document.forms[0].surname.value == '' ) {
		alert ('Please enter your surname');	
		document.forms[0].surname.focus();
		return false;
	}
	if ( document.forms[0].address1.value == '' ) {
		alert ('Please enter your street address');	
		document.forms[0].address1.focus();
		return false;
	}
	if ( document.forms[0].city.value == '' ) {
		alert ('Please enter your city/suburb');	
		document.forms[0].city.focus();
		return false;
	}
	if ( document.forms[0].postcode.value == '' ) {
		alert ('Please enter your postcode');	
		document.forms[0].postcode.focus();
		return false;
	} else {
		if ( document.forms[0].postcode.value.length < 4 ) {
			alert ('Australian post codes are 4 digits long');
			document.forms[0].postcode.focus();
			return false;	
		}
	}
	if ( document.forms[0].telephone.value == '' ) {
		alert ('Please enter your telephone ');	
		document.forms[0].telephone.focus();
		return false;
	} else {
		if ( document.forms[0].telephone.value.length > 8 || document.forms[0].telephone.value.length < 8 ) {
			alert ('Australian telephone numbers must be 8 digits long');
			document.forms[0].telephone.focus();
			return false;
		}
	}
	if ( document.forms[0].email.value == '' ) {
		alert ('Please enter your email address');	
		document.forms[0].email.focus();
		return false;
	} else {
		if ( !emailcheck( document.forms[0].email.value ) ) {
			alert ('Please enter a valid email address');
			document.forms[0].email.focus();
			return false;
		} 
	}
	if ( document.forms[0].comments.value.length > 255 ) {
		alert ('Comments can only be 255 characters long\nPlease remove ' + (document.forms[0].comments.value.length - 255) + ' characters');
		document.forms[0].comments.focus();
		return false;
	}
	document.forms[0].submit();
	return true;
}

function emailcheck ( emailStr ) {


var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);

if (matchArray==null) {
//	alert("Email address seems incorrect (check @ and .'s)");
	return false;
}
var user=matchArray[1];
var domain=matchArray[2];

for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
//		alert("Ths username contains invalid characters.");
		return false;
   }
}
for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
//		alert("Ths domain name contains invalid characters.");
		return false;
   }
}

if (user.match(userPat)==null) {
//	alert("The username doesn't seem to be valid.");
	return false;
}

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
//		alert("Destination IP address is invalid!");
		return false;
   }
}
return true;
}

var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
//		alert("The domain name does not seem to be valid.");
		return false;
   }
}

if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
//	alert("The address must end in a well-known domain or two letter " + "country.");
	return false;
}

if (len<2) {
//	alert("This address is missing a hostname!");
	return false;
}

return true;
}
//-->
