/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1) { return data[i].identity; }
			} else if (dataProp) { return data[i].identity; }
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) { return; }
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ string: navigator.userAgent, subString: "Chrome",	identity: "Chrome" },
		{ string: navigator.userAgent, subString: "OmniWeb", versionSearch: "OmniWeb/", identity: "OmniWeb" },
		{ string: navigator.vendor,	subString: "Apple",	identity: "Safari" },
		{ prop: window.opera, identity: "Opera"	},
		{ string: navigator.vendor,	subString: "iCab", identity: "iCab"	},
		{ string: navigator.vendor,	subString: "KDE", identity: "Konqueror"	},
		{ string: navigator.userAgent, subString: "Firefox", identity: "Firefox" },
		{ string: navigator.vendor, subString: "Camino", identity: "Camino" },
		{ string: navigator.userAgent, subString: "Netscape", identity: "Netscape" },
		{ string: navigator.userAgent, subString: "MSIE", identity: "Explorer",	versionSearch: "MSIE" },
		{ string: navigator.userAgent, subString: "Gecko", identity: "Mozilla",	versionSearch: "rv"	},
		{ string: navigator.userAgent, subString: "Mozilla", identity: "Netscape", versionSearch: "Mozilla"	}
	],
	dataOS : [
		{ string: navigator.platform, subString: "Win", identity: "Windows"	},
		{ string: navigator.platform, subString: "Mac",	identity: "Mac" },
		{ string: navigator.platform, subString: "Linux", identity: "Linux"	}
	]

};
BrowserDetect.init();

var offsetfrommouse=[15,15]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 270;	// maximum image size.

if (document.getElementById || document.all){
	document.write('<div id="trailimageid">');
	document.write('</div>');
}

function gettrailobj(){
	if (document.getElementById) { return document.getElementById("trailimageid").style; }
	else if (document.all) { return document.all.trailimageid.style; }
}

function gettrailobjnostyle(){
	if (document.getElementById) { return document.getElementById("trailimageid"); }
	else if (document.all) { return document.all.trailimageid; }
}

function truebody(){
	if(BrowserDetect.browser=="Chrome"||BrowserDetect.browser=="Safari") {
		return document.body;
	} else if (document.compatMode && document.compatMode!="BackCompat") {
		return document.documentElement;
	} else {
		return document.body;	
	}
//return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function showtrail(imagename,title,description,qoh,showthumb,width,showqoh,height){

	if (height > 0) { currentimageheight = height; }
	document.onmousemove=followmouse;

	newHTML = '<div style="padding: 5px; background-color: #FFF; border: 1px solid #888;">';
	newHTML = newHTML + '<span class="title"><b>' + title + '</b></span><br/>';
	newHTML = newHTML + '<span class="standard">' + description + '</span><br/>';
	if(showqoh) {
		newHTML = newHTML + '<span class="standard">QOH: ' + qoh + '</span><br/>';
	}

	if (showthumb > 0){
		newHTML = newHTML + '<div align="center" style="padding: 8px 2px 2px 2px;"><img width="'+ width +'" height="'+ height +'" src="' + imagename + '" border="0"></div>';
	}

	newHTML = newHTML + '</div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().visibility="visible";
}

function showorder(ref_array,title,description,qoh,showthumb,height,cur,lang){

	var eachorder = ref_array.split('^');
	if (height > 0) { currentimageheight = height; }
	document.onmousemove=followmouse;
    if(lang=="FR") {
        var lblitem = 'Détails d\'article';
        var lblqty = 'Qté';
        var lblpric = 'Prix';   
    } else {
        var lblitem = 'Item Details';
        var lblqty = 'Qty';
        var lblpric = 'Price';
    }

	newHTML = '<div style="padding: 10px; background-color: #FFF; border: 1px solid #888;">';
	newHTML = newHTML + '<table width="350" cellpadding="0" cellspacing="0">';
	newHTML = newHTML + '<tr><td colspan="3" class="title"><b>' + title.toUpperCase() + '</b></td></tr>';
	newHTML = newHTML + '<tr><td class="spacer" colspan="3"></td></tr>';
	newHTML = newHTML + '<tr><td width="215" class="standard2">' + lblitem + '</td>';
    newHTML = newHTML + '<td width="60" align="right" class="standard2">' + lblqty + '</td>';
    newHTML = newHTML + '<td width="75" align="right" class="standard2">' + lblpric + '</td></tr>';
	newHTML = newHTML + '<tr><td class="spacer" colspan="3"></td></tr>';
	newHTML = newHTML + '<tr><td class="hline" colspan="3"></td></tr>';
	for(x in eachorder){
		if (x!=0){
			var orderdata = eachorder[x].split('~');
			newHTML = newHTML + '<tr>';
			newHTML = newHTML + '<td class="standard"><b>' + orderdata[0] + '</b><br>' + orderdata[1] + '</td>';
			newHTML = newHTML + '<td class="standard" align="right" valign="bottom">' + orderdata[2] + ' ' + orderdata[4] + '</td>';
			newHTML = newHTML + '<td class="standard" align="right" valign="bottom">' + cur +' '+ orderdata[3] + '</td>';
			newHTML = newHTML + '</tr>';
			newHTML = newHTML + '<tr><td height="5" colspan="3"></td></tr>';
			newHTML = newHTML + '<tr><td height="1" bgcolor="#E7E7E7" colspan="3"></td></tr>';
		}	
	}
	newHTML = newHTML + '</table></div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().visibility="visible";
}

function showshipping(ref_array,title,description,showthumb,height){

	var eachorder = ref_array.split('~');
	if (height > 0) { currentimageheight = height; }
	document.onmousemove=followmouse;
	
	newHTML = '<div style="padding: 10px; background-color: #FFF; border: 1px solid #888;">';
	newHTML = newHTML + '<table width="300" cellpadding="0" cellspacing="0">';
	newHTML = newHTML + '<tr><td class="title">' + title.toUpperCase() + '</td></tr>';
	newHTML = newHTML + '<tr><td class="spacer"></td></tr>';
	newHTML = newHTML + '<tr><td class="hline"></td></tr>';
	newHTML = newHTML + '<tr><td class="spacer"></td></tr>';

	for (s=0;s<eachorder.length;s++) {
		if (eachorder[s]) {
			newHTML = newHTML + '<tr><td class="standard">' + eachorder[s] + '</td></tr>';
		}
	}

	newHTML = newHTML + '</table></div>';

	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().visibility="visible";
}

function showinwards(imagename,title,description,qoh,editor,date,height){

	if (height > 0) { currentimageheight = height; }
	document.onmousemove=followmouse;

	newHTML = '<div style="padding: 5px; background-color: #FFF; border: 1px solid #888;">';
	newHTML = newHTML + '<span class="title"><b>' + title + '</b></span><br/><br/>';
	newHTML = newHTML + '<span class="standard">' + qoh + '</span><br/>';
	newHTML = newHTML + '<span class="standard">Last edited by ' + editor + ' at ' + date + '</span><br/><br/>';
	newHTML = newHTML + '<span class="standard">' + description + '</span><br/>';

	newHTML = newHTML + '</div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().visibility="visible";
}

function showhint(){

	currentimageheight = 100;
	document.onmousemove=followmouse;

	newHTML = '<div style="padding: 10px; background-color: #FFF; border: 1px solid #888;">';
	newHTML = newHTML + '<table width="300" cellpadding="0" cellspacing="0">';
	newHTML = newHTML + '<tr><td class="title"><strong>PRINTING SETUP</strong></td></tr>';
	newHTML = newHTML + '<tr><td class="hline"></td></tr>';
	newHTML = newHTML + '<tr><td height="10"></td></tr>';
	newHTML = newHTML + '<tr><td class="standard">To print this graph you have to enable your browser to print the background colours & images.</td></tr>';
	newHTML = newHTML + '<tr><td height="10"></td></tr>';
	newHTML = newHTML + '<tr><td class="standard2">FOR INTERNET EXPLORER USER :</td></tr>';
	newHTML = newHTML + '<tr><td class="standard">1. Go to Tools > Internet Options<br>2. Go to the Advanced Tab, and check "Print background colors and images" under Printing category.</td></tr>';
	newHTML = newHTML + '</table></div>';

	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().visibility="visible";
}

