function getSubcategory(c_id, cmb){
   new ajax ('ajax.php', {postBody: 'method=getSubcategory&cid='+c_id, onComplete: get_subcat_callback, userVariable:cmb });
}

function get_subcat_callback(request, uservar){
	if(request.responseText!=""){
		combo = uservar;

		for(i=0; i< combo.options.length; i++){
			combo.options[0] = null;
		}
		
		arrTmp = request.responseText.split("^");
		for(i=0; i<arrTmp.length; i++){
			arrOption = arrTmp[i].split("|");
			var opt = new Option();
			opt.value = arrOption[0];
			opt.text = arrOption[1];
			
			combo.options[combo.options.length] = opt;
		}
	}
}
function check_password(password,user_id){
	new ajax ('ajax.php', {postBody: 'method=checkpassword&password='+password+"&user_id="+user_id, onComplete: check_password_callback});
	return false;
}
function check_password_callback(request, uservar){
	if(request.responseText=="OK"){
		if(document.frm_change_password.newpassword.value == document.frm_change_password.oldpassword.value){
			alert('Your current password and new password can not be same!!');
		}else{
			document.frm_change_password.submit();	
		}
	}else if(request.responseText=="INVALID"){
		alert('Your current password does not match with our record');	
	}else{
		alert('There was a problem communicating with the server\nPlease try later');
	}
}

function showsubCat(c_id, cmb){
	 
	   new ajax ('ajax.php', {postBody: 'method=getsubcat&cid='+c_id, onComplete: get_subcat_callback, userVariable:cmb });
	}

function get_subcat_callback(request, uservar){
	
	if(request.responseText!=""){
		
		combo = uservar;
		//alert(combo.options.length);
		for(i=0; i< combo.options.length; i++){
			combo.options[0] = null;
		}
		
		arrTmp = request.responseText.split("^");
		for(i=0; i<arrTmp.length; i++){
			arrOption = arrTmp[i].split("|");
			var opt = new Option();
			opt.value = arrOption[0];
			opt.text = arrOption[1];
			
			combo.options[combo.options.length] = opt;
		}
		
	}
}
function toggle(subId){
	thisSub = document.getElementById(subId);
	if (thisSub.style.display == "none") 
	{
		thisSub.style.display = "block";
		return true;
	} 
	else 
	{
		thisSub.style.display = "none";
		return true;				
	}
	return false;	
}

