// JavaScript Document

function printpage(){
	
	window.print();  
}



// (C) 2000 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this  header
// NS4-6,IE4-6
// Fade effect only in IE; degrades gracefully

// =======================================
// set the following variables
// =======================================

// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 8000;

// Duration of crossfade (seconds)
var crossFadeDuration = 3

// Specify the image files
var Pic = new Array() // don't touch this
// to add more images, just continue
// the pattern, adding to the array below

Pic[0] = "../images/top_banner1.jpg";
Pic[1] = "../images/top_banner2.jpg";
Pic[2] = "../images/top_banner3.jpg";
Pic[3] = "../images/top_banner4.jpg";
//Pic[4] = "../images/top_banner5.JPG";
//Pic[5] = "../images/top_banner6.JPG";


// =======================================
// do not edit anything below this line
// =======================================

var t
var j = 0
var p = Pic.length

var preLoad = new Array()
for (i = 0; i < p; i++){
   preLoad[i] = new Image()
   preLoad[i].src = Pic[i]
}


function runSlideShow(){

	//detect browser type
	var browserName=navigator.appName; 
	
	//alert(browserName);
	
	if(browserName=="Microsoft Internet Explorer" || browserName=="Netscape" || browserName=="Opera"){
	
		if (document.all){
		  document.SlideShow.style.filter="blendTrans(duration=2)";
		  document.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
		  document.SlideShow.filters.blendTrans.Apply();
		}
		document.SlideShow.src = preLoad[j].src;
		if (document.all){
		  document.SlideShow.filters.blendTrans.Play();
		}
		j = j + 1;
		if (j > (p-1)) j=0;
		t = setTimeout('runSlideShow()', slideShowSpeed);
	}

}


// pop-up window for product pictures
var win= null;
function NewWindow(mypage,myname,w,h,scroll){
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
var settings ='height='+h+',';
settings +='width='+w+',';
settings +='top='+wint+',';
settings +='left='+winl+',';
settings +='scrollbars='+scroll+',';
settings +='resizable=yes';
win=window.open(mypage,myname,settings);
//if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
} 



