function getObjectX(object) {return getObjectC(object, "x")}
function getObjectY(object) {return getObjectC(object, "y")}

function getObjectC(object, c)
{
    pos = 0;
    while (object != null)
    {
        pos += (c == "y") ? object.offsetTop : object.offsetLeft;
        object = object.offsetParent;
    }
    return pos;
}

function showimage(elem,params)
{
	_selected = elem.options.selectedIndex;


	model = elem.options[_selected].getAttribute('model');
	price = elem.options[_selected].getAttribute('price');

	_image = elem.options[_selected].getAttribute('image');

	number = elem.id.substr(3);

	new_hidden_elem = eval('document.getElementById(\'new'+number+'_hidden\')');
	new_hidden_elem.value = model;

	pricing_elem = eval('document.getElementById(\'pricing'+number+'\')');
	pricing_elem.innerHTML = '<b>&pound;</b>' + custRound(price,2);

	linksnew_elem = eval('document.getElementById(\'linksnew'+number+'\')');
	linksnew_elem.innerHTML = '';

	enlarge_pics_elem = eval('document.getElementById(\'enlarge_pics'+number+'\')');
    /*enlarge_pics_elem.href = "javascript:popupWindow('http://www.vadim.co.uk/popup_image/"+_image+"')"*/
	enlarge_pics_elem.href = "http://www.vadim.co.uk/images/"+_image;

        //enlarge_pics_elem.href = '/images/'+_image;
	/*
	picdiv_elem = eval('document.getElementById(\'picdiv'+number+'\')');
	picdiv_elem.innerHTML = '';
	*/
	/*
	if(model != '')
	{
		_onclick = 'javascript:show_popup_text(\'/ccc_more_info.php?path='+model+'\')';
		linksnew_elem.innerHTML = '<input TYPE="button" VALUE="More Info"  onclick="'+_onclick+'" class="button">';
		if(pics == 'y')
		{
			_onclick = 'javascript:show_popup_img(\'/images/'+_image+'\')';
			picdiv_elem.innerHTML = '<input TYPE="button" VALUE="Enlarge Image"  onclick="'+_onclick+'" class="button" target="_blank">';
		}
	}
	*/
	if(pics == 'y')
	{
		pics_elem = eval('document.getElementById(\'pics'+number+'\')');
		pics_elem.src = 'images/no_image.gif';
		if (_image != "images/")
		{
		 	 if (_image == "nosel.gif") pics_elem.src = "images/"+_image;
		 	 else pics_elem.src = "thumbs_108/"+_image;
		}
	}

	if(params != 'onload')
	{
		calculate_total_price();
	}
}
function load_custom_pc()
{
	var Selects = document.body.getElementsByTagName("Select");

	for (var i = 0; i < Selects.length; i++)
	{
		name = Selects[i].id.substr(0,3);
		if (name == 'new')
		{
			id = Selects[i].id.substr(3);
			_selected = Selects[i].options.selectedIndex;
			var qty = Selects[i].options[_selected].getAttribute('qty');

			qty_elem = eval('document.getElementById(\'qty'+id+'\')');

			if(qty_elem != null && qty_elem.options[(qty-1)] != null)
			{
				qty_elem.options[(qty-1)].selected = "selected";
			}

			showimage(Selects[i],'onload');
		}
	}
	calculate_total_price();
}

function is_warranty(_m)
{
	_m = parseInt(_m);
	if (_m == 1288 || _m == 1287 || _m == 1286 || _m == 1801 || _m == 1985 ) return true;
	else return false;
}

function is_building(_m)
{
	_m = parseInt(_m);
	if ( _m == 1284 || _m == 1281 || _m == 2723 ||  _m == 2724 ) return true;
	else return false;
}

