function noteshow(_8c){
	for(var i=0;i<5;i++){
		$("star"+(i+1)).src="/img/shared/star_off.png";
	}
	for(var i=0;i<_8c;i++){
		$("star"+(i+1)).src="/img/shared/star_on.png";
	}
}
function notesave(key,_8f){
	_8f=parseInt(_8f);
	if(_8f<1||_8f>5){
		alert("Erreur sur la note");
	}
	$("note").value=_8f;
	$("has_noted").value=1;
}
function noteclear(){
	setTimeout("notereset()",600);
}
function notereset(){
	noteshow($("note").value);
}

function popup(f,nom, w, h) {
	var top=0;
	var left=0;
	if (self.screen)
		left=(screen.width-(w+((screen.width*1)/100)));
	myWin = window.open(f, nom, 'resizable,screenX=0,screenY=0,scrollbars=yes,menubar=no,top='+top+',left='+left +',width=' + w + ',height=' + h );
	myWin.focus();
}

function DisplayMsg(myMsg) {
	if (document.getElementById)
	{
		document.getElementById("orderMessage").innerHTML = myMsg;
		document.getElementById("orderMessage").style.display = '';
	}
	else if (document.all)
	{
		document.all["orderMessage"].innerHTML = myMsg;
		document.getElementById("orderMessage").style.display = '';
	}
}

function clearMsgBox() {
	//DisplayMsg('');
	$('#orderMessage').style.display = 'none';
}

function DisplayWarning(myMsg) {
	if (document.getElementById)
	{
		document.getElementById("warning").innerHTML = myMsg;
		document.getElementById("warning").style.display = '';
	}
	else if (document.all)
	{
		document.all["warning"].innerHTML = myMsg;
		document.getElementById("warning").style.display = '';
	}
}

function DisplayMsg2(myMsg, boxid)
{
	if (document.getElementById)
	{
		document.getElementById(boxid).innerHTML = myMsg;
		document.getElementById(boxid).style.display = '';
	}
	else if (document.all)
	{
		document.all[boxid].innerHTML = myMsg;
		document.getElementById(boxid).style.display = '';
	}
}
function clearMsg2(boxid) {
	$(boxid).style.display = 'none';
}

function loadMobilePhoto(id, modelName, brandName, size)
{
	$('#modelPicture').fadeTo("fast", 0.33);
	// Set image source
	if (id==0 && modelName=='' && brandName=='') {
		var src = "/img/shared/phone_nopict.jpg";
		$('#modelPicture').attr("src", src);
	}
	else {
		var src = "/picture+" + size + "+" + brandName + "+" + modelName + "+" + id + ".jpg";
		var title = brandName + " " + modelName;
		$('#modelPicture').attr("src", src);
		$('#modelPicture').attr("alt", title);
		$('#modelPicture').attr("title", title);
		$('#modelPicture').fadeTo("slow", 1);
	}
}

function reset_form() {
	$("#bb_vip_ww").hide();
	$("#bb_vip_instant").hide();
	$("#bb_start").animate({opacity: 'show'}, 500, "linear");
}

function setNoProvider() {
	switch_unlock_solution('ww');
	$("#noProvider").addClass("ui-widget-sel");
	$("#divCountry").hide();
	$("#divNetwork").hide();
	$('input#providerName').val('factory_code');
	$('select#providerId').val('NONE');
	$("#ToolID").val(235); // force toolID to new MEP security
}

var provName = $('input#providerName').val();
var provId = $('select#providerId').val();
function switch_unlock_solution(service) {
	if (service=='instant') {
		$("#ToolID").val(215);
		$("#bb_start").hide();
		$("#bb_vip_ww").hide();
		$("#bb_vip_instant").animate({opacity: 'show'}, 500, "linear");
		$("#formContainer").animate({ height:200}, 800);
		$("div.box-quote").animate({ height:200}, 800);
		$("#noProvider").removeClass("ui-widget-sel");
	}
	else if (service=='ww') {
		$("#ToolID").val(228);
		$("#bb_start").hide();
		$("#bb_vip_instant").hide();
		$("#bb_vip_ww").animate({opacity: 'show'}, 500, "linear");
		$("#formContainer").animate({ height:210}, 800);
		$("div.box-quote").animate({ height:210}, 800);
	}
	$("span.hint:visible").hide();
}
function showInfo(mybox) {
	//get the position of the placeholder input
	var pos = mybox.offset();  
	var width = mybox.width();
	var tickbox = mybox.next("span.hint");
	tickbox.css( { "left": (pos.left + width + 2) + "px", "top":(pos.top - 9) + "px"} );
	tickbox.fadeIn(200);
	setTimeout(function(){
				tickbox.fadeOut(500);
			}, 3500);
}
function hideInfo(mybox) {
	mybox.next("span.hint").fadeOut(600);
}

function UnSetNoProvider() {
	if($("select#countryID").val()>0 && $("select#providerId").val()!='NONE') {
		if ($("select#providerId").val()=='NULL') switch_unlock_solution('ww');
		else switch_unlock_solution('instant');
	}
	else {
		reset_form();
	}
	if($("select#countryID").val()>0) {
		$("#divNetwork").show();
	}
	$("#divCountry").show();
	$("#noProvider").removeClass("ui-widget-sel");
	$('input#providerName').val(provName);
	$('select#providerId').val(provId);
}

/**********************/

function ajaxSetCountry(CountryID, modelID)
{
	$("#divNetwork").hide();
	$("#providerId").css({'background-color' : '', 'border' : ''});
	
	if (CountryID != "" && CountryID>0)
	{
		// Show Loading
		$("#divLoading").show();
		
		$(document).ready(function() {
			var providers;
			$.get('/xml/providers.xml.php?all_network=true&id=' + CountryID + '&modelId=' + modelID, function(data) {
				var thisCountry = $("select#countryID option:selected").text();
				providers = data;
				$('#providerId').empty();
				$('#providerId').append("<option value='NONE'> "+ thisCountry +" >> select :</option>");
				$('network', providers).each(function() {
					var optionvalue = $(this).attr('id');
					var optiontitle = $(this).text();
					$('#providerId').append("<option value='"+ optionvalue +"'>"+ optiontitle +"</option>");
				});
			}, 'xml'); 
			
			$("#divNetwork").show();
			$("#providerId").css({'background-color' : '#e0ffff', 'border' : '1px solid #4682b4'});
			
			// Hide Loading
			setTimeout(function(){
				$("#divLoading").slideUp();
			}, 500);
		});
	}
}

function ajaxAutoSelectProvider(provider_ID)
{		
		if (provider_ID)
		{
			$("select#providerId").val(provider_ID);
			$('#divCountry').show();
			$('#divNetwork').show();
		}
}
