<!--

function myOnSubmitEventHandler() {
		try {
			if(typeof(document.getElementById('editor1').EscapeUnicode) == 'undefined') {
				throw "Error"
			} else {
				document.getElementById('editor1').EscapeUnicode = true;
				document.getElementById('xhtml1').value = document.getElementById('editor1').value;
			}			
		}
		catch(er) {
			document.getElementById('xhtml1').value = document.getElementById('alternate1').value;
		}
	}
	

function moveup(uSel) {
   var intNewValue;
   var strNewText;
	for (i=1;i<uSel.options.length;i++)
		if (uSel.options[i].selected)
		{
		   intNewText = uSel.options[i-1].text;
		   intNewValue = uSel.options[i-1].value;
		   uSel.options[i-1].text = uSel.options[i].text;
		   uSel.options[i-1].value = uSel.options[i].value;
		   uSel.options[i].text = intNewText;
		   uSel.options[i].value = intNewValue;
		   uSel.options[i].selected = false;    
		   uSel.options[i-1].selected = true;    
		}
		
}
function movedown(uSel) {
   var intNewValue;
   var strNewText;
	for (i=uSel.options.length - 2;i>=0;i--)
		if (uSel.options[i].selected)
		{
		   intNewText = uSel.options[i+1].text;
		   intNewValue = uSel.options[i+1].value;
		   uSel.options[i+1].text = uSel.options[i].text;
		   uSel.options[i+1].value = uSel.options[i].value;
		   uSel.options[i].text = intNewText;
		   uSel.options[i].value = intNewValue;
		   uSel.options[i].selected = false;    
		   uSel.options[i+1].selected = true;    
		   
		}
}	

function submitform(uSel,uTxt) {
    var strSubmitString
    strSubmitString = "";
  	for (i=0;i<uSel.options.length;i++)
  	    {
  		if (i == 0) {
  	       strSubmitString = uSel.options[i].value
           }
           else
           {
  	       strSubmitString = strSubmitString + "|" + uSel.options[i].value
           }
        }     
       uTxt.value = strSubmitString; 		   	    
}

function ImageLoadFailed() {
  window.event.srcElement.style.display = "None";
}


/*

addRemoveClass:

check if there is already a class applied and add the new one preceeded by a space if that is the case:
a - defines the action you want the function to perform.
o - the object in question.
c1 - the name of the first class
c2 - the name of the second class

Possible actions are:

swap - replaces class c1 with class c2 in object o.
add - adds class c1 to the object o.
remove - removes class c1 from the object o.
check - test if class c1 is already applied to object o and returns true or false. 

*/

function addRemoveClass(a,o,c1,c2)
{
  switch (a){
    case 'swap':
      o.className=!addRemoveClass('check',o,c1)?o.className.replace(c2,c1): o.className.replace(c1,c2);
    break;
    case 'add':
      if(!addRemoveClass('check',o,c1)){o.className+=o.className?' '+c1:c1;}
    break;
    case 'remove':
      var rep=o.className.match(' '+c1)?' '+c1:c1;
      o.className=o.className.replace(rep,'');
    break;
    case 'check':
      return new RegExp('\\b'+c1+'\\b').test(o.className)
    break;
  }
}

function findParent(elementID){
	var childElement = document.getElementById(elementID);
	for (var i=0; i<document.forms.length; i++) { 
		for (var x=0; x<document.forms[i].elements.length; x++) {
			alert(childElement.parentNode.id);
			if(childElement.id == elementID){
				return document.forms[i].id;
			}
		}
	} 
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	var str = new String(features);
	var hStartPos, hEndPos, hVal 
	var wStartPos, wEndPos, wVal	
	var x, y
	
	if((str.indexOf("height") >= 0)&&(str.indexOf("width") >= 0)) {
		hStartPos = str.indexOf("height");	
		hEndPos = str.indexOf(",", hStartPos);
		hVal = str.substring(hStartPos + 7, hEndPos);
	
		wStartPos = str.indexOf("width");	
		wEndPos = str.indexOf(",", wStartPos);
		wVal = str.substring(wStartPos + 6, wEndPos);
	
		x = (screen.availWidth / 2) - (wVal / 2)
		y = (screen.availHeight / 2) - (hVal / 2)
		
		var newWin = window.open(theURL,winName,features);
		newWin.moveTo(x, y);
	}
	else {
		window.open(theURL,winName,features);
	}
}

