var BF_HOST="http://www.busfox.com";
var BF_HOST_SSL="https://www.busfox.com";
var bf_login_box;

var bf_script_email_sender;


if(document.location.hostname=="dev.busfox.com"){
	BF_HOST="http://dev.busfox.com";
	BF_HOST_SSL="https://dev.busfox.com";
}

var bf_login_page=BF_HOST+"/customer/login_customer.php";
var bf_recovery_page=BF_HOST+"/customer/recovery_pwd.php";

function bf_write_login_box(){
	document.writeln("<script type=\"text/javascript\" src=\""+BF_HOST+"/customer/js/init_vars.php?lang="+bf_language+"\"></script>");
	document.writeln("<script type=\"text/javascript\" src=\""+BF_HOST+"/js/xmlhttp.js\"></script>");
	document.writeln("<link href=\""+BF_HOST+"/customer/css/bf_login_box.css\" type=\"text/css\" rel=\"stylesheet\"/>");
	document.writeln("<div id=\"bf_login_box\"></div>");
	
	setEvent(window,"load",bf_init_login_box);
}

function bf_init_login_box(){
	bf_login_box=bf_set_style_login_box();
	if(BF_LOGGED){
		bf_logged();
	}else{
		bf_fill_login_box();
	}
}

function bf_logged(){
	var a,div,img;
	var div_cont=bf_login_box;
	div=document.createElement("div");
	div.id="bf_logged_box";
	img=document.createElement("img");
	img.src=BF_HOST+"/img/shoppingcart_gray.gif";
	a=document.createElement("a");
	a.href=bf_iframe_url;
	a.innerHTML=BF_LBL_ECOMMERCE_LINK;
	div.appendChild(img);
	div.appendChild(a);
	div_cont.appendChild(div);
}

function bf_set_style_login_box(){
	var div_cont=document.getElementById("bf_login_box");
	var IE=(navigator.appName=="Microsoft Internet Explorer");
	if(IE){
		bf_height=(parseInt(bf_height)+20)+"px";
		bf_width=(parseInt(bf_width)+20)+"px";
	}
	div_cont.style.height=bf_height;
	div_cont.style.width=bf_width;
	div_cont.style.border=bf_border_width+" solid "+bf_border_color;
	div_cont.style.backgroundColor=bf_background_color;
	div_cont.style.fontFamily=bf_font_family;
	div_cont.style.fontSize=bf_font_size;
	div_cont.style.fontWeight=bf_font_weight;
	div_cont.style.color=bf_color;
	return div_cont;
}
////////////////////////////////////////////////////////////
function bf_post_send_msg(outcome){
	var div_cont=bf_login_box;
	div_cont.innerHTML="";
	var msg;
	var bf_lbl_link;
	var bf_function;
	var iframe=document.getElementById("bf_email_sender");
	
	if(outcome=='ok'){
		msg=BF_MSG_SEND_PWD_OK;
		bf_lbl_link=BF_GOTO_LOGIN;
		bf_function=bf_fill_login_box;
	}else{
		msg=BF_MSG_SEND_PWD_FAIL;
		bf_lbl_link=BF_LBL_RECOVERY;
		bf_function=bf_recovery_pwd;
	}
	
	img=document.createElement("img");
	img.src=BF_HOST+"/img/lucchettochiuso.gif";
	div_cont.appendChild(img);
	
	el=document.createElement("h3");
	el.appendChild(document.createTextNode(BF_RECOVERY_BOX_TITLE));
	div_cont.appendChild(el);
	
	div_cont.appendChild(document.createElement("br"));
	div_cont.appendChild(document.createElement("br"));
	
	div=document.createElement("div");
	div.appendChild(document.createTextNode(msg));
	div.appendChild(document.createElement("br"));
	
	div_cont.appendChild(div);
	
	a=document.createElement("a");
	a.id="bf_recovery";
	a.href="javascript:void(0);";
	a.innerHTML=bf_lbl_link;
	setEvent(a,"click",bf_function);
	
	div_cont.appendChild(a);
	
	bf_script_email_sender.parentNode.removeChild(bf_script_email_sender);
	//iframe.parentNode.removeChild(iframe);
}

function bf_send_recovered_pwd(){
	var email=document.getElementById("bf_email").value;
	var lang=document.getElementById("bf_language").value;
	var div_cont=bf_login_box;
	
	var params="bf_email="+email+"&bf_language="+lang+"&t="+get_ts();
	
	var script=document.createElement("script");
	script.type="text/javascript";
	script.src=BF_HOST+"/customer/recovery_pwd.php?"+params;
	bf_script_email_sender=document.getElementsByTagName("head")[0].appendChild(script);
}

