/* le fichier principal pour les javascripts */

var myLightbox = false; 
var expected = '';
var current_language = readCookie('language') || 'E';
//alert(current_language);
if(readCookie('language') == null || readCookie('language') == 'undefined'){
	createCookie('language','E')
}
if(readCookie('menu_item') == null){
	createCookie('menu_item',0);
}


//	setTimeout('alert("TT")',1000);
   
Event.onReady(function(){

			switchlang();
			 $('wrapper').style.display = 'inline';
	select_current(readCookie('menu_item'));

	
	$$('#lang_menu a').each(function(e){
		Event.observe(e,'click',function(evt){
			var nulang = e.innerHTML.match(/^\w/)[0];
			createCookie('language',nulang);
			current_language = readCookie('language');
			switchlang();
			Event.stop(evt);
		    });
	    })
	    
	// manage current menu highlight
	$$('#main_menu a').each(function(e,i){
		Event.observe(e,'click',function(evt){
			e = Event.element(evt);
			createCookie('menu_item',i);
			select_current(i);
			
		})
	})
	
	

	
	
	
	setInterval(function(){
		$$('input','select').each(function(i){
			if(i.getAttribute('type') == 'text' && !i.hasClassName('text_input')){
				i.addClassName('text_input')
			}
		})
		
	},500)
	// do other stuff
		if(window.innerWidth < 1000) window.resizeTo(1024,screen.availHeight);
		try{$('advert').style.height = $('body').offsetHeight + 'px'}catch(e){}
		basicurls = []
		$$('#left_col a').each(function(e){
			basicurls.push(e.href.gsub(new RegExp(BASE_URL+'/'),''))
		})
	
		    //ajaxify_links()
		    /*if(window.location.hash != ''){
			get_page(window.location.href.gsub(/#/,''))
		}
		setInterval(function(){
			if (window.location.hash != expected){
				get_page(window.location.href.gsub(/#/,''))
			}
			},500)*/

});
Event.observe(window,'load',function(){	

	//	   window.setInterval('galleryimagetips()',5000)

})

function callprint()
{
    prtContent = document.getElementById('the_watch');
 
    WinPrint = window.open();
    var bodystring = "";
 
  
	var theStyle = "#watchimg{width:200px;float:left;}"
	theStyle += "h4{";
	theStyle += "border-bottom:1px dotted #ccc;";
	theStyle += "color:#990000;";
	theStyle += "margin:2;";
	theStyle += "padding:2px;";
	theStyle += "}";
	


  WinPrint.document.write("<html><head><style>"+ theStyle + "</style></head>");

    bodystring += prtContent.innerHTML;
    bodystring += " <script type = 'text/javascript' language = 'javascript'> ";
    bodystring += "document.getElementById('noborder').style.display = 'none';";
    bodystring += " <\/script> ";
    WinPrint.document.write(bodystring);
    WinPrint.document.write('</body></html>');
    WinPrint.document.close();
    WinPrint.focus();
    WinPrint.print();
    WinPrint.close(); 
}

function evalScripts(text){

	text.gsub(/<script[^>]+>(.*)?<\/script>/,function(m){eval(m[1])});
}
function galleryimagetips(){
	if(readCookie('language') == 'E'){
		var myclass = 'en';
		var noclass = 'fr';
	}else{
		var myclass = 'fr';
		var noclass = 'en';
	}
	$$('.single_watch img').each(function(a){
		if(!a.has_been_done){
			a.has_been_done = true
			var text = [];
			   var children = $(a.parentNode.parentNode.parentNode.childNodes);
			 	for(i=0;i<children.length;i++){
if(children[i].style.display == 'none'){
	if($(children[i].firstChild).hasClassName(myclass)){
		if($(children[i].childNodes)[0].innerHTML)
		text[myclass] = $(children[i].childNodes)[0].innerHTML;
		else text[myclass] = '';
	}else{
		if($(children[i].childNodes)[0].innerHTML)
 		text[noclass] = $(children[i].childNodes)[0].innerHTML;
		else text[noclass] = '';
	}
}
/*
var content = '<img src="'+a.src+'" height="250"/><p '+(myclass == 'en' ? 'style="display:block"' : 'style="display:none"')+' class="en">'+text['en']+'</p><p '+(myclass == 'fr' ? 'style="display:block"' : 'style="display:none"')+' class="fr">'+text['fr']+'</p>'
a.parentNode.onclick = function(){popitup(a.alt,content);return false}
a.parentNode.setAttribute('target','_self')
*/  
    //new Tip(a,content,{title:a.alt});
				}
		}
	})
	}
