/*String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}*/

var reqModell= function (oXML) { 
	//alert(cId)
	var combo = document.getElementById(cId);
	combo.options.length = 0;
	var response = oXML.responseText;
	var items = response.split(";");
	var count = items.length;
		combo.options[0] =
		new Option('w'+String.fromCharCode(228)+'hlen','0');
	for (var i=0;i<count-1;i++)//ultil pt ca ultimul split e siru vid
	{
		var options = items[i].split("-");
		//daca scot wahlen folosesc combo.options[i]
		combo.options[i+1] =
		new Option(options[0],options[1]);
	}

		//document.getElementById("div_models").innerHTML=oXML.responseText;
 };
 
 var cId='';
 function popModel(wo,comboId){
 cId=comboId;	 
 var myConn = new XHConn();
 myConn.connect('models.php?car_id='+wo.value, 'POST', '', reqModell);
 }


var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage) 
{

    if ((version >= 5.5) && (version <7) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? 
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	   myImage.outerHTML = strNewHTML	  
    }
}

///////////////
function CheckAll(chk){
  if (chk.length != null){
    for (i = 0; i < chk.length; i++){
    	chk[i].checked = true ;
  	}
	}else{
		chk.checked = true ;
	}
}

function UnCheckAll(chk){
  if (chk.length != null){
    for (i = 0; i < chk.length; i++){
    	chk[i].checked = false ;
  	}
	}else{
				chk.checked = false ;
	}
}
var l_allChecked=false;
function CheckUncheckAll(chk){
  l_allChecked=!l_allChecked;
  if (chk.length != null){
    for (i = 0; i < chk.length; i++){
    	chk[i].checked =  l_allChecked ;
  	}
	}else{
		chk.checked = !chk.checked ;
	}	
}
///////////
function calcLeft_div_h(){
	var tlt_h=document.getElementById('topLeftTool').offsetHeight;
	var pg_h=document.getElementById('page').offsetHeight;
	//var ftr=document.getElementById('footer').offsetHeight;
	var avachk_h=document.getElementById('avachk').offsetHeight;
	var ftr_h=12;
	fLT_h=document.getElementById('ftrLeftTool').offsetHeight;
	var myH_h=pg_h-ftr_h-tlt_h-fLT_h-avachk_h
	document.getElementById('divScrollTextCont').style.height=myH_h.toString()+"px";
}
///////////////////
var theTable, theTableBody

var LeftToolSearchOrderBy
LeftToolSearchOrderBy="alpha"

function doneGetChildsLeftTool(oXML){
	var response = oXML.responseText;
	var items = response.split("<separator>");
	for(i=0;i<items.length;i++){
		 var items2 = items[i].split("<;>");
		 id_car=items2[1];
		 marca=items2[0];
		 model=items2[2];
		 id_auc=items2[3];
		 days_left=items2[4];
		 rowHtml='<a class="LeftToolTable_child_link" style="float:left" href="index.php?page=adet&auc='+id_auc+'">'+model+'</a><a class="LeftToolTable_child_link" style="float:right;"  href="index.php?page=adet&auc='+id_auc+'">&nbsp;'+days_left+' Tage</a><div style="clear:both"></div>';
		 document.getElementById("LeftToolTable_child_div"+id_car).innerHTML+=rowHtml;
	}
	var scrt=oScroll.css.top
	scrolltextInit();
	oScroll.css.top=scrt
	noScroll()
}
function getChildsLeftTool(id){
	 var myConn = new XHConn();
	
	if(document.getElementById("LeftToolTable_child_div"+id).innerHTML!=''){
		document.getElementById("LeftToolTable_child_div"+id).innerHTML='';
		document.getElementById("LeftToolPlus"+id).innerHTML='+';
		document.getElementById("LeftToolTable_child"+id).style.background="#CCBEAE"
	}else{
		document.getElementById("LeftToolPlus"+id).innerHTML='-';
		document.getElementById("LeftToolTable_child"+id).style.background="#CCBfa1"
		url="left_tool_get_childs.php?id="+id;
		myConn.connect(url, 'POST', '', doneGetChildsLeftTool);
	}
}