function showuser(){

	currentimageheight = 100;
	document.onmousemove=followmouse;

	newHTML = '<div style="padding: 10px; background-color: #FFF; border: 1px solid #888;">';
	newHTML = newHTML + '<table width="300" cellpadding="0" cellspacing="0">';
	newHTML = newHTML + '<tr><td class="title"><strong>USER PRIVILEGE EXPLANATION</strong></td></tr>';
	newHTML = newHTML + '<tr><td class="hline"></td></tr>';
	newHTML = newHTML + '<tr><td height="10"></td></tr>';
	newHTML = newHTML + '<tr><td class="standard2">SITE MANAGER</td></tr>';
	newHTML = newHTML + '<tr><td class="standard">Site Manager have access to administrator section, and make changes for the site.</td></tr>';
	newHTML = newHTML + '<tr><td height="10"></td></tr>';
	newHTML = newHTML + '<tr><td class="standard2">TEAM LEADER</td></tr>';
	newHTML = newHTML + '<tr><td class="standard">Team leader is a person who commands a specific group. They can add unlimited shipping addresses from the customer database.</td></tr>';
	newHTML = newHTML + '<tr><td height="10"></td></tr>';
	newHTML = newHTML + '<tr><td class="standard2">TEAM MEMBER</td></tr>';
	newHTML = newHTML + '<tr><td class="standard">Team member is a person who works together in a group, lead by a Team leader. They can add unlimited shipping addresses from the customer database.</td></tr>';
	newHTML = newHTML + '<tr><td height="10"></td></tr>';
	newHTML = newHTML + '<tr><td class="standard2">SINGLE USER</td></tr>';
	newHTML = newHTML + '<tr><td class="standard">Single User is a user that can create their own one shipping address.</td></tr>';
	newHTML = newHTML + '<tr><td height="10"></td></tr>';
	newHTML = newHTML + '<tr><td class="standard2">SINGLE CUSTOMER</td></tr>';
	newHTML = newHTML + '<tr><td class="standard">Single Customer only have one shipping address assigned by the Administrator.</td></tr>';
	newHTML = newHTML + '<tr><td height="10"></td></tr>';
	newHTML = newHTML + '<tr><td class="standard2">GUEST</td></tr>';
	newHTML = newHTML + '<tr><td class="standard">Guest can only see the items, but cannot order anything.</td></tr>';
	newHTML = newHTML + '</table></div>';

	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().visibility="visible";
}

function showbasket(){

	currentimageheight = 50;

	document.onmousemove=followmouse;

	newHTML = '<div style="padding: 10px; background-color: #FFF; border: 1px solid #888;">';
	newHTML = newHTML + '<table width="300" cellpadding="0" cellspacing="0">';
	newHTML = newHTML + '<tr><td class="title"><strong>ATTENTION !</strong></td></tr>';
	newHTML = newHTML + '<tr><td class="hline"></td></tr>';
	newHTML = newHTML + '<tr><td height="10"></td></tr>';
	newHTML = newHTML + '<tr><td class="standard">You still have some items left unordered in your basket from the last time you login.</td></tr>';
	newHTML = newHTML + '</table></div>';

	gettrailobjnostyle().innerHTML = newHTML;

	gettrailobj().visibility="visible";
}

function showinfo(message){

	currentimageheight = 50;

	document.onmousemove=followmouse;

	newHTML = '<div style="padding: 10px; background-color: #FFF; border: 1px solid #888;">';
	newHTML = newHTML + '<table width="300" cellpadding="0" cellspacing="0">';
	newHTML = newHTML + '<tr><td class="title"><strong>Information</strong></td></tr>';
	newHTML = newHTML + '<tr><td class="hline"></td></tr>';
	newHTML = newHTML + '<tr><td height="10"></td></tr>';
	newHTML = newHTML + '<tr><td class="standard">'+message+'</td></tr>';
	newHTML = newHTML + '</table></div>';

	gettrailobjnostyle().innerHTML = newHTML;

	gettrailobj().visibility="visible";
}

function hidetrail(){
	gettrailobj().visibility="hidden";
	document.onmousemove="";
	gettrailobj().left="-500px";

}