//Event.observe(window,'load',function(){
//	$$('.gallery a').each(function(a){
//		var img = a.getElementsByTagName('img')[0]
//		new Tip(a,'<img src="'+a.href+'"/>',{title:a.title})
//	})
//})
function select_current(i){
	$$('#main_menu a').each(function(e,j){
		if(j==i){
			e.addClassName('current');
		}else{
			e.removeClassName('current');
		}
	})
}




function switchlang(){

    /*$$('.en').show();
    $$('.fr').hide();
    */

		$$('.en','.fr').each(function(e){
		e.hide();
		if(readCookie('language') == 'E' && (e.className.indexOf('en') > -1)){
			e.show();
		}else if(readCookie('language') == 'F' && (e.className.indexOf('fr') > -1)){
		    //		    setTimeout(e.show(),12000);
		    			e.show();
			}
			})
}
function get_page(url){


//alert("T2EST");
	$('right_col').innerHTML = "<p><img src=\"/public/images/layout/loading.gif\"/></p>";
	window.location.hash = url.match(/rodania.informatiquejfb.com\/(.*)$/)[1] || ''
	
	expected = window.location.hash
		new Ajax.Request(url, {
		  method: 'get',
		  requestHeaders: ['User-Agent','ajax_call'],
		  onComplete: change_body
	 	});
}
function change_body(o){

	$('right_col').innerHTML = o.responseText;
	evalScripts(o.responseText)
	$('advert').style.height = $('right_col').offsetHeight + 'px';
	myLytebox = new LyteBox();
}
function ajaxify_links(){
    /*		$$('#left_col a').each(function(e,i){
			e.setAttribute('onclick',"get_page(\'"+e.href+"\');return false;");
			e.setAttribute('href','#');
			});*/
}

function popitup(alt,content) {
	var newwindow2=window.open('','name','height=400,width=400');
	newwindow2.focus();
	var tmp = newwindow2.document;
	tmp.write('<html><head><title>popup</title>');
	tmp.write('<link rel="stylesheet" href="css/main.css">');
	tmp.write('</head><body><h3>'+alt+'</h3>'+content+'</p>');
	tmp.write('</body></html>');
	tmp.close();
}

function popup(url)
{
    newwindow=window.open(url,'name','height=480,width=560');
    if (window.focus) {newwindow.focus()}
}



function change_brand(){

	//select_collection_watch($F('brand'));  
  var url = "/brand/change_brand2";
  var myAjax = new Ajax.Request(
  url,{
    method: 'post',
    requestHeaders: ['User-Agent','ajax_call'],
    postBody: 'brand='+ $F('brand_id'),
    onSuccess: updateCollectionListbox2
  });
}



function change_brand2(){
	//select_collection_watch($F('brand'));
    
  var url = "/brand/change_brand";
  var myAjax = new Ajax.Request(
  url,{
    method: 'post',
    requestHeaders: ['User-Agent','ajax_call'],
    postBody: 'brand='+ $F('brand'),
    onSuccess: updateCollectionListbox2
  });
}

function updateCollectionListbox2(t){
	var tchaine = t.responseText;
	var arrayID = new Array();
	var arrayName = new Array();
	var lb = document.getElementById('collection_id');
    
 
     var newOpt;

    //Effacer le liste box
    for (var i=lb.options.length-1; i>=0; i--){
        lb.options[i] = null;
    }
    //    lb.selectedIndex = -1;
	
	var data = tchaine.split(/\;|\||\=/);
	var sets = [];

  	var i =0;
	num  = 0;
	while(data.length > 0)
	{     
	    
		sets[i] = {};
		sets[i][data.shift()] = data.shift()
		sets[i][data.shift()] = data.shift()
		newOpt = document.createElement("OPTION");
  	
  		//alert(sets[i]['id'].toString());
  		if(sets[i]['id'].toString() != 'undefined'){
		    //alert(sets[i]['id']);
		    if(sets[i]['value'] == " ")
			{
			    num = i;
			}
  			newOpt.text =sets[i]['value'];
  			newOpt.value = sets[i]['id'];
			if( sets[i]['id'] == "45")
			{
				 num = i;
				//newOpt.selected = true;
			}
 			lb.options.add(newOpt);
 		}
		i++;
 		//alert("end");

	}
	lb.selectedIndex =num;
	change_collection(0);	
	

}


