

var confDel = 'Are you sure you want to delete?';

//////////////////////// cookies for date and resolution /////////////////////

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

var dat = new Date();
var res = screen.width+'x'+screen.height;

$.cookie("userTime", dat.getTime(), { expires: 7 });
$.cookie("userRes", res, { expires: 7 });
//////////////////////// cookies for date and resolution /////////////////////


function sComm(wre)
{
	var txtVal = $("#sCommArea").val();
	
	if(txtVal=='' || txtVal=='Write your comment here...')
	{
		alert("Please write comment!");
	}
	else
	{
		//jQuery("#boxMess").html("<img src=\'_s/loading.gif\' alt=\'loading...\' />"); 

		
		$.ajax({type: 'POST', url: 'comme.php', data: "wre="+wre+"&wht=melComm&msg="+txtVal, cache: false, 
			success: function(htmLo){ 
			 document.getElementById('sCommArea').value='Write your comment here...';
			 
			 
			 //$("#lComm").prepend(htmLo);
			 
			 jQuery('#listComm').append(htmLo);
			 
			 //$("#lComm").addClass('hide');
			 //$("#vehComm div:last").append(htmLo);
			 jQuery('ul#listComm li:last').fadeIn(1000);
			 //$("#lComm").scrollTo("slow");
			 //$('#lComm').localScroll();
			 //$('#lComm').animate(200);
			 //jQuery.scrollTo('#lComm', 800 );
			 jQuery('ul#listComm li:last').effect("highlight", {color: "#99c0e1"}, 5000);

			 }});
		
		
	}
}


function sMess(wre, mid)
{
	var sbjVal = $("#sbj").val();
	var txtVal = $("#sMessArea").val();
	
	if(txtVal=='')
	{
		alert("Please write message!");
	}
	else
	{
		jQuery("#wrComm").html("<img src=\'_s/loading.gif\' alt=\'loading...\' />");
		
		
		$.ajax({type: 'POST', url: 'comme.php', data: "wre="+wre+"&wht=melMess&msg="+txtVal+"&sbj="+sbjVal+"&mid="+mid, cache: false, success: function(htmLo){ 
		$("#wrComm").html(htmLo); 
		
		//document.getElementById('sbj').value='';
		//document.getElementById('sMessArea').value='';
		
		}});
		

	}
}


function likeThis(vId)
{
	jQuery("#vLike").load("aj/vehLike/"+vId+"/");
}

function showPic (whichpic, thg) 
{
	if (document.getElementById) 
	 {
		  jQuery(".galThumbs a").removeClass("current");
		  jQuery("#thg"+thg).addClass("current");

		  document.getElementById('galMainImg').src = whichpic.href;
		  return false;
	 } 
	 else 
	 {
	  	return true;
	 }
}


function selMod(mVal)
{
	jQuery("#dispMod").html("<img src=\'_s/loading.gif\' alt=\'loading...\' />").load('ajload.php?wre=melModels&wht='+mVal);
}


function setAlCov(imId)
{
	jQuery('.capt > small').removeClass('confDel');
	jQuery('#hd'+imId).addClass('confDel');
	jQuery('.imgDef').html('Set as default image');
	jQuery('#iDe'+imId).html('<img src="/_s/i_check.png" alt="" /> <strong style="color: #2e9427;">Default image</strong>');
	
	//jQuery("#reqBack").load("aj/gaCovVeh/"+imId+"/");	
	
	jQuery("#reqBack").load("aj/gaCovVeh/"+imId+"/", null, function()
	{ 															 
		jQuery("#reqBack").effect("highlight", {color: "#99c0e1"}, 5000);
		//jQuery('#srtItm_'+imId).effect("highlight", {color: "#99c0e1"}, 5000);
	});

	//jQuery("#reqBack").slideToggle("normal").fadeTo(1000, 1).fadeOut(1000);
	
	
	
}

function delIm(imId)
{
	if ( $('#hd'+imId).hasClass("confDel")) { alert('You can`t delete image used as album cover!'); }
	else 
	{ 
		$('#srtItm_'+imId).addClass("confDel");
		
		if (confirm(confDel)) 
		{ 
			jQuery("#loi"+imId).html("<img src=\'_s/lib/ajaximg/load01.gif\' alt=\'loading...\' />");
			jQuery("#reqBack").load("aj/deImg/"+imId+"/", null, function() { $('#srtItm_'+imId).slideUp(700);  });
		}
		else
		{
			$('#srtItm_'+imId).removeClass("confDel");
		}
	}
}