function changeDate(newDate) {
	var startDate = document.getElementById('txtDate');
	startDate.value = newDate;
	document.getElementById('frmUser').submit();
}

// fieldList is comma separated, no whitespace
function chkReqdFields(formName, fieldList) {
	var arrFields;
	var i = 0
//	alert('Checking ' + formName);

	arrFields = fieldList.split(',');
	for(i = 0; i<arrFields.length; i++) {
		//alert('Checking ' + arrFields[i]);
		if(isWhitespace(eval('document.forms["' + formName + '"].' + arrFields[i] + '.value'))) {
			alert("Veuillez remplir tous les champs obligatoires.");
			return false;
		}
	}
	return true;
}

// Check whether string s is empty.
function isEmpty(s) {
   return ((s == null) || (s.length == 0))
}

// whitespace characters
var whitespace = " \t\n\r";

// Returns true if string s is empty or
// whitespace characters only.
function isWhitespace (s) {   
	var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

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") == "external")
     anchor.target = "_blank";
}
}

var popupLinkConfig = new Array;

//====Popup Window Parameters==============//
// popupLinkConfig["classname"] = new Array ( "targetname", "width=550,height=350,scrollbars=yes,resizable=yes,status=yes,toolbar=yes,location=yes,menubar=yes");
popupLinkConfig["popup"]    = new Array ( "", "width=500,height=450,scrollbars=yes,resizable=yes,menubar=no");
popupLinkConfig["glossary"] = new Array ( "help", "width=550,height=350,resizable=yes");
// ==========================================================================


function initPopupLinks()
{
  if (!document.getElementsByTagName) return true;
  var pageLinks = document.getElementsByTagName("a");
  for (var i = 0; i < pageLinks.length; i++) 
  {
    if (((pageLinks[i].className != null) && 
         (pageLinks[i].className != "")) ||
        ((pageLinks[i].parentNode.className != null) && 
         (pageLinks[i].parentNode.className != "")))
    {
      var linkClass = " " + pageLinks[i].className + " ";
      if ((linkClass == "  ") && (pageLinks[i].parentNode.className != ""))
      {
        linkClass = " " + pageLinks[i].parentNode.className + " ";
      }
      for (var theKey in popupLinkConfig) 
      {
        if (linkClass.indexOf(" " + theKey + " ") > -1)
        {
          if ((pageLinks[i].target == "") || (pageLinks[i].target == null))
          {
            pageLinks[i].target = (popupLinkConfig[theKey][0] != "") ? popupLinkConfig[theKey][0] : theKey;
          }
          pageLinks[i].settings = popupLinkConfig[theKey][1];
          pageLinks[i].onclick = popUp;
        }
      }
    }
  }
  return true;
}

function popUp()
{
  newWin = window.open(this.href, this.target, this.settings);
  newWin.focus();
  return false;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
  if (restore) selObj.selectedIndex=0;
}