//sets newsletter preference
function toggle_field_val(sku, checkbox, action, tag_id){
	
	
	//create xmlHttp object
	var xmlHttp;
	var browserName=navigator.appName; 
	
	
	if (browserName=="Netscape" || browserName=="Safari" || browserName=="Opera" || browserName=="Firefox")
	{
		xmlHttp=new XMLHttpRequest();
	}
	else if(browserName=="Microsoft Internet Explorer"){
	
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	
	}
	
	
	//on readystate function
	xmlHttp.onreadystatechange=function(){
	
		if(xmlHttp.readyState==4){
	
			//alert(xmlHttp.responseText);				
			document.getElementById(tag_id).innerHTML=xmlHttp.responseText;
									
		}
	}
	
	
	//new valur based on weather the checkox is checked or not
	var set_value;
	
	if(checkbox.checked)
		set_value="1";
		
	else set_value="0";		
		
		
	xmlHttp.open("POST","toggle_field.php",true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");       
	xmlHttp.send("&action="+action+"&value="+set_value+"&sku="+sku);	
	
	
}


//adds/removes sku to the list of products for which a suggested product will be choosen
function toggle_backgr(sku, list_id, list_id2, sku_list, table_obj){

	//add to the list
	if(document.getElementById(table_obj).bgColor=='#f5f5f5'){
		
		//remove this sku form the list only if it is in the list
		 if(document.getElementById(list_id).value.match(sku)==null)
		 	document.getElementById(list_id).value=document.getElementById(list_id).value+sku+",";
		 
		 //sku_list is null in case if the function is called by the right-hand side list
		 if(sku_list!="")
		 	document.getElementById(list_id2).value=sku_list;
		 
		 //toggle background
		 document.getElementById(table_obj).bgColor='#9ec7f0';
		 
		 //list the suggested products in the middle
		 list_suggested_prods(sku_list, "suggested_prods");

	}
	//remove from the list
	else if(document.getElementById(table_obj).bgColor=='#9ec7f0'){
		
		//remove this sku form the list only if it is in the list and only if it's called by the left-hand side list
		if(document.getElementById(list_id).value.match(sku)!=null && sku_list!="")
			document.getElementById(list_id).value=document.getElementById(list_id).value.replace(sku+",", "");
		
		//sku_list is null in case if the function is called by the right-hand side list
		if(sku_list!="")
			document.getElementById(list_id2).value="";
		
		//toggle background
		document.getElementById(table_obj).bgColor='#f5f5f5';
		
		//clear the list of suggested prods
		document.getElementById("suggested_prods").innerHTML="";

	}
	
}

//removes a suggested prod
function remove_segg_prod(sku, list_id){
	
	document.getElementById(list_id).value=document.getElementById(list_id).value.replace(sku+",", "");	
	
}



//updates the matches between main and suggested products
function update_sugg_prods(list_id1, list_id2){
	
	//alert(list_id1+", "+list_id2);
	
	var sku_list1 = document.getElementById(list_id1).value;
	var sku_list2 = document.getElementById(list_id2).value;
	
	//create xmlHttp object
	var xmlHttp;
	var browserName=navigator.appName; 
	
	
	if (browserName=="Netscape" || browserName=="Safari" || browserName=="Opera" || browserName=="Firefox")
	{
		xmlHttp=new XMLHttpRequest();
	}
	else if(browserName=="Microsoft Internet Explorer"){
	
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	
	}
	
	
	//on readystate function
	xmlHttp.onreadystatechange=function(){
	
		if(xmlHttp.readyState==4){
	
			//alert(xmlHttp.responseText);				
			document.getElementById("prod_update_status_id").innerHTML=xmlHttp.responseText;									
		}
	}			
	

	xmlHttp.open("POST","update_sugg_prods.php",true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");       
	xmlHttp.send("&sku_list1="+sku_list1+"&sku_list2="+sku_list2);	
	
	
	//update hidden fields for each product on the left hand site which conain the updated suggested prod list
	for(var i=0; i<sku_list1.split(",").length-1; i++){
		
		document.getElementById("sugg_prods_input_"+sku_list1.split(",")[i]).value=sku_list2;
		
	}
		
}



//list suggested products when adin selects a prod in the left hand list
function list_suggested_prods(sku_list, tag_id){
	
	
	//create xmlHttp object
	var xmlHttp;
	var browserName=navigator.appName; 
	
	
	if (browserName=="Netscape" || browserName=="Safari" || browserName=="Opera" || browserName=="Firefox")
	{
		xmlHttp=new XMLHttpRequest();
	}
	else if(browserName=="Microsoft Internet Explorer"){
	
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	
	}
	
	
	//on readystate function
	xmlHttp.onreadystatechange=function(){
	
		if(xmlHttp.readyState==4){
	
			//alert(xmlHttp.responseText);				
			document.getElementById(tag_id).innerHTML=xmlHttp.responseText;
									
		}
	}			
	
		
	xmlHttp.open("POST","list_suggested_prods.php",true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");       
	xmlHttp.send("&sku_list="+sku_list);	

	
}


//updates shipping method
function set_shipping(order_id, shipping_method, tag_id, lang){	
	
	//create xmlHttp object
	var xmlHttp;
	var browserName=navigator.appName; 
	
	
	if (browserName=="Netscape" || browserName=="Safari" || browserName=="Opera" || browserName=="Firefox")
	{
		xmlHttp=new XMLHttpRequest();
	}
	else if(browserName=="Microsoft Internet Explorer"){
	
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	
	}
	
	
	//on readystate function
	xmlHttp.onreadystatechange=function(){
	
		if(xmlHttp.readyState==4){
	
			//alert(xmlHttp.responseText);				
			//document.getElementById(tag_id).innerHTML=xmlHttp.responseText;
			
			//returns shipping price
			get_ship_price(shipping_method, tag_id, lang);
									
		}
	}	
		
		
	xmlHttp.open("POST","set_shipping.php",true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");       
	xmlHttp.send("&order_id="+order_id+"&shipping_method="+shipping_method);	
	
}

//update order totals
function update_order_totals(shipping_cost, subtotal_input_id, tps_input_id, tvq_input_id, shipping_span_id, total_span_id){
	
	//update shipping span
	/*
	shipping_cost=shipping_cost.toString();
	alert(shipping_cost.split(".")); */
	document.getElementById(shipping_span_id).innerHTML=shipping_cost;  //.numberFormat("0.00");
	
	var total = parseFloat(shipping_cost) 
				+ parseFloat(document.getElementById(subtotal_input_id).value)
				+ parseFloat(document.getElementById(tps_input_id).value)
				+ parseFloat(document.getElementById(tvq_input_id).value);
	
	
	//update total span
	document.getElementById(total_span_id).innerHTML="$"+Math.round(total*100)/100;

	//update paypal inputs
	update_paypal_inputs(parseFloat(shipping_cost), total);

}


//request gift form to appear on checkout page
function update_mark_as_gift(order_id, checkbox, tag_id, my_action, lang){
		
	//create xmlHttp object
	var xmlHttp;
	var browserName=navigator.appName; 
	
	
	if (browserName=="Netscape" || browserName=="Safari" || browserName=="Opera" || browserName=="Firefox")
	{
		xmlHttp=new XMLHttpRequest();
	}
	else if(browserName=="Microsoft Internet Explorer"){
	
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	
	}
	
	
	//on readystate function
	xmlHttp.onreadystatechange=function(){
	
		if(xmlHttp.readyState==4){
	
			//alert(xmlHttp.responseText);				
			document.getElementById(tag_id).innerHTML=xmlHttp.responseText;
									
		}
	}
	
	
	//new valur based on weather the checkox is checked or not
	var set_value;
	
	if(checkbox.checked)
		set_value="1";
		
	else set_value="0";		
		
		
	xmlHttp.open("POST","mark_as_gift.php",true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");       
	xmlHttp.send("&order_id="+order_id+"&set_value="+set_value+"&lang="+lang+"&my_action="+my_action);	
	
	
}


function get_ship_price(index, tag_id, lang){
	
	var shipping_info;
	
	//translations
	var capt_confirmed= new Array(" confirmed"," confirm&eacute;")
	
	//create xmlHttp object
	var xmlHttp;
	var browserName=navigator.appName; 
	
	
	if (browserName=="Netscape" || browserName=="Safari" || browserName=="Opera" || browserName=="Firefox")
	{
		xmlHttp=new XMLHttpRequest();
	}
	else if(browserName=="Microsoft Internet Explorer"){
	
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	
	}
	
	
	//on readystate function
	xmlHttp.onreadystatechange=function(){
	
		if(xmlHttp.readyState==4){
			
			shipping_info=xmlHttp.responseText.split(",");
	
			document.getElementById(tag_id).innerHTML=shipping_info[0] + capt_confirmed[ parseInt(lang)];

			//updates orders totals, i.e. shipping and total
			update_order_totals(shipping_info[1], "subtotal_input", "tps_input", "tvq_input", "shipping_span", "total_span");								
		}
	}
	
		
	xmlHttp.open("POST","get_ship_price.php",true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");       
	xmlHttp.send("&index="+index);	

}



//as user changes shipping method, paypal fields must be updated to reflect the new shipping charges
function update_paypal_inputs(ship_price, total){

	//update shipping input
	document.getElementById("paypal_shipping").value=ship_price;

	//update amount input
	//document.getElementById("paypal_amount").value=total;

}


//update thumbnail dimensions
function update_thumbn_size(table, src_filename, is_accessory, tbn_prefix, size_string, tbn_field, btn_object, loading_img_id){

	//change size_string to lowercase
	size_string=size_string.toLowerCase();
	
	//create xmlHttp object
	var xmlHttp;
	var browserName=navigator.appName; 
	
	
	if (browserName=="Netscape" || browserName=="Safari" || browserName=="Opera" || browserName=="Firefox")
	{
		xmlHttp=new XMLHttpRequest();
	}
	else if(browserName=="Microsoft Internet Explorer"){
	
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	
	}
	
	
	//on readystate function
	xmlHttp.onreadystatechange=function(){
	
		if(xmlHttp.readyState==4){
			
			//document.getElementById(tag_id).innerHTML=xmlHttp.responseText;	
					
			//enable the button and hide loading image			
			document.getElementById(loading_img_id).style.visibility="hidden";
			btn_object.disabled=false;
			
			alert(xmlHttp.responseText);			
			
		}
	}
	
		
	xmlHttp.open("POST","update_thumbn_size.php",true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");       
	xmlHttp.send("&table="+table+"&src_filename="+src_filename+"&is_accessory="+is_accessory+"&tbn_prefix="+tbn_prefix+"&size_string="+size_string+"&tbn_field="+tbn_field);		
	
	//disable the button and show loading image
	btn_object.disabled=true;
	document.getElementById(loading_img_id).style.visibility="visible";
	
}



//submits shipping info for orders that are marked as gift
function submit_gift_recep_info(order_id, tag_id, title, firstname, lastname, address, city, prov_state, country, postal_code, tel, email, message, my_action, lang){

//alert("&order_id="+order_id+"&firstname="+firstname+"&lastname="+lastname+"&address="+address+"&city="+city
//+"&prov_state="+prov_state+"&country="+country+"&postal_code="+postal_code+"&message="+message+"&my_action="+my_action);		

	//create xmlHttp object
	var xmlHttp;
	var browserName=navigator.appName; 
	
	
	if (browserName=="Netscape" || browserName=="Safari" || browserName=="Opera" || browserName=="Firefox")
	{
		xmlHttp=new XMLHttpRequest();
	}
	else if(browserName=="Microsoft Internet Explorer"){
	
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	
	}
	
	
	//on readystate function
	xmlHttp.onreadystatechange=function(){
	
		if(xmlHttp.readyState==4){
	
			//alert(xmlHttp.responseText);				
			document.getElementById(tag_id).innerHTML=xmlHttp.responseText;
									
		}
	}	
		
	xmlHttp.open("POST","mark_as_gift.php",true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");       
	xmlHttp.send("&order_id="+order_id+"&title="+title+"&firstname="+firstname+"&lastname="+lastname+"&address="+address+"&city="+city+"&prov_state="+prov_state+"&country="+country+"&postal_code="+postal_code+"&tel="+tel+"&email="+email+"&message="+message+"&my_action="+my_action+"&lang="+lang);	
	
	
}


//send inquiry email
function SendInq(from, from_email, message){

	//create xmlHttp object
	var xmlHttp;
	var browserName=navigator.appName; 
	
	//alert(browserName);
	
	if (browserName=="Netscape" || browserName=="Safari" || browserName=="Opera" || browserName=="Firefox")
	{
		xmlHttp=new XMLHttpRequest();
	}
	else if(browserName=="Microsoft Internet Explorer"){
	
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	
	}
	
	//on readystate function
	xmlHttp.onreadystatechange=function(){
	
		if(xmlHttp.readyState==4){
	
			//receive confirmation from server
			document.getElementById('err_msg4').innerHTML=xmlHttp.responseText;
			
			//clear fields values															
			document.form_mail.from_email.value="";
			document.form_mail.from.value="";	
			document.form_mail.message.value="";
			
			//enable the fields again
			document.form_mail.submit_btn.disabled=false;
			document.form_mail.message.disabled=false;
			document.form_mail.from.disabled=false;
			document.form_mail.from_email.disabled=false;						
			
			//hide loading immage
			document.getElementById('loading_img').style.visibility="hidden";

		}
	}
	
	if(from=="" || from_email=="" || message==""){
	
		document.getElementById('err_msg4').innerHTML="Please complete all the fields.";
	
	}
	else {	
			//disable all the fields	
			document.form_mail.submit_btn.disabled=true;
			document.form_mail.message.disabled=true;
			document.form_mail.from.disabled=true;
			document.form_mail.from_email.disabled=true;
			
			//show the loading image
			document.getElementById('loading_img').style.visibility="visible";
				
			//send the inquiry
			xmlHttp.open("POST","send_inq.php",true);
			xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");       
			xmlHttp.send("&from="+escape(from)+"&from_email="+escape(from_email)+"&message="+escape(message));
			
	}

  
}

//send inquiry email
function mailing_list_submit(action, email, tag_id, img_id){

	//create xmlHttp object
	var xmlHttp;
	var browserName=navigator.appName; 
	
	//alert(browserName);
	
	if (browserName=="Netscape" || browserName=="Safari" || browserName=="Opera" || browserName=="Firefox")
	{
		xmlHttp=new XMLHttpRequest();
	}
	else if(browserName=="Microsoft Internet Explorer"){
	
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	
	}
	
	//on readystate function
	xmlHttp.onreadystatechange=function(){
	
		if(xmlHttp.readyState==4){
	
			//receive confirmation from server
			document.getElementById(tag_id).innerHTML=xmlHttp.responseText;

			//hide loading immage
			document.getElementById(img_id).style.visibility="hidden";

		}
	}
	

	//show the loading image
	document.getElementById(img_id).style.visibility="visible";
		
	//send the inquiry
	xmlHttp.open("POST","mailing_list_submit.php",true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");       
	xmlHttp.send("&action="+action+"&email="+email);		

  
}

//prints out content of a DIV tag
function print_div(strid){

var prtContent = document.getElementById(strid);
var WinPrint = window.open('','','left=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
//prtContent.innerHTML=strOldOne;
}


//submit checkout comment
function checkout_comment(action, order_id, notes, tag_id, img_id, lang){

	//create xmlHttp object
	var xmlHttp;
	var browserName=navigator.appName; 
	
	//alert(browserName);
	
	if (browserName=="Netscape" || browserName=="Safari" || browserName=="Opera" || browserName=="Firefox")
	{
		xmlHttp=new XMLHttpRequest();
	}
	else if(browserName=="Microsoft Internet Explorer"){
	
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	
	}
	
	//on readystate function
	xmlHttp.onreadystatechange=function(){
	
		if(xmlHttp.readyState==4){
	
			//receive confirmation from server
			document.getElementById(tag_id).innerHTML=xmlHttp.responseText;

			//hide loading immage
			//document.getElementById(img_id).style.visibility="hidden";

		}
	}
	

	//show the loading image
	document.getElementById(img_id).style.visibility="visible";

		
	//send the inquiry
	xmlHttp.open("POST","checkout_comment.php",true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");       
	xmlHttp.send("&my_action="+action+"&order_id="+order_id+"&notes="+notes+"&lang="+lang);		

  
}


//lost password
function lost_pwd(action, tag_id, img_id, email, lang){
	
	//create xmlHttp object
	var xmlHttp;
	var browserName=navigator.appName; 
	
	//alert(browserName);
	
	if (browserName=="Netscape" || browserName=="Safari" || browserName=="Opera" || browserName=="Firefox")
	{
		xmlHttp=new XMLHttpRequest();
	}
	else if(browserName=="Microsoft Internet Explorer"){
	
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	
	}
	
	//on readystate function
	xmlHttp.onreadystatechange=function(){
	
		if(xmlHttp.readyState==4){
	
			//receive confirmation from server
			document.getElementById(tag_id).innerHTML=xmlHttp.responseText;

			//hide loading immage
			//document.getElementById(img_id).style.visibility="hidden";

		}
	}
	

	//show the loading image
	//document.getElementById(img_id).style.visibility="visible";

		
	//send the inquiry
	xmlHttp.open("POST","lost_pwd.php",true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");       
	xmlHttp.send("&my_action="+action+"&email="+email+"&lang="+lang);		
	
	
}


//verifies that the username doesn't exist
function check_if_username_exists(username, form_id, lang){
	
	
	//create xmlHttp object
	var xmlHttp;
	var browserName=navigator.appName; 
	
	//alert(browserName);
	
	if (browserName=="Netscape" || browserName=="Safari" || browserName=="Opera" || browserName=="Firefox")
	{
		xmlHttp=new XMLHttpRequest();
	}
	else if(browserName=="Microsoft Internet Explorer"){
	
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	
	}
	
	//on readystate function
	xmlHttp.onreadystatechange=function(){
	
		if(xmlHttp.readyState==4){
	
			//receive confirmation from server
			//document.getElementById(tag_id).innerHTML=xmlHttp.responseText;

			//hide loading immage
			//document.getElementById(img_id).style.visibility="hidden";
			
			if(xmlHttp.responseText==1){
				
				document.getElementById(form_id).submit();
			}				
			else if (xmlHttp.responseText==0)
			
				//english response
				if(lang==0) document.getElementById('span_email').innerHTML="This email (username) already exists, please choose another one";
				
				else if(lang==1) document.getElementById('span_email').innerHTML="Le courriel (nom d&#39;usager) que vous avez choisit existe d&eacute;j&agrave;, veuillez choisir un autre";
		}
	}
	

	//show the loading image
	//document.getElementById(img_id).style.visibility="visible";

		
	//send the inquiry
	xmlHttp.open("POST","username_check.php",true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");       
	xmlHttp.send("&username="+username);
	
	
}