function calculate_total_price()
{
	var Selects = document.body.getElementsByTagName("Select");

	total_price = Math.abs(base_price);
	prices = new Array();
	var warranty = 0;
	var warranty_id = 0;
	var building = 0;
	var building_id = 0;

	for (var i = 0; i < Selects.length; i++)
	{
		name = Selects[i].id.substr(0,3);
		id = Selects[i].id.substr(3);
		_selected = Selects[i].selectedIndex;

		if (name == 'new')
		{	
			prices[parseInt(id)] = Math.abs(Selects[i].options[_selected].getAttribute('price'));
			
			
			if (is_warranty(Selects[i].options[_selected].getAttribute('model')))
			{	
				warranty = Math.abs(Selects[i].options[_selected].getAttribute('price'));
				warranty_id = parseInt(id);
				prices[parseInt(id)] = 0;
			}
			
			if (is_building(Selects[i].options[_selected].getAttribute('model')))
			{ 
				building = Math.abs(Selects[i].options[_selected].getAttribute('price'));
				building_id = parseInt(id);
				prices[parseInt(id)] = 0;
			}
				
		}
		if (name == 'qty')
		{
			prices[parseInt(id)] *= Math.abs(Selects[i].value);
		}

		if(parseInt(id) >= 0)
		{
			var info_elem = eval('document.getElementById(\'info'+id+'\')');
			var _href = Selects[i].options[_selected].getAttribute('href');
			if(_href != null)
			{
				_href += '?info';
				info_elem.href = _href;
			}else
			{
				//info_elem.href = '';
			}
		}


	}
	for(var i = 0; i < prices.length; i++)
	{
		pricing_elem = eval('document.getElementById(\'pricing'+i+'\')');
		pricing_elem.innerHTML = '<b>&pound;</b>' + custRound(prices[i],2);
		total_price += prices[i];
	}
	total_price1=total_price;
	var warranty_price = total_price1*(warranty/100);
	if (warranty_id) {
		pricing_elem = eval('document.getElementById(\'pricing'+warranty_id+'\')');
		pricing_elem.innerHTML = '<b>&pound;</b>' + custRound(warranty_price,2);
		total_price += warranty_price;
	}
	
	var building_price = total_price1*(building/100);
	if (building_id) { 
		pricing_elem = eval('document.getElementById(\'pricing'+building_id+'\')');
		pricing_elem.innerHTML = '<b>&pound;</b>' + custRound(building_price,2);
		total_price += building_price;
	}
	
	var total_price_inc_vat = total_price*1.175;
	total_price_inc_vat = custRound(total_price_inc_vat,2);
	total_price = custRound(total_price,2);
	document.getElementById('Total_price').innerHTML = total_price;
	document.getElementById('total_price_ex_vat').innerHTML = total_price;
	document.getElementById('total_price_inc_vat').innerHTML = total_price_inc_vat;
	document.getElementById('Total').value = total_price;
	if (total_price_inc_vat >= 2000 ) document.getElementById('disclaimer').style.display = 'block';
	else document.getElementById('disclaimer').style.display = 'none';
	if(peripher == 'peripher'){ g_total_price();}
}
function g_total_price(){
	var g_total = document.getElementById("total_w_new_parts");
	var summ_total = (parseFloat(cart_total) + parseFloat(document.getElementById("total_price_ex_vat").innerHTML));
	g_total.innerHTML = custRound(summ_total,2);
}
function form_reset(fname)
{
	fname.reset();
	load_custom_pc();
}
function cent(amount)
{
	return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}
function custRound(x,places)
{
	return cent(Math.round(x*100)/100);
}
function replace(){
    var oNewDoc = document.open("text/html", "replace");
    var sMarkup = "<HTML><HEAD><TITLE>New Document</TITLE><BODY>Hello, world</BODY></HTML>";
    oNewDoc.write(sMarkup);
    oNewDoc.close();
}
function show_popup_img(_this)
{
	_src = '/images/';
	_src += _this.getAttribute('path');

	Img = new Image();
   	Img.src = _src;
  	w = 300;//Img.width + 10;
   	h = 400;//Img.height + 10;

	popup = window.open('', null,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+w+',height='+h+',screenX=150,screenY=150,top=150,left=150');

   	html = '<html><body ><img src="'+_src+'" width="100%"></body></html>';

	popup.document.write(html);
	return false;
}
function show_popup_text(_src)
{

	popup = window.open(_src, 'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=200,height=50%,screenX=150,screenY=150,top=150,left=150');

}
function forceSubmit(_form,_action,_hidden_action)
{
    if(_hidden_action !== null)
		_form.action.value = _hidden_action;

    if(document.all)
    {
	   for(i = 0; i<_form.attributes.length; i++)
	   {
           if (_form.attributes.item(i).nodeName.toLowerCase() == 'action') _form.attributes.item(i).nodeValue = _action;
           if (_form.attributes.item(i).nodeName.toLowerCase() == 'method') _form.attributes.item(i).nodeValue = 'post';
	   }
	}
    else
	{
        _form.setAttribute("action",_action);
        _form.setAttribute("method","post");
	}
    _form.submit();
}
function pa(_elem)
{
	var str='';
	for(key in _elem)
	{
		str +=key+'\t';
	}
	for (n=0; n< _elem.length; n++)
	{
	      str += _elem[n]+'\t';
    }

	alert(str);
}
function SetFocus(TargetFormName) {
  var target = 0;
  if (TargetFormName != "") {
    for (i=0; i<document.forms.length; i++) {
      if (document.forms[i].name == TargetFormName) {
        target = i;
        break;
      }
    }
  }

  var TargetForm = document.forms[target];

  for (i=0; i<TargetForm.length; i++) {
    if ( (TargetForm.elements[i].type != "image") && (TargetForm.elements[i].type != "hidden") && (TargetForm.elements[i].type != "reset") && (TargetForm.elements[i].type != "submit") ) {
      TargetForm.elements[i].focus();

      if ( (TargetForm.elements[i].type == "text") || (TargetForm.elements[i].type == "password") ) {
        TargetForm.elements[i].select();
      }

      break;
    }
  }
}

function RemoveFormatString(TargetElement, FormatString) {
  if (TargetElement.value == FormatString) {
    TargetElement.value = "";
  }

  TargetElement.select();
}

function CheckDateRange(from, to) {
  if (Date.parse(from.value) <= Date.parse(to.value)) {
    return true;
  } else {
    return false;
  }
}

