// JavaScript Document
// Sankar R.
// April 09 2009
/*function showDetail(obj,n) {
	var boxId = "detailBox"+n;
	var boxObj = document.getElementById(boxId);
	
	if(obj.className == "ucExpButn"){
		obj.className = "ucExpButnA";
		boxObj.style.display="block";
	}else {
		obj.className = "ucExpButn";
		boxObj.style.display="none";
	}	 
	checkHeight();
}*/
function doffleRowClick(len){
for(var i=0;i<len;i++)
document.getElementsByClassName("usedRow1")[i].onmousemove = getElement;
}
document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
}; 

function getElement(){
	var n = this.id.split('-');
	var butId = "expBut"+n[1];
	var obj = document.getElementById(butId);
	var boxId = "detailBox"+n[1];
	var boxObj = document.getElementById(boxId);
	
	this.onmouseover = function(){
		this.style.backgroundColor =	"#f3f0d6";
	}
	
	this.onmouseout = function(){
		if(n[1]%2 ==0){
			this.style.backgroundColor =	"#EFEFEF";
		}else{
			this.style.backgroundColor =	"#FFFFFF";
		}
	}
	
	this.onclick = function(){
		if(obj.className == "ucExpButn"){
			obj.className = "ucExpButnA";
			boxObj.style.display="block";
		}else {
			obj.className = "ucExpButn";
			boxObj.style.display="none";
		}
		checkHeight();
	}
}
function checkHeight() {
	var divObj = document.getElementById("usedGrid");
	var offsetObj = document.getElementById("usedGridA");
	if(offsetObj.offsetHeight <= 314) {
		divObj.style.height = 314+"px";
	}else {
		divObj.style.height = offsetObj.offsetHeight+"px";
	}
}

function getCompareCheckBoxValue(id){
	
	var profileId = document.getElementById(id).value;
	if(document.getElementById(id).checked){
		if(document.getElementById('profileSelec').value==""){
			document.getElementById('profileSelec').value =profileId+",";
		}else{
			document.getElementById('profileSelec').value =document.getElementById('profileSelec').value+profileId+",";
		}
		//alert(document.getElementById('profileSelec').value);
	}else{
		document.getElementById('profileSelec').value = (document.getElementById('profileSelec').value).replace(profileId+",",""); 
		//alert(document.getElementById('profileSelec').value);
	}
	var n = id.split('_');
	m = n[1];
	//alert(m);
	//document.getElementsByClassName("usedRow1")[m].onclick = function(){}
	document.getElementById("usedRow-"+m).onclick = function(){}
	//alert(profileId);
//	profileSelec
}

function getCompareCar(){
	if(document.getElementById('profileSelec').value=="") {
		alert("Please Select at least Two cars to compare");
		return false;
	}else{
		var selecProfileId = document.getElementById('profileSelec').value;
		selecProfileId = selecProfileId.substring(0,selecProfileId.length-1);
		var selprofileIds = selecProfileId.split(',');
		var profileId1 ="";
		var profileId2 =""; 
		var profileId3 =""; 
		if(selprofileIds.length==2){
			
			profileId1 = selprofileIds[0];
			profileId2 = selprofileIds[1];
		}
		if(selprofileIds.length==3){
			profileId1 = selprofileIds[0];
			profileId2 = selprofileIds[1];
			profileId3 = selprofileIds[2];
		}	
		
		if(selprofileIds.length<2 || selprofileIds.length>3){
			alert("Please select either two or three cars to compare");
			return false;
		}
		document.usedCarsCompareForm.action="usedcars/compare.htm";
	}
}

function submitMoreDetails(yearValue,makeValue,modelValue,profileId){
	
	var urlVal = "usedcardetails/"+yearValue+"/"+makeValue+"/"+modelValue+"/"+profileId+".htm";
	
	document.usedCarsCompareForm.action = urlVal;
	document.usedCarsCompareForm.submit();
	return false;
}

function submitBySort(sortVal,urlVal){
	document.getElementById('sortByValue').value = sortVal;
	document.usedCarsCompareForm.action = urlVal;
	//alert(document.usedCarsCompareForm.action);
	document.usedCarsCompareForm.submit();
	return false;
}

function submitUsedCars(){
	document.usedCarsCompareForm.action = "usedcars.htm";
	//alert(document.usedCarsCompareForm.action);
	document.usedCarsCompareForm.submit();
	return false;
}


var currentPan = "panA";
var curButn = "";
var curArw ="";
function showHidePanel(n,flag){
	var panId = "pan"+n;
	var arwId = "arrow"+n;
	var panObj = document.getElementById(panId);
	var butObj = document.getElementById(n);
	var arwObj = document.getElementById(arwId);
	var butName = document.getElementById(n).name;
	//var divPos = document.getElementById("contPan").offsetTop;
	if(flag){
		panObj.style.display = "none";
		butObj.style.backgroundColor = "#C2C2C2";
		butObj.style.color = "#000";
		arwObj.style.background = "";
		curButn = "";
		curArw = "";
	} else {
		butObj.style.backgroundColor = "#3C3C3C";
		butObj.style.color = "#fff";
		arwObj.style.background = "url(../images/usedcars/arrow_down.gif) center bottom no-repeat";
		panObj.style.display = "block";
		//panObj.style.top = divPos+"px";
		if(panId != currentPan && curButn !=""){
			document.getElementById(currentPan).style.display = "none";
			document.getElementsByName(curButn)[0].style.backgroundColor = "#C2C2C2";
			document.getElementsByName(curButn)[0].style.color = "#000";
			document.getElementById(curArw).style.background = "";
		}	
		curButn = butName;
		curArw = "arrow"+n;
	}	
	currentPan = panId;
}
function toggleButton(obj,n) {
	butName = obj.name;
	var arwId = "arrow"+obj.id;
	var arwObj = document.getElementById(arwId);
	if(n==1){
		obj.style.backgroundColor = "#3C3C3C";
		obj.style.color = "#fff";
		arwObj.style.background = "url(../images/usedcars/arrow_down.gif) center bottom no-repeat";
	}else{
		if(butName != curButn){
		obj.style.backgroundColor = "#C2C2C2";
		obj.style.color = "#000";
		arwObj.style.background = "";
		}
	}
}