/*==================================for display make ====================================*/
function display_make(vehical_type_id,cmb){	
	new ajax ('ajax.php', {postBody: 'method=display_make&vehical_type_id='+vehical_type_id, onComplete: display_make_callback,userVariable:cmb});

}
function display_make_callback(request, uservar){
	
	combo = uservar;

	var clen=combo.options.length;

	for(i=0; i< clen ; i++){

		combo.options[0] = null;

	}	
	if(request.responseText!=""){
		
		arrTmp = request.responseText.split("^");

		for(i=0; i<arrTmp.length; i++){

			arrOption = arrTmp[i].split("|");

			var opt = new Option();

			opt.value = arrOption[0];

			opt.text = arrOption[1];

			combo.options[combo.options.length] = opt;

		}

	}else{

		for(i=0; i<combo.options.length; i++){

			combo.options[0] = null;

		}

	}

}
/*=======================================================================================*/
/*==================================for display Model ====================================*/
function display_model(car_make_id,vehical_type_id,cmb){		
	new ajax ('ajax.php', {postBody: 'method=display_model&car_make_id='+car_make_id+'&vehical_type_id='+vehical_type_id, onComplete: display_model_callback,userVariable:cmb});

}
function display_model_callback(request, uservar){

	combo = uservar;

	var clen=combo.options.length;

	for(i=0; i< clen ; i++){

		combo.options[0] = null;

	}	
	if(request.responseText!=""){
		
		arrTmp = request.responseText.split("^");

		for(i=0; i<arrTmp.length; i++){

			arrOption = arrTmp[i].split("|");

			var opt = new Option();

			opt.value = arrOption[0];

			opt.text = arrOption[1];

			combo.options[combo.options.length] = opt;

		}

	}else{

		for(i=0; i<combo.options.length; i++){

			combo.options[0] = null;

		}

	}

}
/*=======================================================================================*/
/*============================ tokyo timr ==============================================*/
function tTokyo(){
var GMT = 9; //GMT for Japan
var str;
var week = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
var month = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
var gmt = new Date();
var now = new Date();
var set = now.getTimezoneOffset();
gmt.setTime(now.getTime()+(set/60+parseFloat(GMT))*60*60*1000); /// Calculate with GMT
//gmt.setTime(now.getTime());
//Mon = gmt.getMonth() + 1;if(Mon < 10)Mon = "0" + Mon;
Mon = month[gmt.getMonth()];
Wee = week[gmt.getDay()];
Dat = gmt.getDate();    if(Dat < 10)Dat = "0" + Dat;
//Yr  = gmt.getYear();
hor = gmt.getHours();   if(hor < 10)hor = "0" + hor; 
if(hor<=12)
{
 	str = "AM";
}
else
{
	hor = hor - 12;
	//hor = "0" + hor;
	str = "PM";
}
min = gmt.getMinutes(); if(min < 10)min = "0" + min;
sec = gmt.getSeconds(); if(sec < 10)sec = "0" + sec;

var objtime = document.getElementById('timestr');
objtime.innerHTML= hor+":"+min+":"+sec+" "+str+"&nbsp;"+Wee+", "+Dat+"-"+Mon;//+"-"+Yr;
setTimeout('tTokyo()',999);
}
/*========================================================================================*/
/*==================================check character limit=================================*/
function textLimitCheck(theForm,theControl,maxLength)
{
	if (theForm.value.length > maxLength)
	{
		alert(maxLength + ' characters limit. \r Excessive data will be truncated.');
		theForm.value = theForm.value.substring(0, maxLength-1);
		theForm.focus();
	}
	theControl.value = theForm.value.length;
}
/*========================================================================================*/
/*
tTokyo();
*/
/*==================================Latest Stock=========================================*/
function latest_stock(){
	$('loader').show();	
	new ajax ('ajax.php', {postBody: 'method=latest_stock', onComplete: latest_stock_callback});

}
function latest_stock_callback(request, uservar){	
	$('truck').hide();
	$('machinery').hide();
	$('bike').hide();
	$('parts').hide();
	$('car').hide();
	$('van').hide();
	$('bus').hide();
	$('mini_truck').hide();
	$('muv').hide();
	$('loader').hide();	
	$('latest_stock').update(request.responseText);
	$('latest_stock').show();
}
/*========================================================================================*/
/*==================================Trucks=========================================*/
function truck(){
	$('loader').show();	
	new ajax ('ajax.php', {postBody: 'method=truck', onComplete: truck_callback});

}
function truck_callback(request, uservar){
	$('latest_stock').hide();
	$('machinery').hide();
	$('bike').hide();
	$('parts').hide();
	$('car').hide();
	$('van').hide();
	$('bus').hide();
	$('mini_truck').hide();
	$('muv').hide();
	$('loader').hide();
	$('truck').update(request.responseText);
	$('truck').show();
}
/*========================================================================================*/
/*==================================Machinery=========================================*/
function machinery(){
	$('loader').show();	
	new ajax ('ajax.php', {postBody: 'method=machinery', onComplete: machinery_callback});

}
function machinery_callback(request, uservar){
	$('latest_stock').hide();
	$('truck').hide();
	$('bike').hide();
	$('parts').hide();
	$('car').hide();
	$('van').hide();
	$('mini_truck').hide();
	$('muv').hide();
	$('bus').hide();
	$('loader').hide();
	$('machinery').update(request.responseText);
	$('machinery').show();
}
/*========================================================================================*/
/*==================================Bikes=========================================*/
function bike(){
	$('loader').show();	
	new ajax ('ajax.php', {postBody: 'method=bike', onComplete: bike_callback});

}
function bike_callback(request, uservar){	
	$('latest_stock').hide();
	$('truck').hide();
	$('machinery').hide();
	$('parts').hide();
	$('car').hide();
	$('van').hide();
	$('bus').hide();
	$('mini_truck').hide();
	$('muv').hide();
	$('loader').hide();	
	$('bike').update(request.responseText);
	$('bike').show();
}
/*========================================================================================*/
/*==================================Parts=========================================*/
function parts(){
	$('loader').show();	
	new ajax ('ajax.php', {postBody: 'method=parts', onComplete: parts_callback});

}
function parts_callback(request, uservar){
	$('latest_stock').hide();
	$('truck').hide();
	$('machinery').hide();
	$('bike').hide();
	$('car').hide();
	$('van').hide();
	$('bus').hide();
	$('mini_truck').hide();
	$('muv').hide();
	$('loader').hide();
	$('parts').update(request.responseText);
	$('parts').show();
}
/*========================================================================================*/
/*==================================car=========================================*/
function car(){
	$('loader').show();	
	new ajax ('ajax.php', {postBody: 'method=car', onComplete: car_callback});

}
function car_callback(request, uservar){
	$('latest_stock').hide();
	$('truck').hide();
	$('machinery').hide();
	$('bike').hide();
	$('parts').hide();
	$('van').hide();
	$('bus').hide();
	$('mini_truck').hide();
	$('muv').hide();
	$('loader').hide();
	$('car').update(request.responseText);
	$('car').show();
}
/*========================================================================================*/
/*==================================Van=========================================*/
function van(){
	$('loader').show();	
	new ajax ('ajax.php', {postBody: 'method=van', onComplete: van_callback});

}
function van_callback(request, uservar){
	$('latest_stock').hide();
	$('truck').hide();
	$('machinery').hide();
	$('bike').hide();
	$('parts').hide();
	$('car').hide();	
	$('bus').hide();
	$('mini_truck').hide();
	$('muv').hide();
	$('loader').hide();
	$('van').update(request.responseText);
	$('van').show();
}
/*========================================================================================*/
/*==================================Bus=========================================*/
function bus(){
	$('loader').show();	
	new ajax ('ajax.php', {postBody: 'method=buses', onComplete: bus_callback});

}
function bus_callback(request, uservar){
	$('latest_stock').hide();
	$('truck').hide();
	$('machinery').hide();
	$('bike').hide();
	$('parts').hide();
	$('mini_truck').hide();
	$('muv').hide();
	$('loader').hide();
	$('bus').update(request.responseText);
	$('bus').show();
}
/*========================================================================================*/
/*==================================Mini Truck=========================================*/
function mini_truck(){
	$('loader').show();	
	new ajax ('ajax.php', {postBody: 'method=mini_truck', onComplete: mini_truck_callback});

}
function mini_truck_callback(request, uservar){
	$('latest_stock').hide();
	$('truck').hide();
	$('machinery').hide();
	$('bike').hide();
	$('parts').hide();	
	$('muv').hide();
	$('loader').hide();
	$('mini_truck').update(request.responseText);
	$('mini_truck').show();
}
/*========================================================================================*/
/*==================================MUV=========================================*/
function muv(){
	$('loader').show();	
	new ajax ('ajax.php', {postBody: 'method=muv', onComplete: muv_callback});

}
function muv_callback(request, uservar){
	$('latest_stock').hide();
	$('truck').hide();
	$('machinery').hide();
	$('bike').hide();
	$('parts').hide();
	$('mini_truck').hide();
	$('loader').hide();
	$('muv').update(request.responseText);
	$('muv').show();
}
/*========================================================================================*/
/*=======================================Rating Function===================================*/
var displayRating = '';
function displayStars(rating, idName) {

	document.write('<center>');
	
	for(i=0; i < 10; i++ ) {
		if(i%2 ==0) {
			if(i < rating) {
				document.write('<img src=images/"__odd1.jpg" id="'+idName+'_'+(i+1)+'" title="'+(i+1)+'" onmouseout="changeout(this, '+rating+')" onmouseover="changeover(this, '+rating+')" onclick="updateRating(this, '+rating+')" />');
			}
			else {
				document.write('<img src="images/odd1.jpg" id="'+idName+'_'+(i+1)+'" title="'+(i+1)+'" onmouseout="changeout(this, '+rating+')" onmouseover="changeover(this, '+rating+')" onclick="updateRating(this, '+rating+')" />');
			}
		}
		else {
			if(i < rating) {
				document.write('<img src="images/__even1.jpg" id="'+idName+'_'+(i+1)+'" title="'+(i+1)+'" onmouseout="changeout(this, '+rating+')" onmouseover="changeover(this, '+rating+')" onclick="updateRating(this, '+rating+')" />');
			}
			else {
				document.write('<img src="images/even1.jpg" id="'+idName+'_'+(i+1)+'" title="'+(i+1)+'" onmouseout="changeout(this, '+rating+')" onmouseover="changeover(this, '+rating+')" onclick="updateRating(this, '+rating+')" />');
			}
		}
	}

	if (displayRating == '') {
		document.write('<br /><div class="ratingText" id="'+idName+'_showrating" >'+displayRating+'</div>');
	}
	else {
		document.write('<br /><div class="ratingText" id="'+idName+'_showrating" >'+totalRating+'</div>');
	}
	document.write('</center>');

}