function bf_recovery_pwd(){
	var div_cont=bf_login_box;
	div_cont.innerHTML="";
	
	img=document.createElement("img");
	img.src=BF_HOST+"/img/lucchettochiuso.gif";
	div_cont.appendChild(img);
	
	el=document.createElement("h3");
	el.appendChild(document.createTextNode(BF_RECOVERY_BOX_TITLE));
	div_cont.appendChild(el);
	
	div_cont.appendChild(document.createElement("br"));
	div_cont.appendChild(document.createElement("br"));
		
	form=document.createElement("form");
	form.method="POST";
	form.id="bf_recovery_form";
	form.action=bf_recovery_page;
	
	
	div=document.createElement("div");
	div.appendChild(document.createTextNode(BF_MSG_RECOVERY));
	div.appendChild(document.createElement("br"));

	input=document.createElement("input");
	input.style.marginTop="5px";
	input.id="bf_email";
	input.name="bf_email";
	input.type="text";
	div.appendChild(input);
	form.appendChild(div);
	
	input=document.createElement("input");
	input.type="hidden";
	input.id="bf_language";
	input.name="bf_language";
	input.value=bf_language;
	form.appendChild(input);
	
	input=document.createElement("input");
	input.type="button";
	input.id="bf_login_submit";
	input.value=BF_LBL_SEND;
	setEvent(input,"click",bf_send_recovered_pwd);
	form.appendChild(input);
	
	form.appendChild(document.createElement("br"));
	
	login_a=document.createElement("a");
	login_a.id="bf_recovery";
	login_a.href="javascript:void(0);";
	login_a.innerHTML=BF_GOTO_LOGIN;
	form.appendChild(login_a);
	setEvent(login_a,"click",bf_fill_login_box);
	
	form.appendChild(document.createElement("br"));
	
	div=document.createElement("div");
	div.id="bf_link_cont";
	
	a=document.createElement("a");
	a.id="bf_link";
	a.href="http://www.busfox.com";
	a.innerHTML="Busfox";
	a.style.fontFamily="Arial";
	a.style.fontSize="7pt";
	
	div.appendChild(a);
	form.appendChild(div);
	
	div_cont.appendChild(form);
}
////////////////////////////////////////////////////////////



function bf_fill_login_box(){
	var form,input,div,el,head,img;
	var div_cont=bf_login_box;
	div_cont.innerHTML="";
	
	img=document.createElement("img");
	img.src=BF_HOST+"/img/lucchettochiuso.gif";
	div_cont.appendChild(img);
	
	el=document.createElement("h3");
	el.appendChild(document.createTextNode(BF_LBL_BOX_TITLE));
	div_cont.appendChild(el);
	
	el=document.createElement("hr");
	el.className="spessore";
	//div_cont.appendChild(el);
	div_cont.appendChild(document.createElement("br"));
	div_cont.appendChild(document.createElement("br"));
	
	form=document.createElement("form");
	form.method="POST";
	form.action=bf_login_page;
	div=document.createElement("div");
	div.appendChild(document.createTextNode(BF_LBL_USERNAME));
	div.appendChild(document.createElement("br"));
	input=document.createElement("input");
	input.name="bf_username";
	input.type="text";
	div.appendChild(input);
	form.appendChild(div);
	
	div=document.createElement("div");
	div.appendChild(document.createTextNode(BF_LBL_PASSWORD));
	div.appendChild(document.createElement("br"));
	input=document.createElement("input");
	input.name="bf_password";
	input.type="password";
	div.appendChild(input);
	form.appendChild(div);
	

	input=document.createElement("input");
	input.type="submit";
	input.id="bf_login_submit";
	input.value=BF_LBL_LOGIN;
	form.appendChild(input);
	
	div=document.createElement("div");
	div.id="bf_retry";
	div.style.clear="none";
	div.style.textAlign="center";
	if(!BF_WRONG_LOGIN){div.style.visibility="hidden";}
	div.innerHTML=BF_LBL_WRONG;
	form.appendChild(div);
	
	recovery_a=document.createElement("a");
	recovery_a.id="bf_recovery";
	recovery_a.href="javascript:void(0);";
	recovery_a.innerHTML=BF_LBL_RECOVERY;
	form.appendChild(recovery_a);
	setEvent(recovery_a,"click",bf_recovery_pwd);
	
	form.appendChild(document.createElement("br"));
	
	div=document.createElement("div");
	div.id="bf_link_cont";
	
	a=document.createElement("a");
	a.id="bf_link";
	a.href="http://www.busfox.com";
	a.innerHTML="Busfox";
	a.style.fontFamily="Arial";
	a.style.fontSize="7pt";
	div.appendChild(a);
	form.appendChild(div);
	
	input=document.createElement("input");
	input.type="hidden";
	input.name="bf_iframe_url";
	input.value=bf_iframe_url;
	form.appendChild(input);
	
	input=document.createElement("input");
	input.type="hidden";
	input.name="bf_language";
	input.value=bf_language;
	form.appendChild(input);
	
	input=document.createElement("input");
	input.type="hidden";
	input.name="bf_login_url";
	input.value=document.location.href;
	form.appendChild(input);
	
	div_cont.appendChild(form);
	el=document.createElement("hr");
	el.className="spessore";
	div_cont.appendChild(el);
	
}


document.writeln("<script type=\"text/javascript\" src=\""+BF_HOST+"/js/utils.js\"></script>");