﻿
var jsessionId;
var lastRowSelEl;
function selectRow(){
	eEl = window.event.srcElement;
	if(eEl.type!='checkbox'){
		if (eEl){
			if (lastRowSelEl){
				lastRowSelEl.className = '';
			}
			ePar = eEl.parentElement;
			ePar.className = 'sel';
			lastRowSelEl = ePar;
			rowNum = ePar.id.substr(7);
		}
	}
}

/* close back the row info table and return to full results view */
function hideRowInfo(page){
	rowInfoTable.style.display='none';
	resultsTable.style.height='370px';
	if(page != 'usedCars'){
		document.getElementById('actionDetails').disabled = true;
	}
	document.getElementById('backFullList').disabled = true;
	var innerTable = document.getElementById('mainTable');		// holds the results table
	for(var i=0; i<innerTable.rows.length-1; i++){
		if(innerTable.rows(i).className == 'sel'){				// find the selected row
			innerTable.rows(i).className = '';
			return;
		}
	}
}

function closeFloating(){
	floatingDiv.style.visibility='hidden';
}

function openFloatingPic(url){
	floatingHead.innerText = '';
	floatingDiv.style.visibility = 'visible';
	document.getElementById('floatingContent').parentElement.innerHTML = '<iframe id="floatingContent" width="100%" height="100%" src=do?inc=pictureFrame&pic=' + url + ' frameborder="0" scrolling="no"></iframe>';
}


function openFloatingMifrat(url_jsessionId){
        var url = '';
        var modelIdNum = getModelId(jsDealId, url_jsessionId);
        if(modelIdNum =='-1')
		url = '/modelSymbols.jsp;jsessionid='+url_jsessionId;
        else  
 	      	url = 'mifratim/mifrat-' + modelIdNum + '.jsp;jsessionid='+url_jsessionId;
        window.location.href=url;
}

function getModelId(dealId, url_jsessionId){
	try{
		// Load XML
		var xml = new ActiveXObject("Microsoft.XMLDOM");
		xml.async = false;
		xml.load("http://"+jsServer+"/getModelId.jsp;jsessionid="+url_jsessionId+"?dealId="+dealId);
		// check result
		return xml.documentElement.childNodes(0).getAttribute('ModelId');
	}
	catch(e){
		alert("ארעה שגיאה בטעינת המפרט עבור רכב זה.");
		return "-1";
	}
}

function openFloatingContact(){
	var url = '/do?inc=contactNow';
	floatingHead.innerText = 'מלא פרטיך ונתקשר אליך';
	floatingDiv.style.visibility = 'visible';
	document.getElementById('floatingContent').parentElement.innerHTML = '<iframe id="floatingContent" width="100%" height="100%" src=' + url + ' frameborder="0" scrolling="no"></iframe>';
}

function getSelectedRow(dealId){
	for(i=0; i<mainTable.rows.length-1; i++){					// loop on the cars rows in the ted table
		var id = mainTable.rows(i).cells(1).innerText;
		if(id == dealId){
			mainTable.rows(i).cells(0).fireEvent('onclick');
			break;
		}
	}
}

function doFind(){
	if(document.findFrm.find.value == ''){						// if find field is empty
		alertMsg(1, 'מילת מפתח');
		return false;
	}else{
		return true;
	}
}

/* fired onclick of טופס יצירת קשר button, collects deal and goes to contactUs */
function goContactUs(){
	var screenName = document.getElementById('screenName').value;
	window.location = '/do?pg=contactus&fromScreen=' + screenName + '&dealId=' + jsDealId;
}

/* fired form clicking the a column header */
function makeSort_(colName){
	if (colName != 'n1')
		SortCol = colName;
	else
		colName = SortCol;
	if (sortOrder == 'asc')
		sortOrder = 'desc';
	else if (sortOrder == 'desc')
		sortOrder = 'asc';
	else
		sortOrder = 'asc';
	var column = colName;
	var position = parseInt(colName) + 1;

        var url ='';
        if(pageName=='usedCars1')
       	  url = '' + pageName +'.jsp?'+ 'sort=' + position + '&sortOrder=' + sortOrder;
        else{
          if( jsessionId=='undefined' || jsessionId=='' || jsessionId==null)
             url = '/do?pg=' + pageName + '&sort=' + position + '&sortOrder=' + sortOrder;
          else{
             url = '/do'+jsessionId+'?inc=' + pageName + '&sort=' + position + '&sortOrder=' + sortOrder;
          }
        }

	if(typeof sortParamsStr != "undefined")
		url += sortParamsStr
	document.location.href = url;
}