var myrules = {
		
		'.bbyCart' : function(element){
			element.onload = function(){
				document.getElementById('frmBBYCart').submit();
			}
		},
		
		'.selectBox' : function(element){
			element.onchange = function(){
				document.editTime.submit();
			}
		},
		'.printButton' : function(element){
			element.onclick = function(){
				window.print();
			}
		},
		'.checkSubmit' : function(element){
			element.onclick = function(){
				document.frmFinder.txtAvail.value = 'true';
				document.forms[0].submit();
			}
		},
		'.radioSubmit' : function(element){
			element.onclick = function(){
				document.frmFinder.txtSearch.value = 'true';
				document.forms[0].submit();
			}
		},
		'.radioIndex' : function(element){
			element.onclick = function(){
			document.forms[0].submit();
			}
		},
		'.productLink' : function(element){
			element.onclick = function(){
				loadOpener(element.href);
				return false;
			}
		},
		'#frmTime' : function(element){
			element.onsubmit = function(){
				return chkReqdFields('frmTime','selTask');
			}
		},
		'#selAvailableTime' : function(element){
			element.onchange = function(){
				document.getElementById('frmUser').submit();
			}
		},
		'#chkShowAll' : function(element){
			element.onclick = function(){
				var formName = findParent(element.id)
				document.getElementById(formName).submit();
			}
		},
		'.btnPopupCancel' : function(element){
			element.onclick = function(){
				window.close();
			}
		},
		'fieldset' : function(element){
			element.onmouseover = function(){
				addRemoveClass('add',this,'over');
			}
			element.onmouseout = function(){
				addRemoveClass('remove',this,'over');
			}
		},
		'.submitButton' : function(element){
			element.onmouseover = function(){
				addRemoveClass('add',this,'over');
			}
			element.onmouseout = function(){
				addRemoveClass('remove',this,'over');
			}
		},
		'.productInfo' : function(element){
			var myDt = element.getElementsByTagName("dt").item(0);
			/*var myLink= myDt.getElementsByTagName("a").item(0);*/
			element.onmouseover = function(){
				addRemoveClass('add',this,'over');
			}
			element.onmouseout = function(){
				addRemoveClass('remove',this,'over');
			}
			/*element.onclick = function(){
				var linkAddress = myLink.getAttribute('href');
				parent.location=linkAddress;
			}*/
		},
		'.deleteProductButton' : function(element){
			element.onclick = function(){
				window.confirm("Are you sure you want to remove this item from your cart?");
			}
		}
	}

//=======Onload=============//
  
window.onload=function(){
 externalLinks();
 initPopupLinks();
 Behaviour.register(myrules);
}

function loadOpener(theURL)
{
self.opener.location.href=theURL;
self.opener.focus();
return false;
}

function bbyCart()
{
	//alert('here');
	document.getElementById('frmBBYCart').submit();
}

function changeProductColor(id, newClass) {

identity=document.getElementById(id);
identity.className=newClass;

if (id == 'rdoDesktopLabel') {
	identity=document.getElementById('rdoNotebookLabel');
	identity.className='selectButton';
}

if (id == 'rdoNotebookLabel') {
	identity=document.getElementById('rdoDesktopLabel');
	identity.className='selectButton';
}

}


function changeColor(id, newClass) {

identity=document.getElementById(id);
identity.className=newClass;

if (id == 'rdoProductLabel01') {
	identity=document.getElementById('rdoProductLabel02');
	identity.className='selectButton';
	identity=document.getElementById('rdoProductLabel03');
	identity.className='selectButton';
}

if (id == 'rdoProductLabel02') {
	identity=document.getElementById('rdoProductLabel01');
	identity.className='selectButton';
	identity=document.getElementById('rdoProductLabel03');
	identity.className='selectButton';
}

if (id == 'rdoProductLabel03') {
	identity=document.getElementById('rdoProductLabel01');
	identity.className='selectButton';
	identity=document.getElementById('rdoProductLabel02');
	identity.className='selectButton';
}

}


function changeEssentialColor(id, newClass, chkName) {

identity=document.getElementById(chkName);

//alert(identity.checked);

if (identity.checked == true) {
	identity=document.getElementById(id);
	identity.className=newClass;	
} else {
	identity=document.getElementById(id);
	identity.className='selectButton';
	}
}

function changeSingleEssentialColor(id, newClass, chkName, id2, id3) {

identity=document.getElementById(chkName);

if (identity.checked == true) {
	identity=document.getElementById(id);
	identity.className=newClass;	
} else {
	identity=document.getElementById(id);
	identity.className='selectButton';
	}

identity=document.getElementById(id2);
identity.className='selectButton';

identity=document.getElementById(id3);
identity.className='selectButton';
}


