///////////////////////////////////////////////////////////////////////////////
//HighSlise JS                        
///////////////////////////////////////////////////////////////////////////////
    hs.graphicsDir = '/images/laptops/highslide/graphics/';
		hs.maxHeight = '600';
		hs.minHeight = '600';

// Highslide fixed popup mod. Requires the "Events" component.
if (!hs.ie || hs.uaVersion > 6) hs.extend ( hs.Expander.prototype, {
	fix: function(on) {
		var sign = on ? -1 : 1,
			stl = this.wrapper.style;

		if (!on) hs.getPageSize(); // recalculate scroll positions

		hs.setStyles (this.wrapper, {
			position: on ? 'fixed' : 'absolute',
			zoom: 1, // IE7 hasLayout bug,
			left: (parseInt(stl.left) + sign * hs.page.scrollLeft) +'px',
			top: (parseInt(stl.top) + sign * hs.page.scrollTop) +'px'
		});

		if (this.outline) {
			stl = this.outline.table.style;
			hs.setStyles (this.outline.table, {
				position: on ? 'fixed' : 'absolute',
				zoom: 1, // IE7 hasLayout bug,
				left: (parseInt(stl.left) + sign * hs.page.scrollLeft) +'px',
				top: (parseInt(stl.top) + sign * hs.page.scrollTop) +'px'
			});

		}
		this.fixed = on; // flag for use on dragging
	},
	onAfterExpand: function() {
    	this.fix(true); // fix the popup to viewport coordinates
			if(this.objectType=='ajax')
			{
  		var myKey = "MSIE 7.0";
  		var myStringVar = navigator.userAgent;
  		var myMatch = myStringVar.search(myKey);
  		if(myMatch != -1)
  		{
  		document.documentElement.style.overflow="hidden"; // re-instate body scroll bar
  		}
  		else
  		{
  		document.body.style.overflow="hidden"; // re-instate body scroll bar
  		}
			}
	},

	onBeforeClose: function() {
		this.fix(false); // unfix to get the animation right 
		if(this.objectType=='ajax')
		{
		var myKey = "MSIE 7.0";
		var myStringVar = navigator.userAgent;
		var myMatch = myStringVar.search(myKey);
		if(myMatch != -1)
		{
		document.documentElement.style.overflow="scroll"; // re-instate body scroll bar
		}
		else
		{
		document.body.style.overflow="auto"; // re-instate body scroll bar
		}
		}
	},

    onDrop: function() {
    	this.fix(true); // fix it again after dragging
	},

	onDrag: function(sender, args) {
		if (this.fixed) { // only unfix it on the first drag event
			this.fix(false);
		}
	}

});
///////////////////////////////////////////////////////////////////////////////
//Form Validator - onSubmit                        
///////////////////////////////////////////////////////////////////////////////
function Form_Validator(specbuilder,page_id,form_name)
{
  // require a value be entered in the field
  if ((specbuilder.q.value == "") || (specbuilder.q.value == "0") || (specbuilder.q.value == "00") || (specbuilder.q.value == "000"))
  {
    alert("Please enter a value above zero for the \"Quantity\" field.");
    specbuilder.q.focus();
    return (false);
  }
	
	//check that graphics cards are identical
	if(document.getElementById("12"))
	{
	if(document.getElementById("12").value!=402 && document.getElementById("12").value!=document.getElementById("11").value)
  {
  alert("When configuring a computer with multiple graphics cards, each graphic card must be identical. Please correct this before proceeding.");
  document.getElementById("12").focus();
  return false;
  }
	}
	
  // require that at least one character be entered
  if (specbuilder.q.value.length < 1)
  {
    alert("Please enter at least one number in the \"Quantity\" field.");
    specbuilder.q.focus();
    return (false);
  }

  // don't allow more than 5 characters be entered
  if (specbuilder.q.value.length > 5)
  {
	 alertsay = "Please enter at most 5 numbers in "
	 alertsay = alertsay + "the \"Quantity\" field."
    alert(alertsay);
    specbuilder.q.focus();
    return (false);
  }
  // only allow 0-9, hyphen and comma be entered
  var checkOK = "0123456789";
  var checkStr = specbuilder.q.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only numbers in the \"Quantity\" field.");
    specbuilder.q.focus();
    return (false);
  }
  //check for separator selected

  var group = document.specbuilder.elements;
  var x, len = group.length;
  for(x=0; x<len; x++)
  {
  if(group[x].value=="sep")
  {
	var cat_id = group[x].id;
	var cat_name = document.getElementById("cat"+cat_id+"").value;
	var cat_name = cat_name.replace("<sup>", "");
	var cat_name = cat_name.replace("</sup>", "");
  alert('You have not selected a valid product for the category: "'+cat_name+'". Please select a product before continuing.');
  return false;
  }
  }
	check_spec(page_id,form_name);
	//document.specbuilder.submit();
}
///////////////////////////////////////////////////////////////////////////////
//JS For Running Total                          
///////////////////////////////////////////////////////////////////////////////
function running_total(page_id,type){
var products;
for (var x=0; x < document.specbuilder.elements.length; x++)
{
if(document.specbuilder.elements[x].type=="select-one")
{
products = products+document.specbuilder.elements[x].value+",";
}
else if(document.specbuilder.elements[x].type=="radio" && document.specbuilder.elements[x].checked)
{
products = products+document.specbuilder.elements[x].value+",";	
}
else if(document.specbuilder.elements[x].type=="hidden" && document.specbuilder.elements[x].name!="page_id")
{
products = products+document.specbuilder.elements[x].value+",";
}
}
pcs_retrieve("/form/running_total.php?products="+products+"&&q="+document.specbuilder.q.value+"&&form_id="+page_id+"&&type="+type+"");
}
///////////////////////////////////////////////////////////////////////////////
//JS For Loading Images on Accessories Tab - Now Deprecated                        
///////////////////////////////////////////////////////////////////////////////
function changeImage(category_id,product_id)
{
if(""+product_id+""=='undefined')
{
document.getElementById("acc"+category_id+"").src = '/images/global/generic.jpg';
}
else if(""+product_id+""=='sb')
{
   for (var i=0; i < document.specbuilder.elements.length; i++)
   {
   if (document.specbuilder.elements[i].name==""+category_id+"" && document.specbuilder.elements[i].checked)
   {
	 if(document.specbuilder.elements[i].lang=='none')
	 {
	 document.getElementById("acc"+category_id+"").src = '/images/global/generic.jpg';
	 }
	 else
	 {
	 document.getElementById("acc"+category_id+"").src = '/images/products/'+document.specbuilder.elements[i].value+'/1.jpg';
	 pcs_retrieve('http://www.pcspecialist.co.uk/form/image_error.php?product='+document.specbuilder.elements[i].value+'');
	 }
   }
   }
}
else
{
document.getElementById("acc"+category_id+"").src = '/images/products/'+product_id+'/1.jpg';
pcs_retrieve('http://www.pcspecialist.co.uk/form/image_error.php?product='+product_id+'');
}
}
///////////////////////////////////////////////////////////////////////////////
//JS For Help Window Popup                       
///////////////////////////////////////////////////////////////////////////////
function popup(mylink, windowname) 
{
var screen_height = screen.height;
var screen_width = screen.width;
if (! window.focus)return true; 
var href; 
if (typeof(mylink) == 'string') 
href=mylink; 
else 
href=mylink.href; 
window.open(href, windowname, 'width=' + screen_width + ',height=' + screen_height + ',scrollbars=yes,resizable=yes'); 
return false; 
} 
///////////////////////////////////////////////////////////////////////////////
//JS For Show/Hide Categories Not Loaded on Form - such as 3rd/4th HDD, etc                       
///////////////////////////////////////////////////////////////////////////////
function customOption(val){

var cats = new Array();
cats = val.split(","); 
for (i in cats)
{
if(document.getElementById('show'+cats[i]+'').style.display=='')
{
document.getElementById('show'+cats[i]+'').style.display = 'none';
if(document.getElementById("dispname"+cats[i]+""))
{
document.getElementById("dispname"+cats[i]+"").childNodes[0].nodeValue = 'Show';
}
}
else
{
document.getElementById('show'+cats[i]+'').style.display = '';
if(document.getElementById("dispname"+cats[i]+""))
{
document.getElementById("dispname"+cats[i]+"").childNodes[0].nodeValue = 'Hide';
}
}
}
}
///////////////////////////////////////////////////////////////////////////////
//JS For Tabs                      
///////////////////////////////////////////////////////////////////////////////
function toggle(val,model){

var show = new Array();
show = val.split(","); 

document.getElementById(show[0]+"1").src = '/images/global/tableft.gif';
document.getElementById(show[0]+"2").className = "laptop_tab_on";
document.getElementById(show[0]+"3").src = '/images/global/tabright.gif';
document.getElementById(show[0]).style.display = 'inline';

document.getElementById(show[1]+"1").src = '/images/global/tabgreyleft.gif';
document.getElementById(show[1]+"2").className = "laptop_tab_off";
document.getElementById(show[1]+"3").src = '/images/global/tabgreyright.gif';
document.getElementById(show[1]).style.display = 'none';

document.getElementById(show[2]+"1").src = '/images/global/tabgreyleft.gif';
document.getElementById(show[2]+"2").className = "laptop_tab_off";
document.getElementById(show[2]+"3").src = '/images/global/tabgreyright.gif';
document.getElementById(show[2]).style.display = 'none';

if(show[0]=='configurator')
{
document.getElementById("bigbar").innerHTML = '1) view images of the '+model+'';
document.getElementById("bigbar2").innerHTML = '2) choose your core components';
}
else if(show[0]=='general')
{
document.getElementById("bigbar").innerHTML = 'view images of the '+model+'';
document.getElementById("bigbar2").innerHTML = 'view the detailed specification';
}
else if(show[0]=='features')
{
document.getElementById("bigbar").innerHTML = 'view images of the '+model+'';
document.getElementById("bigbar2").innerHTML = 'view the features';
}
else
{
document.getElementById("bigbar").innerHTML = 'view images of the '+model+'';
document.getElementById("bigbar2").innerHTML = '';
}
}
///////////////////////////////////////////////////////////////////////////////
//JS For Laptops, toggling Images                       
///////////////////////////////////////////////////////////////////////////////
function toggleImages(val){
for(i=1;i<=5;i++)
{
if(i==val)
{
var display = '';
}
else
{
var display = 'none';
}
document.getElementById('img'+i+'').style.display = display;
}
}
///////////////////////////////////////////////////////////////////////////////
//JS For Exception Highlight                          
///////////////////////////////////////////////////////////////////////////////
function highlight()
{
var show = document.getElementById("highlight").innerHTML;
document.getElementById("clearbg").innerHTML = show;
var show = show.split("x");
for (var x=0; x <= show.length; x++)
{
if(document.getElementById("fadein"+show[x]+"a"))
{
document.getElementById("show"+show[x]).style.backgroundColor = '#fd8686';
document.getElementById("fadein"+show[x]+"a").style.backgroundColor = '#fd8686';
document.getElementById("fadein"+show[x]+"b").style.backgroundColor = '#fd8686';
var to_focus = document.getElementById("fadein"+show[x]+"a").lang;
document.getElementById(to_focus).focus();
}
}
}
///////////////////////////////////////////////////////////////////////////////
//JS For Exception BG Clearing                       
///////////////////////////////////////////////////////////////////////////////
function clearbg(val)
{
var show = val.split("x");
for (var x=0; x <= show.length; x++)
{
if(document.getElementById("fadein"+show[x]+"a"))
{
document.getElementById("show"+show[x]).style.backgroundColor = '#ffffff';
document.getElementById("fadein"+show[x]+"a").style.backgroundColor = '#ffffff';
document.getElementById("fadein"+show[x]+"b").style.backgroundColor = '#ffffff';
}
}
}
///////////////////////////////////////////////////////////////////////////////
//JS For Exceptions                          
///////////////////////////////////////////////////////////////////////////////
function check_spec(page_id,form_name){
var products = '';
var categories = '';
var otherkeys = '';
var othervals = '';
for (var x=0; x < document.specbuilder.elements.length; x++)
{
if(document.specbuilder.elements[x].type=="select-one")
{
products = products+document.specbuilder.elements[x].value+",";
categories = categories+document.specbuilder.elements[x].name+",";
}
else if(document.specbuilder.elements[x].type=="radio" && document.specbuilder.elements[x].checked)
{
products = products+document.specbuilder.elements[x].value+",";
categories = categories+document.specbuilder.elements[x].name+",";
}
else if(document.specbuilder.elements[x].type=="hidden")
{
  if(isNaN(document.specbuilder.elements[x].name))
	{
	othervals = othervals+document.specbuilder.elements[x].value+",";
  otherkeys = otherkeys+document.specbuilder.elements[x].name+",";
	}
	else
	{
  products = products+document.specbuilder.elements[x].value+",";
  categories = categories+document.specbuilder.elements[x].name+",";
  }
}
else if(document.specbuilder.elements[x].name!='18')
{
otherkeys = otherkeys+document.specbuilder.elements[x].name+",";
othervals = othervals+document.specbuilder.elements[x].value+",";
}
}
div1 = document.getElementById('exceptions_return');
div1.href= "/form/includes/form_exceptions.php?categories="+categories+"&&products="+products+"&&q="+document.specbuilder.q.value+"&&form_id="+page_id+"&&form_name="+form_name+"&&otherkeys="+otherkeys+"&&othervals="+othervals+"";
hs.htmlExpand(div1, { preserveContent: false, outlineType: 'rounded-white', align: 'center', objectType: 'ajax', width: '800', maxHeight: '600' } );
//clear out failed exception bg colours
clearbg(document.getElementById('clearbg').innerHTML);
}
///////////////////////////////////////////////////////////////////////////////
//End of JS                      
///////////////////////////////////////////////////////////////////////////////