function followmouse(e){

	var xcoord=offsetfrommouse[0];
	var ycoord=offsetfrommouse[1];

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15;
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(document.body.offsetHeight, window.innerHeight);

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 400){
			xcoord = e.pageX - xcoord - 286; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight + 270)){
			ycoord += e.pageY - Math.max(0,(270 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < 300){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 286; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX;
		}
		if (docheight - event.clientY < (currentimageheight + 270)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(270 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15;
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight);

	gettrailobj().left=xcoord+"px";
	gettrailobj().top=ycoord+"px";
}

function unNullify(sel)
{
    var checkedbox = document.elements.getElementById("");

    return true;
} // end of the 'unNullify()' function

function changeImage(idsel,imwidth,imheight,imagetoshow)
{
	var thumbid = 'thumb_'+idsel;
	var thebox = document.getElementById(thumbid);
	var theplace = document.getElementById('placeholder');
	var thelink = document.getElementById('linkholder');
	var previd = theplace.src;
	var linkhref = thelink.href;

	var nochange = document.getElementsByTagName('div');
	for(n=0;n<nochange.length;n++) {
		var splname = nochange[n].id.split("_");
		if (splname[0]=='thumb') {
			nochange[n].style.borderColor = '#E7E7E7';
		}
	}
	
	thebox.style.borderColor = '#000000';
	if(imwidth) { theplace.width = imwidth; }
	if(imheight) { theplace.height = imheight; }
	theplace.src = imagetoshow;
	linkelem = thelink.href.split("&");
	var newlink = '';
	for(l=0;l<(linkelem.length-1);l++) {
		if(l) { newlink = newlink + '&' + linkelem[l]; }
		else { newlink = linkelem[l]; }
	}
	thelink.href = newlink+'&wim='+idsel;
}

/***********************************************
* Gradual Highlight image script- Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var baseopacity=50;

function slowhigh(which2){
	imgobj=which2;
	browserdetect=which2.filters? "ie" : typeof which2.style.MozOpacity=="string"? "mozilla" : "";
	instantset(baseopacity);
	highlighting=setInterval("gradualfade(imgobj)",50);
}

function slowlow(which2){
	cleartimer();
	setTimeout(function() {gradualfadeout(which2);}, 50);
}

function instantset(degree){
	if (browserdetect=="mozilla") {
		imgobj.style.MozOpacity=degree/100
	} else if (browserdetect=="ie") {
		imgobj.filters.alpha.opacity=degree
	} else {
		imgobj.style.opacity = degree/100;
	}
}

function cleartimer(){
	if (window.highlighting) clearInterval(highlighting)
}

function gradualfade(cur2){
	if (browserdetect=="mozilla" && cur2.style.MozOpacity<1)
		cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.1, 0.99)
	else if (browserdetect=="ie" && cur2.filters.alpha.opacity<100)
		cur2.filters.alpha.opacity+=10
	else if (browserdetect!="mozilla") {
		if (browserdetect!="ie") {
			cur2.style.opacity=Math.min(parseFloat(cur2.style.opacity)+0.1, 0.99)
		}
	}
	else if (window.highlighting)
		clearInterval(highlighting)
}

function gradualfadeout(cur3){
	cr3=setTimeout(function() {gradualfadeout(cur3);}, 50)
	if (browserdetect=="mozilla" && cur3.style.MozOpacity>0.3)
		cur3.style.MozOpacity=Math.min(parseFloat(cur3.style.MozOpacity)-0.1)
	else if (browserdetect=="ie" && cur3.filters.alpha.opacity>30)
		cur3.filters.alpha.opacity=cur3.filters.alpha.opacity-10
	else if (cur3.style.opacity>0.3)
		cur3.style.opacity=Math.min(parseFloat(cur3.style.opacity)-0.1)

	if (browserdetect=="mozilla" && cur3.style.MozOpacity<=0.5)
		clearTimeout(cr3);
	else if (browserdetect=="ie" && cur3.filters.alpha.opacity<=50)
		clearTimeout(cr3);
	else if (cur3.style.opacity<=0.5)
		clearTimeout(cr3);
}

function getElementsByName_iefix(tag, name) {
	var elem = document.getElementsByTagName(tag);
	var arr = new Array();
	for(i = 0,iarr = 0; i < elem.length; i++) {
		att = elem[i].getAttribute("name");
		if(att == name) {
			arr[iarr] = elem[i];
			iarr++;
		}
	}
	return arr;
}

function showAcc(curbutton,this_detail) {
	if (BrowserDetect.browser=="Explorer") {
		$('.but_acc_sel2').attr('class','but_acc2');
        $('.content_text').hide();

		if (this_detail == '3') {
			document.getElementById('content_acc').style.display = 'block';
		} else if (this_detail == '4') {
			document.getElementById('content_feat').style.display = 'block';
		} else if (this_detail == '5') {
			document.getElementById('content_spec').style.display = 'block';
		} else if (this_detail == '6') {
			document.getElementById('content_inc').style.display = 'block';
		}

		curbutton.className = 'but_acc_sel2';
	} else {
        $('.but_acc_sel2').attr('class','but_acc2');
        $('.content_text').hide();
	    
		if (this_detail == '3') {
			document.getElementById('content_acc').style.display = 'block';
		} else if (this_detail == '4') {
			document.getElementById('content_feat').style.display = 'block';
		} else if (this_detail == '5') {
			document.getElementById('content_spec').style.display = 'block';
		} else if (this_detail == '6') {
			document.getElementById('content_inc').style.display = 'block';
		}
		curbutton.className = 'but_acc_sel2';
	}
}

function flipcolor(controlElement, show)
{
	if (show) {
		controlElement.className = 'color';	
	} else {
		controlElement.className = 'standard';	
	}
}

function showEditBox(controlElement, show)
{
	if (show) {
		
		controlElement.style.display = 'none';
		document.getElementById('divcat').style.display = 'block';
	} else {
		//document.write(document.getElementById('divbutton').style.display);
		
		document.getElementById('divcat').style.display = 'none';
		document.getElementById('divbutton').style.display = 'block';
		document.getElementById('divim').style.display = 'block';
	}
}

function showEditName(controlElement, show)
{
	if (show) {
		document.getElementById('name_input').style.display = 'block';
		document.getElementById('rename_apply').style.display = 'block';
		document.getElementById('name_string').style.display = 'none';
		document.getElementById('rename_this').style.display = 'none';
	} else {
		document.getElementById('name_input').style.display = 'none';
		document.getElementById('rename_apply').style.display = 'none';
		document.getElementById('name_string').style.display = 'block';
		document.getElementById('rename_this').style.display = 'block';
	}
}

function applyCategoryChange(controlElement)
{
	var nameArray = controlElement.id.split("_");
	var input_num = 'sp_' + nameArray[1];
	var hidden_num = 'hi_' + nameArray[1];
	var div_num = 'div_' + nameArray[1];
	
	var spanText = document.getElementById(input_num);
	var isUpdated = document.getElementById(hidden_num);
	var divBox = document.getElementById(div_num);

	isUpdated.value = '1';
	document.category_rename.submit();

	divBox.style.display = 'none';
	spanText.style.display = 'block';
}

function changeAccess(controller)
{
	var newAccess = controller.value;
	var selectBox = new Array();

	//document.getElementById('assign_customer').style.display = 'none';
	document.getElementById('assign_team').style.display = 'none';
	document.getElementById('assign_leader').style.display = 'none';
	document.getElementById('salesperson_box').style.display = 'none';

	var menuCount = 22;
	if (newAccess == 2) {
		selectBox[1] = "1";
		selectBox[2] = "2";
		selectBox[3] = "3";
		selectBox[4] = "4";
		selectBox[5] = "5";
		selectBox[6] = "6";
		selectBox[7] = "7";
		selectBox[8] = "8";
		selectBox[9] = "9";
		selectBox[10] = "10";
		selectBox[11] = "11";
		selectBox[12] = "12";
		selectBox[13] = "13";
		selectBox[14] = "14";
		selectBox[15] = "15";
		selectBox[16] = "16";
		selectBox[17] = "17";
		selectBox[19] = "19";
		selectBox[20] = "20";
		selectBox[21] = "21";
	} else if (newAccess == 3) {
		selectBox[6] = "4";
		selectBox[8] = "5";
		selectBox[9] = "6";
		selectBox[15] = "7";
		selectBox[16] = "8";
		$('#assign_team').show();
		$('#teamdiv').show();
		$('#assign_leader').hide();
	} else if (newAccess == 5) {
		document.getElementById('salesperson_box').style.display = 'block';
	}
	if (newAccess != 2 && newAccess != 3) {
		document.getElementById('assign_leader').style.display = 'block';	
	}

	for (a=0;a<menuCount;a++) {
		var objName = 'a_' + a;
		var checkObj = document.getElementById(objName);
		if (selectBox[a] != null) {
			if (checkObj != null) { checkObj.checked = true; }
		} else {
			if (checkObj != null) { checkObj.checked = false; }
		}
	}
}

function changeSuper(controller,clientval,clientstring)
{
	var haveLeader = controller.value;
	var leaderString = controller.options[controller.selectedIndex].text;
	if (haveLeader) {
		var superSelect = document.getElementById('input_supervisor');
		superSelect.options.length=0;
		superSelect.options[0] = new Option(clientstring,clientval,true,false);
		superSelect.options[1] = new Option(leaderString,haveLeader,false,false);
	}
}

function checkChild(controller, checkstring)
{
	var splitId = controller.id.split('_');
	var whichCheck = splitId[0];
	
	if (whichCheck == 'L') {
		var unCheck1 = 'R';
		var unCheck2 = 'C';
	} else if (whichCheck == 'C') {
		var unCheck1 = 'L';
		var unCheck2 = 'R';
	} else if (whichCheck == 'R') {
		var unCheck1 = 'L';
		var unCheck2 = 'C';	
	}
	conUncheck1 = unCheck1 + '_' + splitId[1];
	conUncheck2 = unCheck2 + '_' + splitId[1];
	
	if(document.getElementById(conUncheck1)) {
		document.getElementById(conUncheck1).checked = false;
	}
	if(document.getElementById(conUncheck2)) {
		document.getElementById(conUncheck2).checked = false;
	}
	
	var idToCheck = checkstring.split('::');
	var untilTo = idToCheck.length;
	for (i=0;i<untilTo;i++) {
		if (idToCheck[i]) {
            var tocheck = '#L_'+idToCheck[i];
            if(controller.checked) {
                $(tocheck).attr('checked','checked');   
            } else {
                $(tocheck).attr('checked','');
            }
            /*
			var nameUncheck1 = unCheck1 + '_' + idToCheck[i];
			var nameUncheck2 = unCheck2 + '_' + idToCheck[i];
			if(document.getElementById(nameUncheck1)) {
				document.getElementById(nameUncheck1).checked = false;
			}
			if(document.getElementById(nameUncheck2)) {
				document.getElementById(nameUncheck2).checked = false;
			}
			
			var nameToCheck = whichCheck + '_' + idToCheck[i];
			if(document.getElementById(nameToCheck)) {
				var elemToCheck = document.getElementById(nameToCheck);
			}
			elemToCheck.checked = controller.checked;
            */
		}
	}
}

