function ajaxcall(url){
 var xml = null;
 try {
    xml = new ActiveXObject("Microsoft.XMLHTTP");
 }
 catch(exception) {
    xml = new XMLHttpRequest();
 }
 if(xml!=null) {
	xml.open("GET",url, false);
	xml.send(null);
    if(xml.status == 404) alert("Error 404: Incorrect url.");
    return xml.responseXML;
 }
 alert("Your browser does not support XMLHTTP.");
 return "";
}

function init_s(){
  var el = document.getElementById("load_mess");
  if(el.style.display=="none") {
	    el.style.display = '';
	    var st1 = setTimeout("init_s();",1);
  } else {
	  var val_1 = document.getElementById("categ").options[document.getElementById("categ").selectedIndex].value;
	  var val_2 = document.getElementById("config_id").value;
	  var ord_n = document.getElementById("ord_n");
	  var ord_s = document.getElementById("ord_s");
	  var cord_n = document.getElementById("cord_n");
	  var cord_s = document.getElementById("cord_s");
	  
	  if(document.getElementsByName("stoc")[1].checked) {var stoc='stoc'; } else { var stoc=''; }
	  var sel_company = document.getElementById("d_producator");
	  var filtru = document.getElementById("smoothmenu1");
	  var result = document.getElementById("result");
	  var config_ta = document.getElementById("config");
	  var config_ta_sum = document.getElementById("config_sum");

	  var xml = ajaxcall("../comp/servere/configurator.php?action=init_s&category=" + escape(val_1) + "&ord_n=" + ord_n.value + "&ord_s=" + ord_s.value + "&stoc=" + stoc + "&config_id=" + val_2 + "&cord_n=" + cord_n.value + "&cord_s=" + cord_s.value);
	  if (xml) {
	    var raspuns_xml = xml.getElementsByTagName("sel_comp");
		if (raspuns_xml.length>0){
	      raspuns = raspuns_xml[0];
		  sel_company.innerHTML = unescape(raspuns.attributes.getNamedItem("mess").value);
		}
		 //Initialize Menu instance(s):
		  ddsmoothmenu.init({
		  mainmenuid: 'smoothmenu1', //menu DIV id
		  orientation: 'v', //Horizontal or vertical menu:
          add_arrow: true,
		  classname: 'ddsmoothmenu-v', //class added to menu's outer DIV
		  contentsource: ["menuf", "../comp/servere/configurator_filtru.php?categ=" + escape(val_1)]}) //"markup"
	    raspuns_xml = xml.getElementsByTagName("result_prod");
		if (raspuns_xml.length>0){
	      raspuns = raspuns_xml[0];
		  result.innerHTML = unescape(raspuns.attributes.getNamedItem("mess").value)
		} else result.innerHTML = "";
		raspuns_xml = xml.getElementsByTagName("config_ta");
		if (raspuns_xml.length>0){
	      raspuns = raspuns_xml[0];
		  config_ta.innerHTML = unescape(raspuns.attributes.getNamedItem("mess").value);
		  
		} else config_ta.innerHTML = "";
		raspuns_xml = xml.getElementsByTagName("config_ta_sum");
		if (raspuns_xml.length>0){
	      raspuns = raspuns_xml[0];
		  config_ta_sum.innerHTML = unescape(raspuns.attributes.getNamedItem("mess").value);

		} else config_ta_sum.innerHTML = "";
	  }
      document.getElementById("sfiltru").value='';
	  el.style.display = 'none';
  }
}

function chg_categ(){
  var el = document.getElementById("load_mess");
  if(el.style.display=="none") {
	    el.style.display = '';
	    var st1 = setTimeout("chg_categ();",1);
  } else {
	  var val_1 = document.getElementById("categ").options[document.getElementById("categ").selectedIndex].value;
	  var ord_n = document.getElementById("ord_n");
	  var ord_s = document.getElementById("ord_s");
	  if(document.getElementsByName("stoc")[1].checked) var stoc='stoc'; else var stoc='';
	  var sel_company = document.getElementById("d_producator");
	  var filtru = document.getElementById("smoothmenu1");
	  var result = document.getElementById("result");
	  var xml = ajaxcall("../comp/servere/configurator.php?action=chg_categ&category=" + escape(val_1) + "&ord_n=" + ord_n.value + "&ord_s=" + ord_s.value + "&stoc=" + stoc);
	  if (xml) {
	    var raspuns_xml = xml.getElementsByTagName("sel_comp");
		if (raspuns_xml.length>0){
	      raspuns = raspuns_xml[0];
		  sel_company.innerHTML = unescape(raspuns.attributes.getNamedItem("mess").value)
		}
		 //Initialize Menu instance(s):
		  ddsmoothmenu.init({
		  mainmenuid: 'smoothmenu1', //menu DIV id
		  orientation: 'v', //Horizontal or vertical menu:
          add_arrow: true,
		  classname: 'ddsmoothmenu-v', //class added to menu's outer DIV
		  contentsource: ["menuf", "../comp/servere/configurator_filtru.php?categ=" + escape(val_1)]}) //"markup"
	    raspuns_xml = xml.getElementsByTagName("result_prod");
		if (raspuns_xml.length>0){
	      raspuns = raspuns_xml[0];
		  result.innerHTML = unescape(raspuns.attributes.getNamedItem("mess").value)
		} else result.innerHTML = "";

	  }
      document.getElementById("sfiltru").value='';
	  el.style.display = 'none';
  }
}

