var check_off = document.createElement('img');
var check_on = document.createElement('img');
check_on.setAttribute('src','/wcsstore/DOL/images/common/check_on.gif');
check_off.setAttribute('src','/wcsstore/DOL/images/common/check_off.gif');

var currentActiveStep=1;

function switch_class(myel, old_class, new_class){
		var el=document.getElementById(myel);
		var a, clasa=""; 
		a = el.className.split(" ");
    for (i = 0;i<a.length;i++){
      if (a[i] != old_class){
        clasa=clasa+" "+a[i];
      }
    }
    clasa=clasa+" "+new_class;
		el.className=clasa;
}
function switch_steps(step_id){
	if(step_id == 1){
		switch_class('billingProfileArea_inactive','','nodisplay');
		switch_class('billingProfileArea','nodisplay','');		

		switch_class('shippingItemsArea_inactive','nodisplay','');
		switch_class('shippingItemsArea','','nodisplay');		
		
		switch_class('shippingAddressArea_inactive','nodisplay','');
		switch_class('shippingAddressArea','','nodisplay');		
	}else if(step_id == 3){
		switch_class('shippingItemsArea_inactive','','nodisplay');
		switch_class('shippingItemsArea','nodisplay','');		

		switch_class('billingProfileArea_inactive','nodisplay','');
		switch_class('billingProfileArea','','nodisplay');		
		
		switch_class('shippingAddressArea_inactive','nodisplay','');
		switch_class('shippingAddressArea','','nodisplay');			
	}else if(step_id == 2){
		switch_class('shippingAddressArea_inactive','','nodisplay');
		switch_class('shippingAddressArea','nodisplay','');		

		switch_class('shippingItemsArea_inactive','nodisplay','');
		switch_class('shippingItemsArea','','nodisplay');		
		
		switch_class('billingProfileArea_inactive','nodisplay','');
		switch_class('billingProfileArea','','nodisplay');		 
	}
	
	
}

function switch_tabs_product(myel,old_class,new_class){
	switch_class(currentTab, new_class, old_class);
	currentTab='tab_'+myel;
	switch_class(currentTab, old_class, new_class);
	switch_div(currentTabContainer, myel);
	currentTabContainer=myel;
	switch_div(myel, currentTabContainer);
}

var d = document;
var gebtn = function(parEl,child) { return parEl.getElementsByTagName(child); };
function load_checkboxes() {
    if(!d.getElementById || !d.createTextNode) return;
    var ls = gebtn(d,'label');
    for (var i = 0; i < ls.length; i++) {
        var l = ls[i];
        if (l.className.indexOf('label_') == -1) continue;
        var inp = gebtn(l,'input')[0];
        if (l.className == 'label_check') {
            l.className = inp.checked ? 'label_check c_on' : 'label_check c_off';
            //ATBDOL workaround to get this to work in IE and FF - strange behaviour in FF when using onclick: function check_it is called twice every time
            if(document.all)
	            l.onclick = check_it;
	        else
	        	l.onchange = check_it;
        };
    };
};
function check_it() {
    var inp = gebtn(this,'input')[0];
    if (this.className == 'label_check c_off') {
        this.className = 'label_check c_on';
        inp.checked = true;
    } else {
        this.className = 'label_check c_off';     
        inp.checked = false;
    };
    

	//if the id of this product begins with input. then this is a input used by FastFinder! Call the apropriate method
	if(inp.id.match('^input.')){
		filterWithProductExplorer();
	}
};

function select_switch(currentEl, one, two){
	if (currentEl.options[currentEl.selectedIndex].value == 1){
		switch_div(two, one);
	}else{
		switch_div(one, two);
	}
}

function switch_div(hide, show ){
    var a;
    if (a = document.getElementById(hide)){
       add_class(a, "nodisplay");
    }
    if (a = document.getElementById(show)){
       remove_class(a, "nodisplay");
    }
    return true;
}

function add_class(el,str){
	if ((typeof el == "object") && str && (el != null)){
		var cls = "";
		var t = el.className.split(" ");
		if (t.length){
			for (var i=0; i<t.length; i++){
				if (t[i] == str){
					delete(t[i]);
				}
			}
		}
		cls = t.join(" ");
		cls+= " "+str;
		el.className = cls;
	}
}

function remove_class(el,str){
	if ((typeof el == "object") && str && (el != null)){
		var cls = "";
		var t = el.className.split(" ");
		if (t.length){
			for (var i=0; i<t.length; i++){
				if (t[i] == str){
					delete(t[i]);
				}
			}
		}
		el.className = t.join(" ");
	}
}


function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "blank")
     anchor.target = "_blank";
 }
}

function isdefined( variable){
    return (typeof(window[variable]) == "undefined")?  false: true;
}

// used to block clicked until the page is completly loaded
var pageLoaded = false;
// blocks the second click on a submit button/link
var clicked = true;

onload = function(){
	externalLinks();
	if (isdefined('tooltipsON'))
		load_tooltips();
	load_checkboxes();
	
	if (isdefined('isItemPageDisplayed')){
		checkCookie(productId);
		//also! update the product tab comment text
		//update the tab top text with the new number of comments
		document.getElementById('numberOfCommentsTextDiv').innerHTML = document.getElementById('numberOfCommentsText').value;			
	}

	//for fastFinder!! Only if this is the subcategory page, refresh the fast finder!
	//if(document.getElementById('ProductExploreForm')!=null){
	//	fastFinderJS.filterResultsWithTabs(document.getElementById('tabAll'));
	//} 
	
	// used to block clicked until the page is completly loaded
	pageLoaded = true;
	// blocks the second click on a submit button/link
	clicked = false;
	//alert ("page inited!");

}