function IsValidDate(DateToCheck, FormatString) {
  var strDateToCheck;
  var strDateToCheckArray;
  var strFormatArray;
  var strFormatString;
  var strDay;
  var strMonth;
  var strYear;
  var intday;
  var intMonth;
  var intYear;
  var intDateSeparatorIdx = -1;
  var intFormatSeparatorIdx = -1;
  var strSeparatorArray = new Array("-"," ","/",".");
  var strMonthArray = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
  var intDaysArray = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

  strDateToCheck = DateToCheck.toLowerCase();
  strFormatString = FormatString.toLowerCase();

  if (strDateToCheck.length != strFormatString.length) {
    return false;
  }

  for (i=0; i<strSeparatorArray.length; i++) {
    if (strFormatString.indexOf(strSeparatorArray[i]) != -1) {
      intFormatSeparatorIdx = i;
      break;
    }
  }

  for (i=0; i<strSeparatorArray.length; i++) {
    if (strDateToCheck.indexOf(strSeparatorArray[i]) != -1) {
      intDateSeparatorIdx = i;
      break;
    }
  }

  if (intDateSeparatorIdx != intFormatSeparatorIdx) {
    return false;
  }

  if (intDateSeparatorIdx != -1) {
    strFormatArray = strFormatString.split(strSeparatorArray[intFormatSeparatorIdx]);
    if (strFormatArray.length != 3) {
      return false;
    }

    strDateToCheckArray = strDateToCheck.split(strSeparatorArray[intDateSeparatorIdx]);
    if (strDateToCheckArray.length != 3) {
      return false;
    }

    for (i=0; i<strFormatArray.length; i++) {
      if (strFormatArray[i] == 'mm' || strFormatArray[i] == 'mmm') {
        strMonth = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'dd') {
        strDay = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'yyyy') {
        strYear = strDateToCheckArray[i];
      }
    }
  } else {
    if (FormatString.length > 7) {
      if (strFormatString.indexOf('mmm') == -1) {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mm'), 2);
      } else {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mmm'), 3);
      }

      strDay = strDateToCheck.substring(strFormatString.indexOf('dd'), 2);
      strYear = strDateToCheck.substring(strFormatString.indexOf('yyyy'), 2);
    } else {
      return false;
    }
  }

  if (strYear.length != 4) {
    return false;
  }

  intday = parseInt(strDay, 10);
  if (isNaN(intday)) {
    return false;
  }
  if (intday < 1) {
    return false;
  }

  intMonth = parseInt(strMonth, 10);
  if (isNaN(intMonth)) {
    for (i=0; i<strMonthArray.length; i++) {
      if (strMonth == strMonthArray[i]) {
        intMonth = i+1;
        break;
      }
    }
    if (isNaN(intMonth)) {
      return false;
    }
  }
  if (intMonth > 12 || intMonth < 1) {
    return false;
  }

  intYear = parseInt(strYear, 10);
  if (isNaN(intYear)) {
    return false;
  }
  if (IsLeapYear(intYear) == true) {
    intDaysArray[1] = 29;
  }

  if (intday > intDaysArray[intMonth - 1]) {
    return false;
  }

  return true;
}

function IsLeapYear(intYear) {
  if (intYear % 100 == 0) {
    if (intYear % 400 == 0) {
      return true;
    }
  } else {
    if ((intYear % 4) == 0) {
      return true;
    }
  }

  return false;
}
function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=450,height=280,screenX=150,screenY=150,top=150,left=150')
}
function live_chat(_this)
{
	var _url = 'http://chat.boldchat.com/chat/visitor.jsp?cdid=661506734';
	_url +='&url=' + document.location;
	_style = 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=640,height=480';
	this.newWindow = window.open(_url,'Chat',_style);
	this.newWindow.focus();
	this.newWindow.opener = window;return false;
}

function livehelp(url)
{
         window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=600,height=510,screenX=150,screenY=150,top=150,left=150');
}

function submit_manufacturers(_this)
{
	if (_this.value) document.location.href =_this.value+'/';
}
function show_login_form()
{
	login_form_elem = document.getElementById('login_form');
	login_form_elem.style.display = 'inline';
	loqin_question_elem = document.getElementById('loqin_question');
	loqin_question_elem.style.display = 'none';
}
function check_agreement()
{
    if (agree_checkbox.checked) { return true; }
    else
	{
		alert('You must read and agree with the Terms And Conditions');
        return false;
	}
}
var timer;
function Scroll(name,start,lnk,dir,speed){ 
	clearTimeout(timer);
	p=document.getElementById(name);
	
	if(p.scrollLeft==p.scrollWidth) current = p.scrollLeft;
	
	if(dir == 1) p.scrollLeft=p.scrollLeft+speed;
			else p.scrollLeft=p.scrollLeft-speed;
	timer=setTimeout('Scroll("'+name+'",'+start+','+lnk+','+dir+','+speed+')',1);
	
	if ((dir ==1 && (p.scrollLeft >= start+lnk || p.scrollLeft==p.scrollWidth)) ||
		(dir ==0 && (p.scrollLeft <= start-lnk ||p.scrollLeft==0))
		){ 
			clearTimeout(timer); 
	}
}