function chg_comp(){
  var el = document.getElementById("load_mess");
  if(el.style.display=="none") {
	    el.style.display = '';
	    var st1 = setTimeout("chg_comp();",1);
  } else {
	  var val_1 = document.getElementById("categ").options[document.getElementById("categ").selectedIndex].value;
	  var val_2 = document.getElementById("producator").options[document.getElementById("producator").selectedIndex].value;
	  var ord_n = document.getElementById("ord_n");
	  var ord_s = document.getElementById("ord_s");
	  if(document.getElementsByName("stoc")[1].checked) var stoc='stoc'; else var stoc='';
	  var sel_company = document.getElementById("d_producator");
	  var filtru = document.getElementById("smoothmenu1");
	  var result = document.getElementById("result");
	  var xml = ajaxcall("../comp/servere/configurator.php?action=chg_comp&category=" + escape(val_1) + "&companie=" + escape(val_2) + "&ord_n=" + ord_n.value + "&ord_s=" + ord_s.value + "&stoc=" + stoc);
	  if (xml) {
		 //Initialize Menu instance(s):
		  ddsmoothmenu.init({
		  mainmenuid: 'smoothmenu1', //menu DIV id
		  orientation: 'v', //Horizontal or vertical menu:
          add_arrow: true,
		  classname: 'ddsmoothmenu-v', //class added to menu's outer DIV
		  contentsource: ["menuf", "../comp/servere/configurator_filtru.php?categ=" + escape(val_1) + "&companie=" + escape(val_2)]}) //"markup"
	    var raspuns_xml = xml.getElementsByTagName("result_prod");
		if (raspuns_xml.length>0){
	      raspuns = raspuns_xml[0];
		  result.innerHTML = unescape(raspuns.attributes.getNamedItem("mess").value)
		} else result.innerHTML = "";
	  }
      document.getElementById("sfiltru").value='';
	  el.style.display = 'none';
  }
}

function chg_filtru(obj){
  var el = document.getElementById("load_mess");
  if(el.style.display=="none") {
        document.getElementById("sfiltru").value=obj;
	    el.style.display = '';
	    var st1 = setTimeout("chg_filtru('" + obj + "');",1);
  } else {
	  var val_1 = document.getElementById("categ").options[document.getElementById("categ").selectedIndex].value;
	  var val_2 = document.getElementById("producator").options[document.getElementById("producator").selectedIndex].value;
	  var ord_n = document.getElementById("ord_n");
	  var ord_s = document.getElementById("ord_s");
	  if(document.getElementsByName("stoc")[1].checked) var stoc='stoc'; else var stoc='';
	  var filtru = document.getElementById("smoothmenu1");
	  var result = document.getElementById("result");
	  var xml = ajaxcall("../comp/servere/configurator.php?action=chg_filtru&category=" + escape(val_1) + "&companie=" + escape(val_2) + "&ord_n=" + ord_n.value + "&ord_s=" + ord_s.value + "&stoc=" + stoc + "&sfiltru=" + escape(obj));
	  if (xml) {
		 //Initialize Menu instance(s):
		  ddsmoothmenu.init({
		  mainmenuid: 'smoothmenu1', //menu DIV id
		  orientation: 'v', //Horizontal or vertical menu:
          add_arrow: true,
		  classname: 'ddsmoothmenu-v', //class added to menu's outer DIV
		  contentsource: ["menuf", "../comp/servere/configurator_filtru.php?categ=" + escape(val_1) + "&companie=" + escape(val_2) + "&sfiltru=" + escape(obj)]}) //"markup"
	    var raspuns_xml = xml.getElementsByTagName("result_prod");
		if (raspuns_xml.length>0){
	      raspuns = raspuns_xml[0];
		  result.innerHTML = unescape(raspuns.attributes.getNamedItem("mess").value)
		} else result.innerHTML = "";
	  }
	  el.style.display = 'none';
  }
}

