// JavaScript Document

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





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');

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>$</b>' + custRound(price,2);

	

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

	linksnew_elem.innerHTML = '';

	

	

        //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(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 calculate_total_price() 

{

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

	

	total_price = Math.abs(base_price);

	prices = new Array();

	

	for (var i = 0; i < Selects.length; i++)

	{

		name = Selects[i].id.substr(0,3);

		id = Selects[i].id.substr(3);

		_selected = Selects[i].options.selectedIndex;

		

		if (name == 'new')

		{

			prices[parseInt(id)] = Math.abs(Selects[i].options[_selected].getAttribute('price'));

		}

		if (name == 'qty')

		{

			prices[parseInt(id)] *= Math.abs(Selects[i].value);

		}

		

		

		

	}

	for(var i = 0; i < prices.length; i++)

	{

		pricing_elem = eval('document.getElementById(\'pricing'+i+'\')');

		pricing_elem.innerHTML = '<b>$</b>' + custRound(prices[i],2);

		total_price += prices[i];

	}

	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; /*Top Price*/
	document.getElementById('total_price_ex_vat').innerHTML = total_price; /*Footer Price*/
	document.getElementById('Total').value = total_price; /* Form price */

}

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 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;

	}

}