function checkChildpub(controller, checkstring)
{
	var splitId = controller.id.split('_');
	var whichCheck = splitId[0];
	
	var idToCheck = checkstring.split('::');
	var untilTo = idToCheck.length-1;
	for (i=0;i<untilTo;i++) {
		if (idToCheck[i]) {
			var nameToCheck = whichCheck + '_' + idToCheck[i];
			if(document.getElementById(nameToCheck)) {
				var elemToCheck = document.getElementById(nameToCheck);
			}
			elemToCheck.checked = controller.checked;
		}
	}
}

function followSuit(controller, follower,opp)
{
	var elToChange = document.getElementById(follower);
	var checkStatus = controller.checked;

	if (opp) {
		if (checkStatus) {
			elToChange.disabled = true;
			elToChange.style.background = '#E7E7E7';
			elToChange.style.color = '#AAAAAA';
		} else {
			elToChange.disabled = false;
			elToChange.style.background = '#FFFFFF';
			elToChange.style.color = '#666666';
		}
	} else {
		if (checkStatus) {
			elToChange.disabled = false;
			elToChange.style.background = '#FFFFFF';
			elToChange.style.color = '#666666';
		} else {
			elToChange.disabled = true;
			elToChange.style.background = '#E7E7E7';
			elToChange.style.color = '#AAAAAA';
		}
	}
}

function showBilling(controller)
{
	var conStatus = controller.checked;
	var billDiv = document.getElementById('billing_info');
	if (conStatus) {
		billDiv.style.display = 'block';
	} else {
		billDiv.style.display = 'none';	
	}
}

function changePrice(controller, pcode, bcount, price_ok, qoh_ok, convertor_array, backorder)
{
	var chopchop = convertor_array.split('::');
	var choplength = chopchop.length-1;
	var conversion = new Array();
	for (c=0;c<choplength;c++) {
		var chopagain = chopchop[c].split('^');
		conversion[chopagain[0]] = chopagain[1];
	}
	var elid = controller.id.split("_");
	
	var selPrice = controller.options[controller.selectedIndex].value;
	
	if (selPrice) {
		for(i=0;i<bcount;i++) {
			if (qoh_ok == 1) {
				div2toHide = '2' + pcode + '_' + i;
				div2Hide = document.getElementById(div2toHide);
				if (div2Hide) {	div2Hide.style.display = 'none'; }
			}
			div3toHide = '3' + pcode + '_' + i;
			div3Hide = document.getElementById(div3toHide);
			if (div3Hide) { div3Hide.style.display = 'none'; }
		}
		
		if (qoh_ok == 1) {
			var div2Name = '2' + pcode + '_' + selPrice;
			the2Div = document.getElementById(div2Name);
			if (the2Div) { the2Div.style.display = 'block'; }
		}
		var div3Name = '3' + pcode + '_' + selPrice;
		the3Div = document.getElementById(div3Name);
		if (the3Div) { the3Div.style.display = 'block'; }

		var txtName = pcode + '_unit';
		var conName = pcode + '_con';
		theTxt = document.getElementById(txtName);
		if (theTxt) { theTxt.value = selPrice; }
		theCon = document.getElementById(conName);
		if (theCon) { theCon.value = conversion[selPrice]; }
		
		var unithn = 'unt_' + elid[1] + '_' + elid[2];
		if(document.getElementById(unithn)) {
			document.getElementById(unithn).value = conversion[selPrice];
		}
	}
	
	var qtybox = 'qty_' + elid[1]+'_'+elid[2];
	var boxname = '#pricebox_'+elid[1]+'_'+elid[2];
	var iqty = document.getElementById(qtybox).value;
	
	//var selqty = '2'+pcode+'_'+selPrice;
	//var curqty = document.getElementById(selqty).innerHTML;
	var onav = 'on_' + elid[1] + '_' + elid[2];
	var unav = 'not_' + elid[1] + '_' + elid[2];
	
	if(iqty<1&&backorder<1) {
		if(document.getElementById(onav)) { document.getElementById(onav).style.display = 'none'; }
		if(document.getElementById(unav)) { document.getElementById(unav).style.display = 'block'; }
	} else {
		if(document.getElementById(onav)) { document.getElementById(onav).style.display = 'block'; }
		if(document.getElementById(unav)) { document.getElementById(unav).style.display = 'none'; }
	}
	
	var queryString = "?pid=" + elid[1] + "&qty=1&unm=" + selPrice;
	//ajaxGo(1,'sc.price.php'+queryString,boxname);
    $.get('sc.price.php'+queryString,function(data) {
       $(boxname).html(data);
    });
}

var sMax;       // Isthe maximum number of stars
var holder; // Is the holding pattern for clicked state
var preSet; // Is the PreSet value onces a selection has been made
var rated;

// Rollover for image Stars //
function rating(num) {
	sMax = 5;       // Isthe maximum number of stars

    if(!rated) {
		s = num.id.replace("_", ''); // Get the selected star
		a = 0;
		for(i=1; i<=sMax; i++) {
			if(i<=s){
				document.getElementById("_"+i).className = "on";
				//document.getElementById("rateStatus").innerHTML = num.title;
				holder = a+1;
				a++;
			} else {
				document.getElementById("_"+i).className = "";
			}
		}
	}
}

// For when you roll out of the the whole thing //
function off(me) {
	if(!rated) {
		if(!preSet) {
			for(i=1; i<=sMax; i++) {
				document.getElementById("_"+i).className = "";
				//document.getElementById("rateStatus").innerHTML = me.parentNode.title;
			}
		} else {
			rating(preSet);
			//document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML;
		}
	}
}

// When you actually rate something //
function rateIt(me) {
	if(!rated) {
		sel = me.id.replace("_", '');
		document.getElementById("star_rating").value = sel;
		preSet = me;
		rated=1;
		sendRate(me);
		rating(me);
	}
}

function showmore(me) {
	document.getElementById('min_review').style.display = 'none';
	document.getElementById('max_review').style.display = 'block';	
}

function hidemore(me) {
	document.getElementById('max_review').style.display = 'none';
	document.getElementById('min_review').style.display = 'block';	
}

function show_comment(me) {
	document.getElementById('review_section').style.display = 'block';
}

function ajaxFunction(){
	var ajaxRequest;  // The variable that makes Ajax possible!

	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('ajaxDiv');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	var zip = document.getElementById('zipcode').value;
	var country = document.getElementById('country_select').value;
	var order_total = document.getElementById('order_total').value;
	var ISAPI_100_50 = document.getElementById('ISAPI_100_50').value;
	var client = document.getElementById('client').value;
	//var weight = document.getElementById('weight').value;
	var queryString = "?zip=" + zip + "&country=" + country + "&order_total=" + order_total + "&ISAPI_100_50=" + ISAPI_100_50 + "&client=" + client;
	//+ "&weight=" + weight;
	ajaxRequest.open("GET", "secure/ajax_shipping_query.php" + queryString, true);
	ajaxRequest.send(null); 
}

function ajaxGo(loadWhat,pageToLoad,onDiv){
	var ajaxRequest;  // The variable that makes Ajax possible!

	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
            if(document.getElementById(onDiv)) {
			    var ajaxDisplay = document.getElementById(onDiv);
			    ajaxDisplay.innerHTML = ajaxRequest.responseText;
            }
		}
	}
	
	if (loadWhat == 1) {
		ajaxRequest.open("GET", pageToLoad, true);
	}
	ajaxRequest.send(null); 
}