function change_brand_for_ul(){
    
	//select_collection_watch($F('brand'));  
  var url = "/brand/change_brand";
  var myAjax = new Ajax.Request(
  url,{
    method: 'post',
    requestHeaders: ['User-Agent','ajax_call'],
    postBody: 'brand='+ $F('brand'),
    onSuccess: update_collectionul
  });
}

 function vider ( elementId ) {
    var elt = document.getElementById( elementId );
    while ( elt.hasChildNodes() ) {
	elt.removeChild( elt.firstChild );
    }
}
function update_collectionul(t){
$('watch_ul').innerHTML = t.responseText;
 switchlang();
    /*
	var tchaine = t.responseText;
	var arrayID = new Array();
	var arrayName = new Array();
	var ul = document.getElementById('watchul');

	var li;
	var ahref;
	var atext;


	vider('watchul');
	

	var data = tchaine.split(/\;|\||\=/);
	var sets = [];
	var i =0;

	while(data.length > 0){

                sets[i] = {};
                sets[i][data.shift()] = data.shift()
	        sets[i][data.shift()] = data.shift()
                //alert(sets[i]['id'].toString());

                if(sets[i]['id'].toString() != 'undefined'){

		    li = document.createElement('LI');
		    ul.appendChild(li);
		    ahref = document.createElement('A');

		    var id =  sets[i]['id'];
		    ahref.onclick = function() { list_watches( id); };
		    //		    ahref.onclick = function


		    //	    ahref.setAttribute('href','brand/list_watches/'+ sets[i]['id']);
		    //		    ahref.onclick = "list_watches("+sets[i]['id']+")"; //'list_watches('+ sets[i]['id'] + ')';
		    //		    	    	    ahref.setAttribute('onclick','list_watches('+ sets[i]['id'] + ');');
	            li.appendChild(ahref);
       	            atext = document.createTextNode(sets[i]['value']);
		    ahref.appendChild(atext);

                }
                i++;
                //alert("end");

	    }

    */
}
function updateCollectionListbox(t){
    
	var tchaine = t.responseText;
	var arrayID = new Array();
	var arrayName = new Array();
	var lb = document.getElementById('collection_id');
    
 
     var newOpt;

    //Effacer le liste box
    for (var i=lb.options.length-1; i>=0; i--){
        lb.options[i] = null;
    }
    lb.selectedIndex = -1;
	
	var data = tchaine.split(/\;|\||\=/);
	var sets = [];
	
	
	//Ajouter l'option Tous
	newOpt = document.createElement("OPTION");
  	
  	newOpt.text ="Tous";
  	newOpt.value = 0;
  	lb.options.add(newOpt);
  	
  	var i = 0;
	while(data.length > 0)
	{
		sets[i] = {};
		sets[i][data.shift()] = data.shift()
		sets[i][data.shift()] = data.shift()
		newOpt = document.createElement("OPTION");
  	
  		//alert(sets[i]['id'].toString());
  		if(sets[i]['id'].toString() != 'undefined'){
  		//	alert(sets[i]['id']);
  			newOpt.text =sets[i]['value'];
  			newOpt.value = sets[i]['id'];
 			lb.options.add(newOpt);
 		}
		i++;
 		//alert("end");

	}
	
	

}


function updatedealerlist(){
	
 var url = "/dealer/updatedealerlist";
  var myAjax = new Ajax.Request(
  url,{
    method: 'post',
    requestHeaders: ['User-Agent','ajax_call'],
    postBody: '&city='+ $F('city') + '&province=' + $('province').value,
    onSuccess: Rupdatedealerlist
  });
}

function Rupdatedealerlist(t){
	$('DealerList').innerHTML = t.responseText;
	
}


function select_collection_watch(currency)
{

  if(typeof(currency) == "undefined"){
    currency = "undefined";
  }
 
  //$('watchrs').style.display = 'none';
  var pars = $F('collection');

  var url = "/brand/request_collection_watch";
  var myAjax = new Ajax.Request(
  url,{
    method: 'post',
    requestHeaders: ['User-Agent','ajax_call'],
    postBody: 'option='+pars+'&currency='+currency+'&brand='+$F('brand'),
    onSuccess: requesterwatch
  });
}


function requesterwatch(t)
{

  $('watchrs').innerHTML = t.responseText;
  //$('watchrs').style.display = 'inline';
   //   update_bank_cart_currency();
}


function  initialize_default(){
      
   // change_brand_for_ul();
    //    change_brand();
    //    select_collection_watch();
  $('watch_displays').style.display = 'none';
  $('the_watch').style.display = 'none';
  $('loading_gif').style.display ='block';
  random_collection();
    switchlang();
    //$('watch_displays').hide();

}

function change_pricelevel(userid){
   var pars = $F('pricelevel');
   
  var url = "/useradmin/change_pricelevel";
  var myAjax = new Ajax.Request(
  url,{
    method: 'post',
    requestHeaders: ['User-Agent','ajax_call'],
    postBody: 'pricelevel='+pars+'&userid='+userid,
    onSuccess: nothing
  });

}

function change_pricelevel(userid,objid){
   var pars = $F(objid);
   
  var url = "/useradmin/change_pricelevel";
  var myAjax = new Ajax.Request(
  url,{
    method: 'post',
    requestHeaders: ['User-Agent','ajax_call'],
    postBody: 'pricelevel='+pars+'&userid='+userid,
    onSuccess: nothing
  });

}