function chg_result(){
  var el = document.getElementById("load_mess");
  if(el.style.display=="none") {
	    el.style.display = '';
	    var st1 = setTimeout("chg_result();",1);
  } else {
	  var val_1 = document.getElementById("categ").options[document.getElementById("categ").selectedIndex].value;
	  var val_2 = document.getElementById("producator").options[document.getElementById("producator").selectedIndex].value;
      var obj = document.getElementById("sfiltru").value;
	  var ord_n = document.getElementById("ord_n");
	  var ord_s = document.getElementById("ord_s");
	  if(document.getElementsByName("stoc")[1].checked) var stoc='stoc'; else var stoc='';
	  var result = document.getElementById("result");
	  var xml = ajaxcall("../comp/servere/configurator.php?action=chg_result&category=" + escape(val_1) + "&companie=" + escape(val_2) + "&ord_n=" + ord_n.value + "&ord_s=" + ord_s.value + "&stoc=" + stoc + "&sfiltru=" + escape(obj));
	  if (xml) {
	    var raspuns_xml = xml.getElementsByTagName("result_prod");
		if (raspuns_xml.length>0){
	      raspuns = raspuns_xml[0];
		  result.innerHTML = unescape(raspuns.attributes.getNamedItem("mess").value)
		} else result.innerHTML = "";
	  }
	  el.style.display = 'none';
  }
}

function chg_ord(ord_) {
	var ord_n = document.getElementById("ord_n");
	var ord_s = document.getElementById("ord_s");
	var loc_pn = document.getElementById("sens_pn");
	var loc_pret = document.getElementById("sens_pret");
	var class_n = document.all ? 'className' : 'class';
	if (ord_n.value=='pret'){
		if(ord_=='pret')
		    if (ord_s.value=='asc'){
				ord_s.value = 'desc';
				loc_pret.setAttribute(class_n, "sens_up");
			} else {
				ord_s.value = 'asc';
				loc_pret.setAttribute(class_n, "sens_down");
			}
		else {
            ord_n.value='produs';
			ord_s.value = 'asc';
			loc_pn.setAttribute(class_n, "sens_down");
            loc_pret.setAttribute(class_n, "");
		}

	} else {
		if(ord_=='produs')
		    if (ord_s.value=='asc'){
				ord_s.value = 'desc';
				loc_pn.setAttribute(class_n, "sens_up");
			} else {
				ord_s.value = 'asc';
				loc_pn.setAttribute(class_n, "sens_down");
			}
		else {
            ord_n.value='pret';
			ord_s.value = 'asc';
			loc_pret.setAttribute(class_n, "sens_down");
			loc_pn.setAttribute(class_n, "");
		}
	}
	chg_result();
}

function chg_ord_c(ord_) {
	var ord_n = document.getElementById("cord_n");
	var ord_s = document.getElementById("cord_s");
	var loc_pn = document.getElementById("csens_pn");
	var loc_pret = document.getElementById("csens_pret");
	var class_n = document.all ? 'className' : 'class';
	if (ord_n.value=='pret'){
		if(ord_=='pret')
		    if (ord_s.value=='asc'){
				ord_s.value = 'desc';
				loc_pret.setAttribute(class_n, "sens_up");
			} else {
				ord_s.value = 'asc';
				loc_pret.setAttribute(class_n, "sens_down");
			}
		else {
            ord_n.value='produs';
			ord_s.value = 'asc';
			loc_pn.setAttribute(class_n, "sens_down");
            loc_pret.setAttribute(class_n, "");
		}

	} else {
		if(ord_=='produs')
		    if (ord_s.value=='asc'){
				ord_s.value = 'desc';
				loc_pn.setAttribute(class_n, "sens_up");
			} else {
				ord_s.value = 'asc';
				loc_pn.setAttribute(class_n, "sens_down");
			}
		else {
            ord_n.value='pret';
			ord_s.value = 'asc';
			loc_pret.setAttribute(class_n, "sens_down");
			loc_pn.setAttribute(class_n, "");
		}
	}
	chg_config();
}