function calcOrderTotal(varAmount, varFieldName, lngRowCount) {
//	alert(varAmount);
	var curVal = 0;
	var newVal = 0;
	var salesTax = 0;
	var shippingCost = 0;
	var grandTotal = 0;
		
	//first block of code inserts line item pricing via div tags	
	if(varFieldName!=undefined){
		if(varAmount > 0) {
			document.getElementById(varFieldName).innerHTML = formatNumber(varAmount, "0.00");
		}
		else {
			document.getElementById(varFieldName).innerHTML = '0.00';
		}	
	}		          

	//remaining code calculates total, tax, and shipping
	//curVal = frmReview.txtTotal.value;
	curVal = document.getElementById('Total').innerHTML;
	curVal = curVal.replace(/,/,"");
	
	
	//change row colors
	var table = document.getElementById("reviewTable");   
	var rows = table.getElementsByTagName("tr");  
	
	lngRowCount = lngRowCount - 1;
	
	if(varAmount < 0) {
		newVal = curVal - Math.abs(varAmount);
		rows[lngRowCount].className = "grayout";
	}
	else {
		newVal = eval(curVal) + eval(varAmount);
		rows[lngRowCount].className = "white"; 
	}
	//frmReview.txtTotal.value = formatNumber(newVal, "0.00");
	document.getElementById('Total').innerHTML = formatNumber(newVal, "0.00");
}

  var separator = ",";  // use comma as 000's separator
  var decpoint = ".";  // use period as decimal point
  var percent = "%";
  var currency = "$";  // use dollar sign for currency

  function formatNumber(number, format, print) {  // use: formatNumber(number, "format")
    if (print) document.write("formatNumber(" + number + ", \"" + format + "\")<br>");

    if (number - 0 != number) return null;  // if number is NaN return null
    var useSeparator = format.indexOf(separator) != -1;  // use separators in number
    var usePercent = format.indexOf(percent) != -1;  // convert output to percentage
    var useCurrency = format.indexOf(currency) != -1;  // use currency format
    var isNegative = (number < 0);
    number = Math.abs (number);
    if (usePercent) number *= 100;
    format = strip(format, separator + percent + currency);  // remove key characters
    number = "" + number;  // convert number input to string

     // split input value into LHS and RHS using decpoint as divider
    var dec = number.indexOf(decpoint) != -1;
    var nleftEnd = (dec) ? number.substring(0, number.indexOf(".")) : number;
    var nrightEnd = (dec) ? number.substring(number.indexOf(".") + 1) : "";

     // split format string into LHS and RHS using decpoint as divider
    dec = format.indexOf(decpoint) != -1;
    var sleftEnd = (dec) ? format.substring(0, format.indexOf(".")) : format;
    var srightEnd = (dec) ? format.substring(format.indexOf(".") + 1) : "";

     // adjust decimal places by cropping or adding zeros to LHS of number
    if (srightEnd.length < nrightEnd.length) {
      var nextChar = nrightEnd.charAt(srightEnd.length) - 0;
      nrightEnd = nrightEnd.substring(0, srightEnd.length);
      if (nextChar >= 5) nrightEnd = "" + ((nrightEnd - 0) + 1);  // round up

 // patch provided by Patti Marcoux 1999/08/06
      while (srightEnd.length > nrightEnd.length) {
        nrightEnd = "0" + nrightEnd;
      }

      if (srightEnd.length < nrightEnd.length) {
        nrightEnd = nrightEnd.substring(1);
        nleftEnd = (nleftEnd - 0) + 1;
      }
    } else {
      for (var i=nrightEnd.length; srightEnd.length > nrightEnd.length; i++) {
        if (srightEnd.charAt(i) == "0") nrightEnd += "0";  // append zero to RHS of number
        else break;
      }
    }

     // adjust leading zeros
    sleftEnd = strip(sleftEnd, "#");  // remove hashes from LHS of format
    while (sleftEnd.length > nleftEnd.length) {
      nleftEnd = "0" + nleftEnd;  // prepend zero to LHS of number
    }

    if (useSeparator) nleftEnd = separate(nleftEnd, separator);  // add separator
    var output = nleftEnd + ((nrightEnd != "") ? "." + nrightEnd : "");  // combine parts
    output = ((useCurrency) ? currency : "") + output + ((usePercent) ? percent : "");
    if (isNegative) {
      output = (useCurrency) ? "(" + output + ")" : "-" + output;
    }
    return output;
  }

  function strip(input, chars) {  // strip all characters in 'chars' from input
    var output = "";  // initialise output string
    for (var i=0; i < input.length; i++)
      if (chars.indexOf(input.charAt(i)) == -1)
        output += input.charAt(i);
    return output;
  }

  function separate(input, separator) {  // format input using 'separator' to mark 000's
    input = "" + input;
    var output = "";  // initialise output string
    for (var i=0; i < input.length; i++) {
      if (i != 0 && (input.length - i) % 3 == 0) output += separator;
      output += input.charAt(i);
    }
    return output;
  }

//-->