function doneLeftToolSearch(oXML){
	var response = oXML.responseText; 
	theTable=document.getElementById("contLeftToolTable")
	while(theTable.rows.length){ // length=0 -> stop 
        theTable.deleteRow(theTable.rows.length-1); 
	}
	var items = response.split("<separator>");
	 var newCelll;
	 for(i=0;i<items.length;i++){
		 var items2 = items[i].split("<;>");
		 id=items2[1];
		 nume=items2[0];
		 contor=items2[2];
		text='&nbsp;<a class="LeftToolTable_parent_link" href="index.php?page=auktionen&amp;marke='+id+'">'+nume+'</a>';
 		appendRow(text,'','LeftToolTable_parent'+id,'LeftToolTable_parent')
		
		if (contor>0){
			text='<a class="LeftToolTable_child_link" style="float:left;"  href="javascript:;"  onclick="getChildsLeftTool('+id+')"  >&nbsp;'+contor+' requests&nbsp;</a>'
			text+='<b><a class="LeftToolTable_child_link" style="float:right" href="javascript:;"  onclick="getChildsLeftTool('+id+')" >&nbsp;&nbsp;<span id="LeftToolPlus'+id+'">+</span>&nbsp;&nbsp;</a></b>'
			text+='<div style="clear:both"></div>'
		}else{
			text='<span>zero requests</span>'
		}
		text+='<div id="LeftToolTable_child_div'+id+'"></div>'
		appendRow(text,"#CCBEAE",'LeftToolTable_child'+id,"LeftToolTable_child")
		
 	}	

	document.getElementById("divText").style.height=theTable.offsetHeight
	scrolltextInit()
	calcLeft_div_h();
}

function topLeftToolSearch(){
	 var myConn = new XHConn();
	 nume=document.getElementById("topLeftToolInput").value
	 bifa=0
	 if(document.getElementById("availab").checked){
	 	bifa=1
	 }
	 url="left_tool_search.php?name="+nume+"&orderby="+LeftToolSearchOrderBy+"&bifa="+bifa;
	 myConn.connect(url, 'POST', '', doneLeftToolSearch);
}

function appendRow(text,bgColor,id,_class) {
	insertTableRow(-1,text,bgColor,id,_class)
	
}
function insertTableRow(where,text,bgColor,id,_class) {
	theTable=document.getElementById("contLeftToolTable")
	theTableBody = theTable.tBodies[0]
    var newCell
    var newRow = theTableBody.insertRow(where)
	//newRow.style.background=bgColor
    newCell = newRow.insertCell(0)
	newCell.style.background=bgColor
    newCell.innerHTML = text
	newCell.id=id
	newCell.setAttribute("class",_class) 
}

function removeRow(index) {
	 theTable=document.getElementById("contLeftToolTable")
	theTableBody = theTable.tBodies[0]
    theTableBody.deleteRow(index)
}

function orderByAva(){
	LeftToolSearchOrderBy="cntr"	
	topLeftToolSearch()
}

function orderByAlph(){
	LeftToolSearchOrderBy="alpha"
	topLeftToolSearch()
}

//////////////////
function basketAdd(idProd){

}

////


////////////////////
var ActiveRowCart;
ActiveRowCart=0;
function setActiveRowCart(rowNr){
	ActiveRowCart=rowNr;
	//document.getElementById("RowCart"+rowNr).style.background="#e1e9ee";
	if(!$("ajCartTable")){
		return
	}
	var elem = $("ajCartTable").getElementsByTagName("tr");
     for(i = 0; i < elem.length; i++) {
		obj=elem[i];
		obj.style.background="";	  
     }
	
	if($("RowCart"+ActiveRowCart)){
		$("RowCart"+ActiveRowCart).style.background="#e1e9ee";
	}
}

function highslideConfirm(txt){
	myhs=hs.htmlExpand(document, { contentId: 'hsConfirmdiv' ,maincontentText:txt} )	
	return hsConfirmFlag;
}


//
function list_highlight(_item_){
	_item_.style.background='#efefef';
}

function list_no_highlight(_item_){
	_item_.style.background='';
}

///
function seeProdukt(idP){
	window.location.href="index.php?page=productdetails&id="+idP
}
function aratameniuasta(i){
	gh=document.getElementById('subprodusele'+i);
	if(gh.style.display=='none'){
		gh.style.display='block';
	} else {
	gh.style.display='none';
	}
}