function chg_config(){
  var el = document.getElementById("load_mess");
  if(el.style.display=="none") {
	    el.style.display = '';
	    var st1 = setTimeout("chg_config();",1);
  } else {
	  var val_1 = document.getElementById("config_id").value;
	  var cord_n = document.getElementById("cord_n");
	  var cord_s = document.getElementById("cord_s");
	  var config_ta = document.getElementById("config");
	  var config_ta_sum = document.getElementById("config_sum");
	  
	  var xml = ajaxcall("../comp/servere/configurator.php?action=chg_config&config_id=" + val_1 + "&cord_n=" + cord_n.value + "&cord_s=" + cord_s.value);
	  if (xml) {
	    var raspuns_xml = xml.getElementsByTagName("config_ta");
		if (raspuns_xml.length>0){
	      raspuns = raspuns_xml[0];
		  config_ta.innerHTML = unescape(raspuns.attributes.getNamedItem("mess").value)
		} else config_ta.innerHTML = "";
		raspuns_xml = xml.getElementsByTagName("config_ta_sum");
		if (raspuns_xml.length>0){
	      raspuns = raspuns_xml[0];
		  config_ta_sum.innerHTML = unescape(raspuns.attributes.getNamedItem("mess").value);
		} else config_ta_sum.innerHTML = "";
	  }
	  el.style.display = 'none';
  }
}

function item_o(kp, func){
  var el = document.getElementById("load_mess");
  if(el.style.display=="none") {
	    el.style.display = '';
	    var st1 = setTimeout("item_o('" + kp + "', '" + func + "');",1);
  } else {
	  var val_1 = document.getElementById("config_id").value;
	  var cord_n = document.getElementById("cord_n");
	  var cord_s = document.getElementById("cord_s");
	  var config_ta = document.getElementById("config");
	  var config_ta_sum = document.getElementById("config_sum");

	  if(func=="add"){
        var xml = ajaxcall("../comp/servere/configurator.php?action=add_item&config_id=" + val_1 + "&cord_n=" + cord_n.value + "&cord_s=" + cord_s + "&kp=" + kp);
	  } else {
        var xml = ajaxcall("../comp/servere/configurator.php?action=sub_item&config_id=" + val_1 + "&cord_n=" + cord_n.value + "&cord_s=" + cord_s + "&kp=" + kp); }

	  el.style.display = 'none';
      chg_config();
  }
}

function chg_buc(buc, kp){
  var el = document.getElementById("load_mess");
  if(el.style.display=="none") {
	    el.style.display = '';
	    var st1 = setTimeout("chg_buc('" + buc + "', '" + kp + "');",1);
  } else {
	  var val_1 = document.getElementById("config_id").value;
	  var cord_n = document.getElementById("cord_n");
	  var cord_s = document.getElementById("cord_s");
	  var config_ta = document.getElementById("config");
	  var config_ta_sum = document.getElementById("config_sum");

      var xml = ajaxcall("../comp/servere/configurator.php?action=chg_buc&config_id=" + val_1 + "&cord_n=" + cord_n.value + "&cord_s=" + cord_s + "&kp=" + kp + "&buc=" + buc);

	  el.style.display = 'none';
      chg_config();
  }
}

function row_over(obj) {
  var rowEl, cellEl;
  for(i=1; i<obj.cells.length; i++){
    cellEl = obj.cells[i];
    cellEl.style.backgroundColor = "#D9F2FF";
  }
}
function row_out(obj) {
  var rowEl, cellEl;

  for(i=1; i<obj.cells.length; i++){
    cellEl = obj.cells[i];
    cellEl.style.backgroundColor = "#FFF";
  }
}

function tipareste_oferta() {
  var val_1 = document.getElementById("config_id").value;
  window.open ("../PDF/configurator.php?kp=" + val_1, "PDF");
}

function add_cos() {
  var val_1 = document.getElementById("config_id").value;
  var xml = ajaxcall("../comp/servere/configurator.php?action=add_cos&config_id=" + val_1);

  window.location = "../ecom/cos";
}

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+', toolbar=0, status=1, resizable=1, scrollbars=1';
  win = window.open(mypage, myname, winprops);
  if (parseInt(navigator.appVersion) >= 4) { win.window.focus();}
}

/***********************************************
* Show Hint script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

var horizontal_offset="9px" //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
}
else{
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
}
return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
if ((ie||ns6) && document.getElementById("hintbox")){
dropmenuobj=document.getElementById("hintbox")
dropmenuobj.innerHTML=menucontents
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
dropmenuobj.style.visibility="visible"
obj.onmouseout=hidetip
}
}

function hidetip(e){
dropmenuobj.style.visibility="hidden"
dropmenuobj.style.left="-500px"
}

function createhintbox(){
var divblock=document.createElement("div")
divblock.setAttribute("id", "hintbox")
document.body.appendChild(divblock)
}

if (window.addEventListener)
window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
window.attachEvent("onload", createhintbox)
else if (document.getElementById)
window.onload=createhintbox