function changeover(obj, rating) {
	
	var imageName = obj.src;
	var id = obj.title;
	var index = imageName.lastIndexOf('/');
	var filename = imageName.substring(index+1);
	var fullId = obj.id;
	var idName = fullId.substr(0, fullId.indexOf('_'));
	var totalRating = rating;

	for(i=0; i<id; i++) {
		var num = i+1;
		
		if (num%2 == 0) {
			document.getElementById(idName+'_'+num).src = 'images/_even1.jpg';			
		}
		else {
			document.getElementById(idName+'_'+num).src = 'images/_odd1.jpg';
		}
	}

}

function changeout(obj, rating) {

	var imageName = obj.src;
	var id = obj.title;
	var index = imageName.lastIndexOf('/');
	var filename = imageName.substring(index+2);
	var fullId = obj.id;
	var idName = fullId.substr(0, fullId.indexOf('_'));
	var totalRating = rating;
	
	for(i=0; i<id; i++) {
		var num = i+1;
		
		if (num%2 == 0) {
			if(i < totalRating) {
				document.getElementById(idName+'_'+num).src = 'images/__even1.jpg';			
			}
			else {
				document.getElementById(idName+'_'+num).src = 'images/even1.jpg';			
			}
		}
		else {
			if(i < totalRating) {
				document.getElementById(idName+'_'+num).src = 'images/__odd1.jpg';			
			}
			else {
				document.getElementById(idName+'_'+num).src = 'images/odd1.jpg';			
			}
		}
	}
}
/*==========================================================================================*/
/*====================================Change Currency=======================================*/
function changCurr(str,theForm)
{
	//theForm = document.frm_stock_list;
	var j = theForm.changeCurrBox.selectedIndex;
	var sym = theForm.changeCurrBox[j].text;
	
	var maxLimit = document.getElementById('tot_records').value;
	var currstr=str.split("^");
	var currId = currstr[0];
	var crate  = currstr[1];
	for(i=0;i<maxLimit;i++)
	{
		var jpy = 'price_local'+i;
		var curr = 'curr'+i;
		
		jpyVal = document.getElementById(jpy).value;
		if(jpyVal>0)
		{
			//newVal = parseInt((jpyVal * crate)/100);
			newVal = parseInt(jpyVal * crate);
			//newVal.toFixed(2);
			if(maxLimit==1){ // detail page no sym needed
				//newVal = addCommas(newVal);
				newVal = newVal.toFixed(2);
			}else{
				//newVal = sym+' '+addCommas(newVal);				
				newVal = newVal.toFixed(2)+'<br>('+sym+')';
			}
			document.getElementById(curr).innerHTML = newVal;
			setCurrency(currId);
		}
	}
}
/*========================================================================================*/
/*==================================setCurrency=========================================*/
function setCurrency(curry){
	new ajax ('ajax.php', {postBody: 'method=setcurrency&code='+curry, onComplete: setCurrency_callback});

}
function setCurrency_callback(request, uservar){	
}
/*==========================================================================================*/
