<!--

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("Please fill in all required fields.");
			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 = {
		'.selectBox' : function(element){
			element.onchange = function(){
				document.forms.frmFinder.submit();
			}
		},
		'.selectBoxSort' : function(element){
			element.onchange = function(){
				document.forms.frmFinder.submit();
			}
		},
		'.printButton' : function(element){
			element.onclick = function(){
				window.print();
			}
		},
		'.radioSubmit' : function(element){
			element.onclick = function(){
				document.forms.frmFinder.submit();
			}
		},
		/*'.productLink' : function(element){
			element.onclick = function(){
				loadOpener(element.href);
				return false;
			}
		},*/
		'.productLinkKiosk' : function(element){
			element.onclick = function(){
				loadOpenerKiosk(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');
				window.status="Test";
			}
			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(){
for(var i=0;i<onloadHandlers.length;i++){
			eval(onloadHandlers[i]);
		}
 onloadHandlers[onloadHandlers.length] = 'SideTabs = new TabNav("side-tabs", "side")';
 onloadHandlers[onloadHandlers.length] = 'PipTabs = new TabNav("pip-tab-controls", "pip-tabs")';
 onloadHandlers[onloadHandlers.length] = 'Tabs = new TabNav("tab-controls", "tabs")';
 externalLinks();
 initPopupLinks();
 Behaviour.register(myrules);

}


function loadOpener(theURL)
{
self.opener.location.href=theURL;
self.opener.focus();
return false;
}

function loadOpenerKiosk(theURL)
{
//win2=window.open(theURL)
//win2.blur()
//window.focus()

remote = window.open("","remotewin");
remote.location.href = theURL;
    if (remote.opener == null) remote.opener = window; 
remote.opener.name = "opener";
//remote.blur();
//window.focus();
}


function saveProduct(theURL,RetailerProductID,CartID,Position)
{
call_server(RetailerProductID, CartID, Position);
window.location.href=theURL;
return false;
}


function creat_Object()
{ 
var xmlhttp;
// This if condition for Firefox and Opera Browsers 
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
{
try 
{
xmlhttp = new XMLHttpRequest();
} 
catch (e) 
{
alert("Your browser is not supporting XMLHTTPRequest");
xmlhttp = false;
}
}
// else condition for ie
else
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}

var request = creat_Object();

function sever_interaction()
{
	if(request.readyState == 4)
	{
	//var answer = request.responseText;
	//document.getElementById('productAjax'+document.forms[0].AjaxDiv.value).innerHTML='';
	//document.getElementById('productAjax'+document.forms[0].AjaxDiv.value).innerHTML = answer;
	//reloadModal();
	}
}

function call_server(RetailerProductID, CartID, Position)
{	
	request.open("GET", "saveCart.ashx?RetailerProductID=" + RetailerProductID + '&CartID=' + CartID + '&Position=' + Position); 
	request.onreadystatechange = sever_interaction;
	request.send('');
}