
var ajax = new Array();

function getModelList(sel,ord,modl)
{
	var carCode = sel.options[sel.selectedIndex].value;
	var modlx = modl;
	var shortie = document.getElementById("modelSelect" + ord);
	shortie.options.length = 0;	// Empty model select box
	
	$("#modelSelect" + ord).hide();
	$('#loading_model').show();
	
	
	if(carCode.length>0){

		var index = ajax.length;
		ajax[index] = new sack();
		ajax[index].requestFile = 'phonecompareget.php?carsCode='+carCode+'&modl='+modlx;	// Specifying which file to get
		ajax[index].onCompletion = function(){ createModels(index,ord) };	// function that will be executed after file found
		ajax[index].runAJAX();		// Execute AJAX function

		$("#modelSelect" + ord).fadeIn(500);
		shortie.options.length = 0;	// Empty model select box
		
		shortie.options[shortie.options.length] = new Option('Choose the model','0');
		
		$('#loading_model').hide();
	}
	
}

function createModels(index,ord)
{
	var obj = document.getElementById('modelSelect' + ord);
	
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}

//////////////////////////////////////////////////////////////


function sendDetail(sel)
{
	var phoneID1 = document.specific.txtMake1.value;
	var phoneID2 = document.specific.txtMake2.value;
	var phoneID3 = document.specific.txtMake3.value;
	
	var mess2 = '<h1>Phone Comparison Error</h1><p>You must choose at least 2 models!</p>';
	var messdiff = '<h1>Phone Comparison Error</h1><p>You must choose different models!</p>';
	
	//if(carID1.length==0&&carID2.length==0&&carID3.length==0){alert ("You did not choose any car models!");return false;}
	if(phoneID1.length==0&&phoneID2.length==0&&phoneID3.length==0){csscody.alert('<h1>Phone Comparison Error</h1><p>You did not choose any phone models!</p>');return false;}
	
	if(phoneID1.length>0&&phoneID2.length==0&&phoneID3.length==0){csscody.alert(mess2);return false;}
	if(phoneID1.length==0&&phoneID2.length>0&&phoneID3.length==0){csscody.alert(mess2);return false;}
	if(phoneID1.length==0&&phoneID2.length==0&&phoneID3.length>0){csscody.alert(mess2);return false;}
	
	if(phoneID1==phoneID2){csscody.alert(messdiff);return false;}
	if(phoneID1==phoneID3){csscody.alert(messdiff);return false;}
	if(phoneID2==phoneID3){csscody.alert(messdiff);return false;}

	 window.location = 'phonecompresult.php?id1='+phoneID1+"&id2="+phoneID2+"&id3="+phoneID3;
}
////////////////////////////////////////////////////////////////
function showimage(ord){
	if (!document.images)
	return
	shortie = document.specific["modelSelect"+ord];
	origText = shortie.options[shortie.selectedIndex].text; 
	origVal = shortie.options[shortie.selectedIndex].value;
	
	
	
	$("#pictures"+ord).hide()
    .load(function () {
      $(this).fadeIn(2000);
    })
    .attr('src', 'http://www.mobiles4everyone.com/250/large' + origVal + '.jpg')
	

	//document.images["pictures"+ord].src = 'http://www.mobiles4everyone.com/250/large' + origVal + '.jpg'
	document.specific["txtModel"+ord].value = origText;
}

function showid(ord){
	shortie = document.specific["modelSelect"+ord];
	document.specific["txtMake"+ord].value = shortie.options[shortie.selectedIndex].value;
	document.specific["txtModel"+ord].value = shortie.options[shortie.selectedIndex].text;
}


function returner(){
var comboValue 
var selIndex = document.specific.makeSelect1.selectedIndex; 
comboValue = document.specific.makeSelect1.options[selIndex].value;

	if(comboValue.length>0){
		getModelList(document.specific.makeSelect1,1,document.specific.txtModel1.value);
		getModelList(document.specific.makeSelect2,2,document.specific.txtModel2.value);
		getModelList(document.specific.makeSelect3,3,document.specific.txtModel3.value);
		alert ("Your previous selection has been saved");
		
		getTrimList(document.specific.modelSelect1,1,document.specific.txtTrim1.value);
		showimage(1);
		getTrimList(document.specific.modelSelect2,2,document.specific.txtTrim2.value);
		showimage(2);
		getTrimList(document.specific.modelSelect3,3,document.specific.txtTrim3.value);
		showimage(3);
			
		
	}
}

/////////////////////////// Index Page combos
function sendIndex()
{
	var	shortie = document.specific["modelSelect1"];
	var phoneID = shortie.options[shortie.selectedIndex].value;
	
	
	

	

	 window.location = 'phonedetail.php?id='+phoneID;
}