function updatePriceLvl(objid)
{
/*alert(objid);
	$F('pricelevel') = $F(objid);*/
	
	setSelectedIndex($('price_level'),$F(objid));
}

function setSelectedIndex(s, v) {
    for ( var i = 0; i < s.options.length; i++ ) {
        if ( s.options[i].value == v ) {
            s.options[i].selected = true;
            return;
        }
    }
}

function GetSelectedValue(s) {
    for ( var i = 0; i < s.options.length; i++ ) {
        if (s.options[i].selected) {
           return s.options[i].text;
            
        }
    }
	return -1;
}

function nothing(t){
}

function call_useradmin(id,quel){
    var pars = id;
    var url = "/dealeradmin/"+quel+"/"+id;
    if(quel.match('delete') == 'delete'){
	var x=window.confirm("Are you sure you want to delete ?")
	    if(x){

		var myAjax = new Ajax.Request(
					      url,{
					  method: 'post',
					  requestHeaders: ['User-Agent','ajax_call'],
					  onSuccess: user_appear,
					  onFailure: delfaile
					      });
	    }
    }
    else{


	var myAjax = new Ajax.Request(
				      url,{
					  method: 'post',
					  requestHeaders: ['User-Agent','ajax_call'],
					  onSuccess: user_appear,
					  onFailure: delfaile
				      });
    }


}

function user_appear(t){
   $('the_user').innerHTML = t.responseText;   
   switchlang();
}


function call_manageuser(id,quel){
    var pars = id;
    var url = "/dealeradmin/"+quel+"/"+id;
    if(quel.match('delete') == 'delete'){
	var x=window.confirm("Are you sure you want to delete ?")
	    if(x){

		var myAjax = new Ajax.Request(
					      url,{
					  method: 'post',
					  requestHeaders: ['User-Agent','ajax_call'],
					  onSuccess: manage_user,
					  onFailure: delfaile
					      });
	    }
    }
}

function manage_user(t){
   $('manage_user').innerHTML = t.responseText;   
   $('the_user').innerHTML = "";

}



function add_user_from_dealeradmin(id){

   
  var url = "/dealeradmin/add_users/"+id;
  var myAjax = new Ajax.Request(
  url,{
    method: 'post',
    requestHeaders: ['User-Agent','ajax_call'],
    onSuccess: the_user_appear
  });


  
}


function edit_user_from_dealeradmin(id){
    var url = "/dealeradmin/add_users/"+id;
    var myAjax = new Ajax.Request(
				  url,{
				      method: 'post',
				      requestHeaders: ['User-Agent','ajax_call'],
				      onSuccess: the_user_appear
				  });

}


function the_user_appear(t){
    $('the_users').innerHTML = t.responseText;
}


function list_watches(colid){
    //    alert('test');
  $('watch_displays').style.display = 'block';
  $('the_watch').style.display = 'block';
  $('random_watch').style.display = 'none';

    var url = "/brand/list_watches/"+colid;
    var myAjax = new Ajax.Request(
				  url,{
				      method: 'post',
				      requestHeaders: ['User-Agent','ajax_call'],
				      onSuccess: list_watches_appear
				  });
    
}




function list_watches_brand(brand){

  $('watch_displays').style.display = 'block';
  $('the_watch').style.display = 'block';
  $('random_watch').style.display = 'none';

    var url = "/brand/list_watches_brand/"+brand;
    var myAjax = new Ajax.Request(
				  url,{
				      method: 'post',
				      requestHeaders: ['User-Agent','ajax_call'],
				      onSuccess: list_watches_appear
				  });
    
}




function list_watches_appear(t){

    //    alert(t.responseText);
    $('watch_displays').innerHTML = t.responseText;
    $obj = document.getElementById("CurrentCollection");
    
    if($obj != null)
    {
        $obj.style.display="block";
    }
}


function delfaile(){
}


function get_single_watch(id){

    var url = "/brand/watch/"+id;
    var myAjax = new Ajax.Request(
                                  url,{
                                      method: 'post',
                                      requestHeaders: ['User-Agent','ajax_call'],
                                      onSuccess: single_watch_appear

                                  });

}



function get_single_watch_pair(id){

    var url = "/brand/watch_pair/"+id;
    var myAjax = new Ajax.Request(
                                  url,{
                                      method: 'post',
                                      requestHeaders: ['User-Agent','ajax_call'],
                                      onSuccess: single_watch_appear

                                  });

}



function effecter(){
  var i = new Effect.Appear('the_watch');
}


function single_watch_appear(t){

   $('the_watch').innerHTML = t.responseText;

 

   switchlang();
//window.the_watch.focus();
}


