
function display_large_images(id, title){
  if (small_screen())
    document.write("<a href=\"javascript:view_large_images('/autos/view_large_images/" + id + "')\">");
  else
    document.write('<a href="/autos/view_large_images/' + id + '?keepThis=true&TB_iframe=true&height=490&width=705" title="' + title + ' Photos" class="thickbox">');    
}

function view_large_images(URL){
      day = new Date();
      id = day.getTime();
      eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=730,height=500,left = 240,top = 212');");
}

function changeViewer(image, id){
    if (small_screen())
      document.getElementById("largeImage").href = "javascript:view_large_images('/autos/view_large_images/" + id + "')";        
    else
	document.getElementById("largeImage").href = "/autos/view_large_images/" + id + "?keepThis=true&TB_iframe=true&height=490&width=705";
    changeImage(image);    
}

function changeImage(imgName){
	directory='/images/user/listings_pictures/';
	document.mainImage.src=directory+imgName;	
}

function toggleLayer(whichLayer){
	if (document.getElementById){
		var style = document.getElementById(whichLayer).style;		
		style.display = (style.display==''||style.display=='none')?'block':'none';
	}
}

function hideLayer(whichLayer){
	if (document.getElementById){
		var style = document.getElementById(whichLayer).style;		
		style.display = 'none';
	}
}

//function


function changeParentLocation(inLocationURL) {
    self.parent.location.href = inLocationURL;
}


function addEditPictures(URL) {
	day = new Date();
	id = day.getTime();

	left = (screen.availWidth-710)/2;
	top_size = (screen.availHeight-570)/2;	
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=710,height=570,left=" + left + ",top=" + top_size + "');");
}

function addEditFreePicture(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=380,height=380,left = 425,top = 300');");
}


function directions(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=800,height=600,left = 240,top = 212');");
}

function showLayer(whichLayer){	
	var email = document.getElementById('email').style;
	var map = document.getElementById('googleMap').style;			
	var current = document.getElementById(whichLayer).style;
	
	if (whichLayer == 'email'){
		current.display='block';
		map.display='none';
	}
	else if (whichLayer == 'googleMap'){
		current.display='block';
		email.display='none';
	}	
}

function advancedSearch(){
	var form = document.getElementById('refine_search_form')
	form.action = "advanced_search";
	form.submit();
}

function submitRefineSearchForm(href) {
	make = "&cm_search_option[at_make_id]=" + document.getElementById(cm_search_option[at_make_id]);
	model = "&cm_search_option[at_model_id]=" + document.getElementByName(cm_search_option[at_model_id]);
	is_new = "&cm_search_option[is_new]=" + document.getElementByName(cm_search_option[is_new]);
	distance = "&cm_search_option[distance]=" + document.getElementById(cm_search_option[distance]);
	zip = "&cm_search_option[zip_code]=" + document.getElementById(cm_search_option_zip_code);
	bottom_price = "&cm_search_option[bottom_price]=" + document.getElementById(cm_search_option_bottom_price);
	top_price = "&cm_search_option[top_price]=" + document.getElementById(cm_search_option_top_price);
	posted = "&cm_search_option[posted]=" + document.getElementById(cm_search_option_posted);
	start_year = "&cm_search_option[start_year]=" + document.getElementById(cm_search_option_start_year);
	end_year = "&cm_search_option[start_year]=" + document.getElementById(cm_search_option_end_year);
	keywords = "&cm_search_option[keywords]=" + document.getElementById(cm_search_option_keywords);
	body_style = "&cm_search_option[at_body_style_id]=" + document.getElementById(cm_search_option[at_body_style_id]);

	href += make + model + is_new + distance + zip + bottom_price + top_price + posted + start_year + end_year + keywords + body_style
	window.location = href;
}

function calctotal(){	
	var total = 0.00;
	boxes = document.getElementsByName("cm_purchase[cm_package_id]");
	for (var i = 0; i < boxes.length; i++) {
		if (boxes[i].checked){
			var package_id = boxes[i].value;
			var amount = document.getElementById("packageprice_" + package_id).innerHTML;
			total += parseFloat(amount.substring(1));
		}
	}
	var totalstring = "$";
	totalstring += total.toString();
	var period = totalstring.indexOf(".");
	if(period == -1){
		totalstring += ".00";
	}
	else if((totalstring.length - period) == 2 ){
		totalstring +="0";
	}
	document.getElementById("totalamt").innerHTML = totalstring;
}

function advancedSearch(){
	var expandImg = "/images/autos/icons/advanced_plus.gif"
	var collapseImg = "/images/autos/icons/advanced_minus.gif"
	var img = document.getElementById('advancedImage')
	var link = document.getElementById('advancedLink')
		
	if(img.alt == "Collpase"){
		img.alt = "Expand"
		img.src = expandImg
		link.innerHTML = "Show Advanced Options";		
	}
	else {
		img.alt = "Collpase"
		img.src = collapseImg
		link.innerHTML  = "Hide Advanced Options";			
	}
	toggleLayer('advanced_search')
}