function addBasket(cont, isapi, ulimit, kitno, refreshpage, stockitem, lang)
{
    var e = 0;
	var elid = cont.id.split("_");
	var remdiv = 'off_' + elid[1]+'_'+elid[2];
	var adddiv = 'on_' + elid[1]+'_'+elid[2];
	var qtybox = 'qty_' + elid[1]+'_'+elid[2];
	var qtyspan = 'qt_' + elid[1]+'_'+elid[2];
	var unitsel = 'sel_' + elid[1]+'_'+elid[2];
	var qohbox = 'qoh_' + elid[1]+'_'+elid[2];
	var limitxt = 'ltxt_' + elid[1]+'_'+elid[2];
	var maxbox = 'max_' + elid[1]+'_'+elid[2];
	var conve = 'unt_' + elid[1]+'_'+elid[2];
	var iqty = document.getElementById(qtybox).value;
	var unitidx = document.getElementById(unitsel).value;
	var itemqty = document.getElementById(qohbox).value;
	var maxlim = document.getElementById(maxbox).value;
	if(document.getElementById(conve)) {
		var convqty = document.getElementById(conve).value;
	}
    
    if(!convqty) { convqty = 1; }
	itemqty = itemqty/parseInt(convqty);
    
	if (iqty>0) {
		var backorder = document.getElementById('gbo').value;
		var globalmax = document.getElementById('gmax').value;
		var ajaxRequest;
		
		try { ajaxRequest = new XMLHttpRequest(); }
		catch (e) {
			try { ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
			catch (e) {
				try { ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");	}
				catch (e) {
					alert("Your browser broke!");
					return false;
				}
			}
		}
		
		ajaxRequest.onreadystatechange = function() {
			if(ajaxRequest.readyState == 4) {
				var ajaxDisplay = document.getElementById('basketdiv');
				ajaxDisplay.innerHTML = ajaxRequest.responseText;
			}
		}
		
		var queryString = "?ISAPI_100_50=" + isapi + "&pid=" + elid[1] + "&qty=" + iqty + "&unm=" + unitidx + "&kit_no=" + kitno;
		var Iitemqty = parseInt(itemqty);
		var Iiqty = parseInt(iqty);
		var Imaxlim = parseInt(maxlim);
		var Iulimit = parseInt(ulimit);
		var Iglobalmax = parseInt(globalmax);
        if(lang=="FR") {
            var lblqty = 'QTÉ EXCÉDAIT';
            var lblmax = 'QTÉ MAX EXCÉDAIT';
        } else {
            var lblqty = 'QTY EXCEEDED';
            var lblmax = 'MAX QTY EXCEEDED';
        }
        
        var refpage = 0;
		if (Iitemqty<Iiqty && backorder<1 && stockitem) {
            document.getElementById(limitxt).style.display = 'block';
			document.getElementById(limitxt).innerHTML = lblqty;
			//document.getElementById(qtybox).value = Iitemqty;
		} else if (Imaxlim>0 && Imaxlim<Iiqty && ulimit<2) {
            document.getElementById(limitxt).style.display = 'block';
			document.getElementById(limitxt).innerHTML = lblmax;
			//document.getElementById(qtybox).value = Imaxlim;
		} else if (Imaxlim<1 && Iglobalmax>0 && Iglobalmax<Iiqty && ulimit<2) {
            document.getElementById(limitxt).style.display = 'block';
			document.getElementById(limitxt).innerHTML = lblmax;
			//document.getElementById(qtybox).value = Iglobalmax;
		} else {
            
            
			ajaxRequest.open("GET", "snap_basket.php" + queryString, true);
			ajaxRequest.send(null);
            refpage = 1;
			
			document.getElementById(limitxt).innerHTML = '';
			document.getElementById(qtyspan).innerHTML = iqty;
			document.getElementById(adddiv).style.display = 'none';
			document.getElementById(remdiv).style.display = 'block';
			document.getElementById(unitsel).disabled = true;
			document.getElementById(unitsel).style.backgroundColor = '#F2F2F2';
		}
		
		if(refreshpage && refpage) {
			window.location.reload();	
		} else {
            var boxname = 'pricebox_'+elid[1]+'_'+elid[2];
            ajaxGo(1,'sc.price.php'+queryString,boxname);    
        }
        
	} else {
		document.getElementById(qtybox).value = 1;	
	}
}

function remBasket(cont, isapi, unitc, pub, kitno, refreshpage)
{
	var elid = cont.id.split("_");
	var remdiv = 'off_' + elid[1]+'_'+elid[2];
	var adddiv = 'on_' + elid[1]+'_'+elid[2];
	var unitsel = 'sel_' + elid[1]+'_'+elid[2];
	var ajaxRequest;
	
	try { ajaxRequest = new XMLHttpRequest(); }
	catch (e) {
		try { ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) {
			try { ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");	}
			catch (e) {
				alert("Your browser broke!");
				return false;
			}
		}
	}

	ajaxRequest.onreadystatechange = function() {
		if(ajaxRequest.readyState == 4) {
			var ajaxDisplay = document.getElementById('basketdiv');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}

	var queryString = "?ISAPI_100_50=" + isapi + "&did=" + elid[1] + "&kit_no=" + kitno;
	if (pub) {
		ajaxRequest.open("GET", "secure/snap_basket.php" + queryString, true);
	} else {
		ajaxRequest.open("GET", "snap_basket.php" + queryString, true);
	}
	ajaxRequest.send(null); 

	var multdiv = 'mult_'+elid[1];
	if (document.getElementById(multdiv)) {
		document.getElementById(multdiv).style.display = 'none';	
	}

	document.getElementById(remdiv).style.display = 'none';
	document.getElementById(adddiv).style.display = 'block';
	if (unitc>1) {
		document.getElementById(unitsel).disabled = false;
		document.getElementById(unitsel).style.backgroundColor = '#FFFFFF';
	}
	
	var boxname = 'pricebox_'+elid[1]+'_'+elid[2];
	if(document.getElementById(unitsel)) {
		var unitlast = document.getElementById(unitsel).value;
	}
	
	var restorestring = "?pid=" + elid[1] + "&unm=" + unitlast + "&qty=1";
	ajaxGo(1,'sc.price.php'+restorestring,boxname);
	
	if(refreshpage) {
		window.location.reload();	
	}
}

function refreshBasket(cont, isapi, pcode, iskit, pub, codegroup)
{
	var elid = cont.id.split("_");
	var basdiv = 'tbas_' + elid[1]+'_'+elid[2];
	var ajaxRequest;

	try { ajaxRequest = new XMLHttpRequest(); }
	catch (e) {
		try { ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) {
			try { ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");	}
			catch (e) {
				alert("Your browser broke!");
				return false;
			}
		}
	}

	ajaxRequest.onreadystatechange = function() {
		if(ajaxRequest.readyState == 4) {
			var ajaxDisplay = document.getElementById(basdiv);
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	
	var queryString = "?ISAPI_100_50=" + isapi + '&Product=' + pcode;
	if (pub) {
		ajaxRequest.open("GET", siteurl+"secure/pub.snapshot_multiple.php" + queryString, true);
	} else {
		ajaxRequest.open("GET", "sc.snapshot_multiple.php" + queryString, true);
	}
	ajaxRequest.send(null);
}

function showdestination(controller,isclose) {
	var divid = controller.id.split('_');
	var gettohide = document.getElementsByTagName('div');

	for(d=0;d<gettohide.length;d++) {
		var splitname = gettohide[d].id.split('_');
		if (splitname[0] == 'ship') {
			gettohide[d].style.display = 'none';
			var revertbut = 'hide_' + splitname[1];
			var revertbut2 = 'cust_' + splitname[1];
			document.getElementById(revertbut).style.display = 'none';
			document.getElementById(revertbut2).style.display = 'block';
		}
	}

	if (!isclose) {
		var nametoshow = 'ship_' + divid[1];
		var buttohide = 'cust_' + divid[1];
		var buttoshow = 'hide_' + divid[1];
		document.getElementById(nametoshow).style.display = 'block';
		document.getElementById(buttohide).style.display = 'none';
		document.getElementById(buttoshow).style.display = 'block';
	}
}

function popNotice(client,userid) {
	var urltoopen = 'sc.snapshot_notice.php?client='+client+'&user_no='+userid;
	$.openPopupLayer({
		name: "NoticePop",
		width: 500,
		url: urltoopen
	});
}

function switchandapply(controller,productcode,userid,client,thetype) {
    if(thetype==1) {
	    var reqelement = 'not_'+productcode;
	    var ooselement = 'oos_'+productcode;
    } else if(thetype==2||thetype==3) {
        var reqelement = 'fnot_'+productcode;
        var ooselement = 'foos_'+productcode;
    }
	var ajaxRequest;
	
	if(thetype==1) {
		ajaxdiv = 'stock_notify';	
	} else if(thetype==2||thetype==3) {
		ajaxdiv = 'clearance_box';	
	}
	
	try { ajaxRequest = new XMLHttpRequest(); }
	catch (e) {
		try { ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) {
			try { ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");	}
			catch (e) {
				alert("Your browser broke!");
				return false;
			}
		}
	}

	ajaxRequest.onreadystatechange = function() {
		if(ajaxRequest.readyState == 4) {
			var ajaxDisplay = document.getElementById(ajaxdiv);
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	
	if (thetype==1) {
		var queryString = '?&Product='+productcode+'&user_no='+userid+'&client='+client;
		ajaxRequest.open("GET", "sc.snapshot_notify.php" + queryString, true);
	} else if (thetype==2) {
		var queryString = '?&Product='+productcode+'&client='+client+'&action=add';
		ajaxRequest.open("GET", "ad.edit_onsale.php" + queryString, true);
	} else if (thetype==3) {
		var queryString = '?&Product='+productcode+'&client='+client+'&action=del';
		ajaxRequest.open("GET", "ad.edit_onsale.php" + queryString, true);
	}
	
	ajaxRequest.send(null);
	
	if(thetype==1) {
		controller.style.display = 'none';
		document.getElementById(reqelement).style.display = 'block';
	} else if (thetype==2) {
		controller.style.display = 'none';
		document.getElementById(reqelement).style.display = 'block';
	} else if (thetype==3) {
		controller.style.display = 'none';
		document.getElementById(ooselement).style.display = 'block';	
	}
}

function ifactiveshow(controller,toshow,tohide) {
	if(controller.checked) {
		document.getElementById(toshow).style.display = 'block';
		document.getElementById(tohide).style.display = 'none';
	}
}

function submit_shipping(isquote,ttype,prefcar,overcost) {
	if(ttype==1) {
		document.getElementById('confirm').value = '';
		document.getElementById('remove_dist').value = 'yes';
	} else if(ttype==2) {
		document.getElementById('remove_dist').value = '';
		document.getElementById('confirm').value = 'yes';
	} else if(ttype==3) {
		document.getElementById('carrier_confirmed').value = '';
		document.getElementById('sendnow').value = 'yes';
	} else if(ttype==4) {
		document.getElementById('sendnow').value = '';
		document.getElementById('carrier_confirmed').value = 'yes';
	}
	
	if (ttype<3) {
		document.getElementById('isquote').value = isquote;
		document.getElementById('preferred_carrier').value = prefcar;
		document.getElementById('override_cost').value = overcost;
		document.destination_form.submit();
	} else {
		document.getElementById('isquote').value = isquote;
		document.getElementById('preferred_carrier').value = prefcar;
		document.continue_form.submit();
	}
}

function refreshone(prodcode,havetext,firstelem,secondelem) {
	var theprodcode = window.frames[0].document.getElementById(prodcode).value;
	var prodnotetext = window.frames[0].document.getElementById(havetext).value;
	if(document.getElementById(firstelem+theprodcode)) {
		var firste = document.getElementById(firstelem+theprodcode);
	}
	if(document.getElementById(secondelem+theprodcode)) {
		var seconde = document.getElementById(secondelem+theprodcode);
	}
	
	if (prodnotetext) {
		firste.style.display = 'block';
		seconde.style.display = 'none';
	} else {
		firste.style.display = 'none';
		seconde.style.display = 'block';
	}
	
	ajaxGo(1,'ad.snippet.php?snippet=note&Product='+theprodcode,'note_'+theprodcode);
}

function notifystock(controller,productcode,ispub) {
	var reqelement = 'not_'+productcode;
	var ooselement = 'oos_'+productcode;
    if(!ispub) { ispub = ''; }
	
    var theaddquery = siteurl+'secure/sc.snapshot_notify.php?Product='+productcode+'&ispublic='+ispub;
	$.get(theaddquery, function(data) {
		var datasplit = data.split('::');
		
		if(datasplit[0]) {
			controller.style.display = 'none';
			if(document.getElementById(reqelement)) {
				document.getElementById(reqelement).style.display = 'block';
			}
		}
	});
}

function addtoFave(controller,productcode,kitnum,ispub,addtype) {
    var afavel = 'isfave_'+productcode+'_'+kitnum;
    var nfavel = 'nofave_'+productcode+'_'+kitnum;
    
    if(addtype) {
        var theaddquery = siteurl+'secure/sc.snapshot_fave.php?Product='+productcode+'&kit_no='+kitnum+'&ispublic='+ispub+'&delete=yes';
        var chelm = afavel;
    } else {
        var theaddquery = siteurl+'secure/sc.snapshot_fave.php?Product='+productcode+'&kit_no='+kitnum+'&ispublic='+ispub;
        var chelm = nfavel;
    }
    
    $.get(theaddquery, function(data) {
        var datasplit = data.split('::');
        
        if(datasplit[0]) {
            controller.style.display = 'none';
            if(document.getElementById(chelm)) {
                document.getElementById(chelm).style.display = 'block';
            }
            if(datasplit[0]=="1") {
                var prevcount = $('#favcount').html();
                if(addtype) {
                   prevcount--; 
                } else {
                    prevcount++;
                }
                $('#favcount').html(prevcount);
            }
        }
    });
}

function ShowHideDiv(controller,tochange,opp) {
    var elToChange = document.getElementById(tochange);
    var checkStatus = controller.checked;
    
    if (opp) {
        if (checkStatus) {
            elToChange.style.display = 'block';
        } else {
            elToChange.style.display = 'none';
        }
    } else {
        if (checkStatus) {
            elToChange.style.display = 'none';
        } else {
            elToChange.style.display = 'block';
        }
    }
}

function changelang(newlang,diffurl) {
    $.ajax({
        url: siteurl+'secure/ajax.change_language.php?newlang='+newlang,
        success: function(){
            if(diffurl) {
                window.location = siteurl+diffurl;   
            } else {
                location.reload();
            }
        }
    });
}

function showAcc2(curbutton,this_detail) {
    if (BrowserDetect.browser=="Explorer") {
        var butarray = getElementsByName_iefix('td','accbutton');
        for (b=0;b<butarray.length;b++) {
            butarray[b].className = 'but_acc2';
        }
        var conarray = getElementsByName_iefix('div','content_text');
        for (c=0;c<conarray.length;c++) {
            conarray[c].style.display = 'none';
        }

        if (this_detail == '3') {
            document.getElementById('content_acc').style.display = 'block';
        } else if (this_detail == '4') {
            document.getElementById('content_feat').style.display = 'block';
        } else if (this_detail == '5') {
            document.getElementById('content_spec').style.display = 'block';
        } else if (this_detail == '6') {
            document.getElementById('content_inc').style.display = 'block';
        }

        curbutton.className = 'but_acc_sel2';
    } else {
        var butarray = document.getElementsByName('accbutton');
        for (b=0;b<butarray.length;b++) {
            butarray[b].className = 'but_acc2';
        }
        var conarray = document.getElementsByName('content_text');
        for (c=0;c<conarray.length;c++) {
            conarray[c].style.display = 'none';
        }
    
        if (this_detail == '3') {
            document.getElementById('content_acc').style.display = 'block';
        } else if (this_detail == '4') {
            document.getElementById('content_feat').style.display = 'block';
        } else if (this_detail == '5') {
            document.getElementById('content_spec').style.display = 'block';
        } else if (this_detail == '6') {
            document.getElementById('content_inc').style.display = 'block';
        }
        curbutton.className = 'but_acc_sel2';
    }
}

function pubaddBasket(cont, isapi, ulimit, kitno, refreshpage, stockitem, lang)
{
    var e = 0;
    var elid = cont.id.split("_");
    var remdiv = 'off_' + elid[1]+'_'+elid[2];
    var adddiv = 'on_' + elid[1]+'_'+elid[2];
    var qtybox = 'qty_' + elid[1]+'_'+elid[2];
    var qtyspan = 'qt_' + elid[1]+'_'+elid[2];
    var unitsel = 'sel_' + elid[1]+'_'+elid[2];
    var qohbox = 'qoh_' + elid[1]+'_'+elid[2];
    var limitxt = 'ltxt_' + elid[1]+'_'+elid[2];
    var maxbox = 'max_' + elid[1]+'_'+elid[2];
    var conve = 'unt_' + elid[1]+'_'+elid[2];
    
    var iqty = document.getElementById(qtybox).value;
    var unitidx = document.getElementById(unitsel).value;
    var itemqty = document.getElementById(qohbox).value;
    var maxlim = document.getElementById(maxbox).value;
    var cli = document.getElementById('pubclient').value;
    
    if(document.getElementById(conve)) {
        var convqty = document.getElementById(conve).value;
    }
    if(!convqty) { convqty = 1; }
    itemqty = itemqty/parseInt(convqty);
    
    if (iqty>0) {
        var backorder = document.getElementById('gbo').value;
        var globalmax = document.getElementById('gmax').value;
        var ajaxRequest;
        
        // For size color module
        var ppo1 = 'ppo1_'+elid[1]+'_'+elid[2];
        var ppo2 = 'ppo2_'+elid[1]+'_'+elid[2];
        var pex1 = document.getElementById(ppo1);
        var pex2 = document.getElementById(ppo2);
        if(pex1) { var pps1 = pex1.value; }
        if(pex2) { var pps2 = pex2.value; }
        
        try { ajaxRequest = new XMLHttpRequest(); }
        catch (e) {
            try { ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
            catch (e) {
                try { ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");    }
                catch (e) {
                    alert("Your browser broke!");
                    return false;
                }
            }
        }
        
        ajaxRequest.onreadystatechange = function() {
            if(ajaxRequest.readyState == 4) {
                var ajaxDisplay = document.getElementById('basketdiv');
                ajaxDisplay.innerHTML = ajaxRequest.responseText;
                if(ajaxRequest.responseText) {
                    if(refreshpage) {
                        window.location = siteurl+'your-cart';    
                    }
                    if(document.getElementById('direct_basket').value==1) {
                        window.location = siteurl+'your-cart';
                    }
                }
            }
        }
        
        var queryString = "?ISAPI_100_51=" + isapi + "&pid=" + elid[1] + "&qty=" + iqty + "&unm=" + unitidx + "&kit_no=" + kitno + "&client=" + cli;
        
        var refpage = 0;
        var Iitemqty = parseInt(itemqty);
        var Iiqty = parseInt(iqty);
        var Imaxlim = parseInt(maxlim);
        var Iulimit = parseInt(ulimit);
        var Iglobalmax = parseInt(globalmax);
        if(lang=="FR") {
            var lblqty = 'QTÉ EXCÉDAIT';
            var lblmax = 'QTÉ MAX EXCÉDAIT';
        } else {
            var lblqty = 'QTY EXCEEDED';
            var lblmax = 'MAX QTY EXCEEDED';
        }
        
        if (Iitemqty<Iiqty && backorder<1 && stockitem) {
            document.getElementById(limitxt).innerHTML = lblqty;
            //document.getElementById(qtybox).value = Iitemqty;
        } else if (Imaxlim>0 && Imaxlim<Iiqty && ulimit<2) {
            document.getElementById(limitxt).innerHTML = lblmax;
            //document.getElementById(qtybox).value = Imaxlim;
        } else if (Imaxlim<1 && Iglobalmax>0 && Iglobalmax<Iiqty && ulimit<2) {
            document.getElementById(limitxt).innerHTML = lblmax;
            //document.getElementById(qtybox).value = Iglobalmax;
        } else {
            
            if (pps1 || pps2) {
                queryString = queryString + '&o1=' + pps1 + '&o2=' + pps2 + '&client=' + cli;
            }
            
            ajaxRequest.open("GET", siteurl+"secure/pub.snap_basket.php" + queryString, true);
            ajaxRequest.send(null); 
            
            if(!pex1&&!pex2) {
                document.getElementById(limitxt).innerHTML = '';
                document.getElementById(qtyspan).innerHTML = iqty;
                document.getElementById(adddiv).style.display = 'none';
                document.getElementById(remdiv).style.display = 'block';
                document.getElementById(unitsel).disabled = true;
                document.getElementById(unitsel).style.backgroundColor = '#F2F2F2';
            }
        }
        
        if(refreshpage && refpage) {
            window.location = siteurl+'your-cart';    
        } else {
            var boxname = 'pricebox_'+elid[1]+'_'+elid[2];
            ajaxGo(1,siteurl+'secure/pub.price.php'+queryString,boxname);   
        }
        
    } else {
        document.getElementById(limitxt).innerHTML = 'YOU CANNOT PUT ZERO QUANTITY TO BASKET';
        document.getElementById(qtybox).value = 1;    
    }
}

function pubremBasket(cont, isapi, unitc, pub, kitno, refreshpage)
{
    var elid = cont.id.split("_");    
    var remdiv = 'off_' + elid[1]+'_'+elid[2];
    var adddiv = 'on_' + elid[1]+'_'+elid[2];
    var unitsel = 'sel_' + elid[1]+'_'+elid[2];
    var ajaxRequest;
    var cli = document.getElementById('pubclient').value;
    
    try { ajaxRequest = new XMLHttpRequest(); }
    catch (e) {
        try { ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
        catch (e) {
            try { ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");    }
            catch (e) {
                alert("Your browser broke!");
                return false;
            }
        }
    }
    
    ajaxRequest.onreadystatechange = function() {
        if(ajaxRequest.readyState == 4) {
            var ajaxDisplay = document.getElementById('basketdiv');
            ajaxDisplay.innerHTML = ajaxRequest.responseText;
        }
    }

    var queryString = "?ISAPI_100_51=" + isapi + "&did=" + elid[1] + "&kit_no=" + kitno + '&client=' + cli;
    ajaxRequest.open("GET", siteurl+"secure/pub.snap_basket.php" + queryString, true);
    ajaxRequest.send(null); 

    var multdiv = 'mult_'+elid[1];
    if (document.getElementById(multdiv)) {
        document.getElementById(multdiv).style.display = 'none';    
    }

    document.getElementById(remdiv).style.display = 'none';
    document.getElementById(adddiv).style.display = 'block';
    if (unitc>1) {
        document.getElementById(unitsel).disabled = false;
        document.getElementById(unitsel).style.backgroundColor = '#FFFFFF';
    }
    
    var boxname = 'pricebox_'+elid[1]+'_'+elid[2];
    if(document.getElementById(unitsel)) {
        var unitlast = document.getElementById(unitsel).value;
    }
    
    var restorestring = "?pid=" + elid[1] + "&unm=" + unitlast + "&qty=1";
    ajaxGo(1,siteurl+'secure/pub.price.php'+restorestring,boxname);
    
    if(refreshpage) {
        window.location.reload();    
    }
}

function pubrefreshBasket(cont, isapi, pcode, iskit, pub)
{
    var elid = cont.id.split("_");
    var basdiv = 'tbas_' + elid[1]+'_'+elid[2];
    var ajaxRequest;
    var cli = document.getElementById('pubclient').value;

    try { ajaxRequest = new XMLHttpRequest(); }
    catch (e) {
        try { ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
        catch (e) {
            try { ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");    }
            catch (e) {
                alert("Your browser broke!");
                return false;
            }
        }
    }

    ajaxRequest.onreadystatechange = function() {
        if(ajaxRequest.readyState == 4) {
            var ajaxDisplay = document.getElementById(basdiv);
            ajaxDisplay.innerHTML = ajaxRequest.responseText;
        }
    }
    var queryString = "?ISAPI_100_51=" + isapi + '&pc=' + pcode + '&client=' + cli;
    if (pub) {
        ajaxRequest.open("GET", "secure/sc.snapshot_multiple.php" + queryString, true);
    } else {
        ajaxRequest.open("GET", "sc.snapshot_multiple.php" + queryString, true);
    }
    ajaxRequest.send(null);
}

function pubchangePrice(controller, pcode, bcount, price_ok, qoh_ok, convertor_array, backorder)
{
    var chopchop = convertor_array.split('::');
    var choplength = chopchop.length-1;
    var conversion = new Array();
    for (c=0;c<choplength;c++) {
        var chopagain = chopchop[c].split('^');
        conversion[chopagain[0]] = chopagain[1];
    }
    var elid = controller.id.split("_");
    
    var selPrice = controller.options[controller.selectedIndex].value;
    if (selPrice) {
        for(i=0;i<bcount;i++) {
            /*
            if (price_ok == 1) {
                divtoHide = pcode + '_' + i;
                divHide = document.getElementById(divtoHide);
                if (divHide) { divHide.style.display = 'none'; }
            }
            */
            if (qoh_ok == 1) {
                div2toHide = '2' + pcode + '_' + i;
                div2Hide = document.getElementById(div2toHide);
                if (div2Hide) {    div2Hide.style.display = 'none'; }
            }
            div3toHide = '3' + pcode + '_' + i;
            div3Hide = document.getElementById(div3toHide);
            if (div3Hide) { div3Hide.style.display = 'none'; }
        }
        
        /*
        if (price_ok == 1) {
            var divName = pcode + '_' + selPrice;
            theDiv = document.getElementById(divName);
            if(theDiv) { theDiv.style.display = 'block'; }
        }
        */
        if (qoh_ok == 1) {
            var div2Name = '2' + pcode + '_' + selPrice;
            the2Div = document.getElementById(div2Name);
            if (the2Div) { the2Div.style.display = 'block'; }
        }
        var div3Name = '3' + pcode + '_' + selPrice;
        the3Div = document.getElementById(div3Name);
        if (the3Div) { the3Div.style.display = 'block'; }

        var txtName = pcode + '_unit';
        var conName = pcode + '_con';
        theTxt = document.getElementById(txtName);
        if (theTxt) { theTxt.value = selPrice; }
        theCon = document.getElementById(conName);
        if (theCon) { theCon.value = conversion[selPrice]; }
        
        var unithn = 'unt_' + elid[1] + '_' + elid[2];
        if(document.getElementById(unithn)) {
            document.getElementById(unithn).value = conversion[selPrice];
        }
    }
    
    
    var qtybox = 'qty_' + elid[1]+'_'+elid[2];
    var boxname = '#pricebox_'+elid[1]+'_'+elid[2];
    var iqty = document.getElementById(qtybox).value;
    
    var queryString = "?pid=" + elid[1] + "&qty=1&unm=" + selPrice;
    //ajaxGo(1,'sc.price.php'+queryString,boxname);
    $.get(siteurl+'secure/pub.price.php'+queryString,function(data) {
       $(boxname).html(data);
    });
}

function changeCurrency(curused) {
    document.getElementById('applycurrencychange').value = 1;
    document.getElementById('currencychange').value = curused;
    document.getElementById('change_currency_form').submit();
}

function commentchange(controller,ispub,scloc) {
    var cons = controller.id.split("_");
    var linkid = "#clink_"+cons[1]+"_"+cons[2];
    var commid = "#comment_"+cons[1]+"_"+cons[2];
    
    if(controller.value=="-usetext-") {
        $(linkid).show();
    } else {
        $(linkid).hide();   
    }
    var selquery = siteurl+'secure/sc.snapshot_dropdown.php?Product='+cons[1]+'&kitno='+cons[2]+'&selcomm='+controller.value+'&ispublic='+ispub;
    $.post(selquery);
    
    if(scloc=="3") { var dvcomm = 'comments3'; }
    else if(scloc=="2") { var dvcomm = 'comments4'; }
    else if(scloc=="1") { var dvcomm = 'comments2'; }
    else { var dvcomm = 'comments'; }
    
    if(controller.value=="-usetext-") {
        if(ispub) {
            var refquery = siteurl+'secure/pub.snippet.php?snippet='+dvcomm+'&Product='+cons[1];
        } else {
            var refquery = siteurl+'secure/sc.snippet.php?snippet='+dvcomm+'&Product='+cons[1];
        }
        $.get(refquery,function(data) {
            if(data) {
                $(commid).html(data);
                $(commid).show();
            } 
        });
    } else {
        $(commid).hide();
    }
}

function navaccord(nav) {
    var divnav = '#nav_'+nav;
    var downnav = '#down_'+nav;
    var rightnav = '#right_'+nav;
    $(divnav).toggle();
    $(downnav).toggle();
    $(rightnav).toggle();
}

function switchview(cont) {
    $.get(siteurl+'secure/pub.switch.php?type=view&value='+cont.value, function(ret) {
        if(ret) {
            location.reload(true);
        }
    });
}

function switchsort(cont) {
    $.get(siteurl+'secure/pub.switch.php?type=sort&value='+cont.value, function(ret) {
        if(ret) {
            location.reload(true);
        }
    });   
}

function switchpage(pageno) {
    $.get(siteurl+'secure/pub.switch.php?type=page&value='+pageno, function(ret) {
        if(ret) {
            location.reload(true);
        }
    });   
}

function addtowishlist(controller,productcode,kitnum,wishid,ispub) {
    var afavel = 'isfave_'+productcode+'_'+kitnum;
    var nfavel = 'nofave_'+productcode+'_'+kitnum;
    
    var theaddquery = siteurl+'secure/sc.snapshot_wishlist.php?wishid='+wishid+'&Product='+productcode+'&kit_no='+kitnum+'&ispublic='+ispub;
    
    $.get(theaddquery, function(data) {
        var datasplit = data.split('::');
        if(datasplit[0]) {
            if(datasplit[0]=="1") {
                $('#wish_'+wishid).hide();
            }
        }
    });
}

$(document).ready(function() {
    $(".wishlist").hover(function () {
        var menu = $(this).find(".wishhovermenu");
        menu.css({
            'left': $(this).position().left - 5,
            'top': $(this).position().top - 5
        });
        menu.show();
    }, function () {
        $(this).find(".wishhovermenu").hide();
    });
});