function random_collection(){

    var objbrand = document.getElementById("BrandId");
    var idbrand = -1;
    if(objbrand != null)
    {
        idbrand = objbrand.value;
    }
  
    var url = "/brand/random_watch/"+idbrand;
    var myAjax = new Ajax.Request(
                                  url,{
                                      method: 'post',
                                      requestHeaders: ['User-Agent','ajax_call'],
                                      onSuccess: random_collection_appear,
										onFailure: delfaile
                                  });
}


function random_collection_appear(t){

  $('random_watch').innerHTML = t.responseText;
$('loading_gif').style.display ='none';
}

function initialize_default_watch(id){
    var url = "/brand/initialize_default_watch/"+id;
    var myAjax = new Ajax.Request(
                                  url,{
                                      method: 'post',
                                      requestHeaders: ['User-Agent','ajax_call'],
                                      onSuccess: single_watch_appear

                                  });
    
}

function public_stats(id){
    var url = "/brand/public_stats/"+id;
    var myAjax = new Ajax.Request(
                                  url,{
                                      method: 'post',
                                      requestHeaders: ['User-Agent','ajax_call'],
                                      onSuccess: nothing

                                  });
    
}



function dealer_stats(id){

    var url = "/brand/dealer_stats/"+id;
    var myAjax = new Ajax.Request(
                                  url,{
                                      method: 'post',
                                      requestHeaders: ['User-Agent','ajax_call'],
                                      onSuccess: nothing

                                  });
    
}


function find_doc(){
var pars = $('reference');

  var url = "/userguide/finddoc/"+ pars.value;
  var myAjax = new Ajax.Request(
  url,{
    method: 'post',
    requestHeaders: ['User-Agent','ajax_call'],
    onSuccess: fill_right
  });


}

function fill_right(t){
   $('right').innerHTML = t.responseText;
   switchlang();
}


function shower(id)
{

 $(id).style.display = 'block';
}

function hider(id)
{
 $(id).style.display = 'none';
}


function change_brand_collection_on_of()
{

    var url = "/admin/manage_collection_on_off_by_brand_id/"+ $F('brand');
    var myAjax = new Ajax.Request(
				  url,{
				      method: 'post',
				      requestHeaders: ['User-Agent','ajax_call'],
				      onSuccess: manage_collection_on_off_appear
				  });
}


function manage_collection_on_off_appear(t)
{
	$('manage_collection_on_of').innerHTML = t.responseText;
   switchlang();
}


function isCatalogueCheck(f)
{
	if($(f).Catalogue.checked == true)
	{
		$('spanCity').innerHTML = '*';
		$('spanCodepostal').innerHTML = '*';
		$('spanStates').innerHTML = '*';
		$('spanCountry').innerHTML = '*';
		$('spanCivicStreet').innerHTML = '*';

		$('spanSubject').innerHTML = '&nbsp;';
		$('spanComment').innerHTML = '&nbsp;';
	}
	else
	{
		$('spanCity').innerHTML = '&nbsp;';
		$('spanCodepostal').innerHTML = '&nbsp;';
		$('spanStates').innerHTML = '&nbsp;';
		$('spanCountry').innerHTML = '&nbsp;';
		$('spanCivicStreet').innerHTML = '&nbsp;';
		

		$('spanSubject').innerHTML = '*';
		$('spanComment').innerHTML = '*';
	}
}

function setShippingValue(obj)
{
	var url = "/main/get_shipping_price/"+ obj.value;
    var myAjax = new Ajax.Request(
				  url,{
				      method: 'post',
				      requestHeaders: ['User-Agent','ajax_call'],
				      onSuccess: setShippingPrice
				  });
}


function addSeparatorsNF(nStr, inD, outD, sep)
{
	nStr += '';
	var dpos = nStr.indexOf(inD);
	var nStrEnd = '';
	if (dpos != -1) 
	{
		nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
		nStr = nStr.substring(0, dpos);
	}
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(nStr)) 
	{
		nStr = nStr.replace(rgx, '$1' + sep + '$2');
	}
	return nStr + nStrEnd;
}

function priceFormat(Price)
{
	Price += ""; //--- A simple way to convert a Float to a String...
	if (Price.indexOf(".") < (Price.length - 3))
		Price = Math.round(Price * Math.pow(10, 2)) / Math.pow(10, 2);
	Price += ""; //--- A simple way to convert a Float to a String...

	if (Price.indexOf(".") == 0)
		Price = "0" + Price;
	else if (Price.indexOf(".") == -1)
		Price = Price + ".00";

	if (Price.indexOf(".") == Price.length - 1)
		Price = Price + "00";
	else if (Price.indexOf(".") == Price.length - 2)
		Price = Price + "0";
       
	return addSeparatorsNF(Price, '.', '.', ',').replace(",","");
}