function delComMe(deId, deWre)
{
	
		$('#com'+deId).addClass("confDel");
		
		//if(('#com'+deId)) alert('ok');
		
		if (confirm(confDel)) 
		{ 
			//jQuery("#loi"+imId).html("<img src=\'_s/lib/ajaximg/load01.gif\' alt=\'loading...\' />");
			jQuery("#lComm").load("aj/"+deWre+"/"+deId+"/", null, function() { $('#com'+deId).fadeOut(700);  });
		}
		else
		{
			$('#com'+deId).removeClass("confDel");
		}
	
}

function delItm(itId, itWre)
{
		jQuery('#di'+itId).addClass("confDel");
		
		if (confirm(confDel)) 
		{ 
			jQuery("#it"+itId).html("<img src=\'_s/lib/ajaximg/load01.gif\' alt=\'loading...\' />");
			jQuery("#it"+itId).load("aj/"+itWre+"/"+itId+"/", null, function() { jQuery("#di"+itId).fadeOut('slow');  });
		}
		else
		{
			jQuery('#di'+itId).removeClass("confDel");
		}
	
}

function shItm(vId, itWre)
{
	var shTxt = jQuery("#sht"+vId).html();
	jQuery("#it"+vId).load("aj/"+itWre+"/"+vId+"/", null, function() 
	   { 
	   
	   $('#hidenItms').slideUp(700);  
		if(shTxt == 'Show') { jQuery("#sht"+vId).html('Hide').removeClass('warning'); }
		else { jQuery("#sht"+vId).html('Show').addClass('warning'); }	
	   
	   });
	
	

}

//$jsH2 = ' $("#mel_make_id").change(function(){$("#dispMod").html("<img src=\'_s/loading.gif\' alt=\'loading...\' />").load(\'ajload.php?wre=melModels&wht=\'+mId); }); ';
/*
$jsH2 = ' $("#mel_make_id").change(function(){
var sMake = this.value;
$("#dispMod").html("<img src=\'_s/loading.gif\' alt=\'loading...\' />").load(\'ajload.php?wre=melModels&wht=\'+sMake);
}); '; */

function drMenu(drName, optId)
{
	var shYear = document.getElementById("selYear");
	var shMake = document.getElementById("selMake");
	var shModel = document.getElementById("selModel");
	var shCar = document.getElementById("locCar");
	var brNode = document.getElementById("brNode").getAttribute('value');
	var fldReq = 'Lst';
		
	if(drName == 'model')
	{
		shModel.setAttribute("value",optId);
		if(document.getElementById('goBtn')) { document.getElementById('goBtn').disabled = false; }
		var locUrl = baseURL+'index.php?cat=3&mod=1&vy='+shYear.getAttribute('value')+'&vma='+shMake.getAttribute('value')+'&vmo='+shModel.getAttribute('value')+'&bnode='+brNode+'&stx='+$('#year :selected').text()+' '+$('#make :selected').text()+' '+$('#model :selected').text();
		shCar.setAttribute("value",locUrl);
		//alert(locUrl);
	}
	else
	{
		switch(drName)
		{
			case 'year':
			if(document.getElementById('make')) { document.getElementById('make').disabled = true; }
			if(document.getElementById('model')) { document.getElementById('model').disabled = true; }
			if(document.getElementById('goBtn')) { document.getElementById('goBtn').disabled = true; }
			
			shYear.setAttribute("value",optId);
			fldReq = 'make'+fldReq;
			shMake.setAttribute("value",0);
			shModel.setAttribute("value",0);
			break;
			
			case 'make':
			if(document.getElementById('model')) { document.getElementById('model').disabled = true; }
			if(document.getElementById('goBtn')) { document.getElementById('goBtn').disabled = true; }
			
			shMake.setAttribute("value",optId);
			fldReq = 'model'+fldReq;
			shModel.setAttribute("value",0);
			break;
	
			case 'model':
			shModel.setAttribute("value",optId);
			break;
		}
	
		var reqYear = document.getElementById('selYear').getAttribute('value');
		var reqMake = document.getElementById('selMake').getAttribute('value');
		
		if(reqMake == null || reqMake == '') {reqMake = 0;}
		
		var reqUrl = baseURL+'ajdrmenu/'+drName+'/'+reqYear+'/'+reqMake+'/'+Math.random();
		//showConts(reqUrl, fldReq);
		//jQuery("#"+fldReq).load(reqUrl);	
		jQuery("#"+fldReq).html("<img src=\'"+baseURL+"_s/loading.gif\' alt=\'loading...\' />").load(reqUrl);
		//alert(reqUrl);
	}
}

function locateCar()
{
	window.location=document.getElementById("locCar").getAttribute('value');
}