function setShippingPrice(t)
{
	//alert(t.responseText);
	
	if(t.responseText == -1)
	{
		alert("error");
		$('progress_shipping').style.display="none";
		$('Shipping_Method_Pop').style.display = "none";
		$('zip').value = "";
		return false;
	}
	
	$('progress_shipping').style.display="none";
	$("ShippingResult").innerHTML = t.responseText;
	switchlang();
	//$('totalInfo').style.display="";
/*	$('tot2').style.display="";
	$('tot3').style.display="";*/
	/*
	if(t.responseText < 0)
	{
		
		$('progress_shipping').style.display="none";
		$('zip').value = "";
		
		return false;
	}
$('progress_shipping').style.display="none";
	priceFormat(t.responseText);
	
	if(parseFloat(t.responseText) > 0 && parseFloat($("subTotal").innerHTML) < 1000)
	{
		$("shipPrice").innerHTML = priceFormat(t.responseText);
		var total = parseFloat($("subTotal").innerHTML) + parseFloat($("shipPrice").innerHTML);
		
		if($("TR_ID_14" ).style.display != "none")
		{
			$("PX_ID_14" ).innerHTML = priceFormat(total * parseFloat($("RT_ID_14").value));
			total = total +  (total * parseFloat($("RT_ID_14").value)) ;
		}
		if($("TR_ID_15" ).style.display != "none")
		{
			$("PX_ID_15" ).innerHTML = priceFormat(total * parseFloat($("RT_ID_14").value));
			total =  total +  (total * parseFloat($("RT_ID_15").value)) ;
		}
		if($("TR_ID_16" ).style.display != "none")
		{
			$("PX_ID_16" ).innerHTML = priceFormat(total * parseFloat($("RT_ID_14").value));
			total =  total +  (total * parseFloat($("RT_ID_16").value)) ;
		}
		
		
		
		$("TOTAL_PRICE").innerHTML = priceFormat(total);
	}
	else
	{
		$("shipPrice").innerHTML = "0.00";
	}
	
	*/
}

function taxein(obj)
{
	var url = "/main/get_taxe/"+ obj.value;
	var myAjax = new Ajax.Request(
			  url,{
				contentType: 'text/xml',
				  method: 'post',
				  onComplete: setTaxePrice
			  });
}

function setTaxePrice(req)
{

	//---- if IE 
	if(document.all)
	{
		var info = req.responseXML.documentElement;
	}
	else //---- if mozilla
	{
		var info = req.responseXML;
	}

	$("TOTAL_PRICE").innerHTML = priceFormat(parseFloat($("subTotal").innerHTML) + parseFloat($("shipPrice").innerHTML));
	$("TR_ID_14" ).style.display = "none";
	$("TR_ID_15" ).style.display = "none";
	$("TR_ID_16" ).style.display = "none";
	var taxes = info.getElementsByTagName("taxe");
	for(i = 0 ; i < taxes.length; i ++)
	{
		var taxeName = taxes[i].getElementsByTagName("taxeName")[0].childNodes[0].nodeValue;
		var taxeID = taxes[i].getElementsByTagName("taxeId")[0].childNodes[0].nodeValue;
		var taxeRate = taxes[i].getElementsByTagName("taxeRate")[0].childNodes[0].nodeValue;
		
		
		$("TX_ID_" + taxeID).innerHTML = taxeName;
		$("TR_ID_" + taxeID).style.display = "";
		$("RT_ID_" + taxeID).value = taxeRate;
		
		
		$("PX_ID_" + taxeID).innerHTML = priceFormat(parseFloat($("TOTAL_PRICE").innerHTML)  * taxeRate);
		$("TOTAL_PRICE").innerHTML = priceFormat((parseFloat($("TOTAL_PRICE").innerHTML) + parseFloat($("PX_ID_" + taxeID).innerHTML)));
		
	}



}

function isCanada(obj)
{
	var strClick = "";

	strClick +='<span class="en" lang="en">Click here.</span>';
	strClick +='<span class="fr" lang="fr">Clicker ici.</span>';


	
	$("shipPrice").innerHTML = 	"0.00";
	$("hship").value = strClick;
	$('ShippingResult').innerHTML = "";

	$('zip').value = "";
	switchlang();
				
	if(obj.value == "1")
	{
		$("TR_ID_14" ).style.display = "none";
		$("TR_ID_15" ).style.display = "none";
		$("TR_ID_16" ).style.display = "none";
		$("prv_list").style.display = "";
		$("tr_zip_code").style.display = "";
		$("TOTAL_PRICE").innerHTML = priceFormat(parseFloat($("subTotal").innerHTML) + parseFloat($("shipPrice").innerHTML));
	}
	else if(obj.value == "2")
	{
		$("TR_ID_14" ).style.display = "none";
		$("TR_ID_15" ).style.display = "none";
		$("TR_ID_16" ).style.display = "none";
		$("tr_zip_code").style.display = "";
		$("prv_list").style.display = "none";
		$("TOTAL_PRICE").innerHTML = priceFormat(parseFloat($("subTotal").innerHTML) + parseFloat($("shipPrice").innerHTML));
	}
	else
	{
		$("TR_ID_14" ).style.display = "none";
		$("TR_ID_15" ).style.display = "none";
		$("TR_ID_16" ).style.display = "none";
		setSelectedIndex($('states'),"");
		$("prv_list").style.display = "none";
		$("tr_zip_code").style.display = "none";
		$("TOTAL_PRICE").innerHTML = priceFormat(parseFloat($("subTotal").innerHTML) + parseFloat($("shipPrice").innerHTML));
		
	}
}

function isValidZipcode(zipcode) {
	if (!(zipcode.length == 5)) return false;
	if (!isNumeric(zipcode)) return false;
	return true;
}

function isValidPostalcode(postalcode) {
if (postalcode.length == 6 && postalcode.search(/^[a-zA-Z]\d[a-zA-Z]\d[a-zA-Z]\d$/) != -1) return true;
	else if (postalcode.length == 7 && postalcode.search(/^[a-zA-Z]\d[a-zA-Z](-|\s)\d[a-zA-Z]\d$/) != -1) return true;
	else return false;

return true;
}

function validZip(zip) {
	if (isValidZipcode(zip) == false && isValidPostalcode(zip) == false) { 
		//alert ("Incorrect US or Canadian Postal Code Format.");
		return false;
	}
	return true;
}

function validZip1(zip)
{
if (zip.match(/^[0-9]{5}$/)) {
return true;
}
zip=zip.toUpperCase();
if (zip.match(/^[A-Z][0-9][A-Z][0-9][A-Z][0-9]$/)) {
return true;
}
if (zip.match(/^[A-Z][0-9][A-Z].[0-9][A-Z][0-9]$/)) {
return true;
}
//alert('*** Bad ZIP.');
return false;
}


function calculating()
{
	var lan = 'en';
	if(current_language == 'F')
	{
		lan = 'fr';
	}
	
		
	//Canada poste Canada
	if(/*$F('shipping_preference') == "24" && */
		$F('country') == "1" && 
		$F('states') != "" && 
		validZip1($F('zip')))
	{
		//$('totalInfo').style.display="none";
		$('progress_shipping').style.display="";

		var url = "/shoping/GetShippingPC/";
		var myAjax = new Ajax.Request(
				  url,{
					  method: 'post',
					  requestHeaders: ['User-Agent','ajax_call'],
					  postBody: 'zip=' + $F('zip')+"&country=CANADA"+"&lang=" +lan,
					  onSuccess: setShippingPrice
				  });
	}
	else if(/*$F('shipping_preference') == "24" && */
	$F('country') == "2"  && 
	validZip1($F('zip')))
	{
		$('progress_shipping').style.display="";

		var url = "/shoping/GetShippingPC/";
		var myAjax = new Ajax.Request(
				  url,{
					  method: 'post',
					  requestHeaders: ['User-Agent','ajax_call'],
					  postBody: 'zip=' + $F('zip') + "&country=US"+"&lang=" +lan,
					  onSuccess: setShippingPrice
				  });
	}
	else //if($F('shipping_preference') == "24")
	{
		$('progress_shipping').style.display="";

		var url = "/shoping/GetShippingPC/";
		var myAjax = new Ajax.Request(
				  url,{
					  method: 'post',
					  requestHeaders: ['User-Agent','ajax_call'],
					  postBody: 'zip=' + $F('zip') + "&country="+GetSelectedValue($('country'))+"&lang=" +lan,
					  onSuccess: setShippingPrice
				  });
			  
	
		/*$('progress_shipping').style.display="";

		var url = "/shoping/GetShippingPC/";
		var myAjax = new Ajax.Request(
				  url,{
					  method: 'post',
					  requestHeaders: ['User-Agent','ajax_call'],
					  postBody: 'zip=' + $F('zip') + "&country=US"+"&lang=" +lan,
					  onSuccess: setShippingPrice
				  });*/
	}
	
}


function calculating_(ship_pref)
{
	var lan = 'en';
	if(current_language == 'F')
	{
		lan = 'fr';
	}
	
		
	//Canada poste Canada
	if(ship_pref == "24" && 
		$F('country') == "1" && 
		$F('states') != "" && 
		validZip1($F('zip')))
	{
		//$('totalInfo').style.display="none";
		$('progress_shipping').style.display="";

		var url = "/shoping/GetShippingPC/";
		var myAjax = new Ajax.Request(
				  url,{
					  method: 'post',
					  requestHeaders: ['User-Agent','ajax_call'],
					  postBody: 'zip=' + $F('zip')+"&country=CANADA"+"&lang=" +lan,
					  onSuccess: setShippingPrice
				  });
	}
	else if(ship_pref == "24" && 
	$F('country') == "2"  && 
	validZip1($F('zip')))
	{
		$('progress_shipping').style.display="";

		var url = "/shoping/GetShippingPC/";
		var myAjax = new Ajax.Request(
				  url,{
					  method: 'post',
					  requestHeaders: ['User-Agent','ajax_call'],
					  postBody: 'zip=' + $F('zip') + "&country=US"+"&lang=" +lan,
					  onSuccess: setShippingPrice
				  });
	}
	else if(ship_pref == "24")
	{
		$('progress_shipping').style.display="";

		var url = "/shoping/GetShippingPC/";
		var myAjax = new Ajax.Request(
				  url,{
					  method: 'post',
					  requestHeaders: ['User-Agent','ajax_call'],
					  postBody: 'zip=' + $F('zip') + "&country="+GetSelectedValue($('country'))+"&lang=" +lan,
					  onSuccess: setShippingPrice
				  });
			  
	
		/*$('progress_shipping').style.display="";

		var url = "/shoping/GetShippingPC/";
		var myAjax = new Ajax.Request(
				  url,{
					  method: 'post',
					  requestHeaders: ['User-Agent','ajax_call'],
					  postBody: 'zip=' + $F('zip') + "&country=US"+"&lang=" +lan,
					  onSuccess: setShippingPrice
				  });*/
	}
	
}

function OpenShipping()
{
	var bok = false;
	
	if(
		$F('country') == "1" && 
		$F('states') != "" && 
		validZip1($F('zip')))
	{
		$('Shipping_Method_Pop').style.display = "";
		bok = true;
	}
	else if($F('country') == "2" && validZip1($F('zip')))
	{
		$('Shipping_Method_Pop').style.display = "";
		bok = true;
	}
	else if($F('country') != "")
	{
		$('Shipping_Method_Pop').style.display = "";
		bok = true;
			
	}
	if(bok)
	{
		//calculating();
	}
	return bok;
}

function CloseShip()
{
	$('Shipping_Method_Pop').style.display = "none";
	$('ShippingResult').innerHTML = "";
}

function CloseShippingINFO()
{
	
	$('Shipping_Method_Pop').style.display = "none";
	//alert($('grp_ship').length);
	var rd_value = getCheckedValue(document.forms['shoping'].elements['grp_ship']);
	if(rd_value != "")
	{
		$('sship').innerHTML = $("name_" + rd_value).innerHTML + "<br />";
		//alert(rd_value);
		$("shipPrice").innerHTML = priceFormat($("prix_" + rd_value).innerHTML);
		$('hi_ship_methode').value = $("ship_name_" + rd_value).value + " : " +  $("name_" + rd_value).innerHTML;
		//alert($("ship_name_" + rd_value).value);
		var total = parseFloat($("subTotal").innerHTML) + parseFloat($("shipPrice").innerHTML);

		if($("TR_ID_14" ).style.display != "none")
		{
			$("PX_ID_14" ).innerHTML = priceFormat(total * parseFloat($("RT_ID_14").value));
			total = total +  (total * parseFloat($("RT_ID_14").value)) ;
		}
		if($("TR_ID_15" ).style.display != "none")
		{
			$("PX_ID_15" ).innerHTML = priceFormat(total * parseFloat($("RT_ID_14").value));
			total =  total +  (total * parseFloat($("RT_ID_15").value)) ;
		}
		if($("TR_ID_16" ).style.display != "none")
		{
			$("PX_ID_16" ).innerHTML = priceFormat(total * parseFloat($("RT_ID_14").value));
			total =  total +  (total * parseFloat($("RT_ID_16").value)) ;
		}



		$("TOTAL_PRICE").innerHTML = priceFormat(total);
		
		var strClick = "";

		strClick +='<span class="en" lang="en">Change Shipping Method</span>';
		strClick +='<span class="fr" lang="fr">Modificer la m&eacute;thode d\'exp&eacute;dition.</span>';

		$("hship").innerHTML = strClick;
		switchlang();
	}
	$('ShippingResult').innerHTML = "";

}

function CancelShippingINFO()
{
	$('Shipping_Method_Pop').style.display = "none";
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
function SetCurrent(obj)
{
    document.getElementById("CurrentCollection").display="none";
    document.getElementById("CurrentCollection").innerHTML = obj.innerHTML;
}


