<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function changeImages() {
	if (document.images) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}
function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function confPass(){
	if (document.RegisterMe.thePass.value == document.RegisterMe.CPass.value) {
		if(document.RegisterMe.thePass.value==""){
			alert("Please enter a password");
			return false;
		}else{
			if(document.RegisterMe.UName.value==""){
				alert("Please enter a Username");
				return false;
			}else{
				if(document.RegisterMe.theEmail.value==""){
					alert("Please enter a valid email address");
					return false;
				}else{
					return true;
				}
			}
		}
	}else{
	alert("Your password and confirmation of password are different. Please re-enter these details");
	document.RegisterMe.thePass.value = "";
	document.RegisterMe.CPass.value = "";
	return false;
	}
}

function giveWarningAndFixValue(field) {
//removes all non-numeric value and replaces
	var value = parseInt(field.value);
	if(!isNaN(value)) field.value = value;
	else field.value = "0";
	//used for NS4.7 because when changing value the cursor is placed in front of the value, instead of behind
	if(document.layers) field.select();
}

function isNumericValue(str) {
	var isValid = true;
	if(str.search(/^[0-9]+$/) == -1) {
		isValid = false;
	}
	return isValid;
}
function checkValue(field) {
	if(!isNumericValue(field.value)) {
		giveWarningAndFixValue(field);
	}
}
/*
function confirmdel()
{
	return window.confirm("If you delete this page all data in it will be lost. Are you sure you wish to continue?");
}

function confirmdelCont()
{
	return window.confirm("Are you sure you wish to delete this content?");
}*/

function CheckPrice(obj)
{
	//validate the price is a positive integer
	if (obj.value=="")
	{
		alert("You must enter a price.");
		return false;
	}
	else
	{	
	
		if (obj.value.search(/[^\d]/)>-1)
		{
		alert("The price must be whole dollars in numbers only with no other characters.");
		obj.value = '0';
		return false;
		}
		else
		{
		return true;
		}		
	}	
}
function CheckQuantity(obj)
{
	if (obj.value=="")
	{
		alert("You must enter a quantity.");
		return false;
	}
	else
	{
		if (obj.value.search(/[^\d]/)>-1)
		{
		alert("The quantity must be a positive number and contain numbers only with no other characters.");
		obj.value = '1';
		return false;
		}
		else
		{
		return true;
		}		
	}	
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_timelinePlay(tmLnName, myID) { //v1.2
  //Copyright 1997, 2000 Macromedia, Inc. All rights reserved.
  var i,j,tmLn,props,keyFrm,sprite,numKeyFr,firstKeyFr,propNum,theObj,firstTime=false;
  if (document.MM_Time == null) MM_initTimelines(); //if *very* 1st time
  tmLn = document.MM_Time[tmLnName];
  if (myID == null) { myID = ++tmLn.ID; firstTime=true;}//if new call, incr ID
  if (myID == tmLn.ID) { //if Im newest
    setTimeout('MM_timelinePlay("'+tmLnName+'",'+myID+')',tmLn.delay);
    fNew = ++tmLn.curFrame;
    for (i=0; i<tmLn.length; i++) {
      sprite = tmLn[i];
      if (sprite.charAt(0) == 's') {
        if (sprite.obj) {
          numKeyFr = sprite.keyFrames.length; firstKeyFr = sprite.keyFrames[0];
          if (fNew >= firstKeyFr && fNew <= sprite.keyFrames[numKeyFr-1]) {//in range
            keyFrm=1;
            for (j=0; j<sprite.values.length; j++) {
              props = sprite.values[j]; 
              if (numKeyFr != props.length) {
                if (props.prop2 == null) sprite.obj[props.prop] = props[fNew-firstKeyFr];
                else        sprite.obj[props.prop2][props.prop] = props[fNew-firstKeyFr];
              } else {
                while (keyFrm<numKeyFr && fNew>=sprite.keyFrames[keyFrm]) keyFrm++;
                if (firstTime || fNew==sprite.keyFrames[keyFrm-1]) {
                  if (props.prop2 == null) sprite.obj[props.prop] = props[keyFrm-1];
                  else        sprite.obj[props.prop2][props.prop] = props[keyFrm-1];
        } } } } }
      } else if (sprite.charAt(0)=='b' && fNew == sprite.frame) eval(sprite.value);
      if (fNew > tmLn.lastFrame) tmLn.ID = 0;
  } }
}

function MM_timelineGoto(tmLnName, fNew, numGotos) { //v2.0
  //Copyright 1997, 2000 Macromedia, Inc. All rights reserved.
  var i,j,tmLn,props,keyFrm,sprite,numKeyFr,firstKeyFr,lastKeyFr,propNum,theObj;
  if (document.MM_Time == null) MM_initTimelines(); //if *very* 1st time
  tmLn = document.MM_Time[tmLnName];
  if (numGotos != null)
    if (tmLn.gotoCount == null) tmLn.gotoCount = 1;
    else if (tmLn.gotoCount++ >= numGotos) {tmLn.gotoCount=0; return}
  jmpFwd = (fNew > tmLn.curFrame);
  for (i = 0; i < tmLn.length; i++) {
    sprite = (jmpFwd)? tmLn[i] : tmLn[(tmLn.length-1)-i]; //count bkwds if jumping back
    if (sprite.charAt(0) == "s") {
      numKeyFr = sprite.keyFrames.length;
      firstKeyFr = sprite.keyFrames[0];
      lastKeyFr = sprite.keyFrames[numKeyFr - 1];
      if ((jmpFwd && fNew<firstKeyFr) || (!jmpFwd && lastKeyFr<fNew)) continue; //skip if untouchd
      for (keyFrm=1; keyFrm<numKeyFr && fNew>=sprite.keyFrames[keyFrm]; keyFrm++);
      for (j=0; j<sprite.values.length; j++) {
        props = sprite.values[j];
        if (numKeyFr == props.length) propNum = keyFrm-1 //keyframes only
        else propNum = Math.min(Math.max(0,fNew-firstKeyFr),props.length-1); //or keep in legal range
        if (sprite.obj != null) {
          if (props.prop2 == null) sprite.obj[props.prop] = props[propNum];
          else        sprite.obj[props.prop2][props.prop] = props[propNum];
      } }
    } else if (sprite.charAt(0)=='b' && fNew == sprite.frame) eval(sprite.value);
  }
  tmLn.curFrame = fNew;
  if (tmLn.ID == 0) eval('MM_timelinePlay(tmLnName)');
}

function MM_initTimelines() { //v4.0
    //MM_initTimelines() Copyright 1997 Macromedia, Inc. All rights reserved.
    var ns = navigator.appName == "Netscape";
    var ns4 = (ns && parseInt(navigator.appVersion) == 4);
    var ns5 = (ns && parseInt(navigator.appVersion) > 4);
    document.MM_Time = new Array(1);
    document.MM_Time[0] = new Array(1);
    document.MM_Time["Timeline1"] = document.MM_Time[0];
    document.MM_Time[0].MM_Name = "Timeline1";
    document.MM_Time[0].fps = 15;
    document.MM_Time[0][0] = new String("sprite");
    document.MM_Time[0][0].slot = 1;
    if (ns4)
        document.MM_Time[0][0].obj = document["Layer2"];
    else if (ns5)
        document.MM_Time[0][0].obj = document.getElementById("Layer2");
    else
        document.MM_Time[0][0].obj = document.all ? document.all["Layer2"] : null;
    document.MM_Time[0][0].keyFrames = new Array(1, 45);
    document.MM_Time[0][0].values = new Array(4);
    if (ns5)
        document.MM_Time[0][0].values[0] = new Array("625px", "614px", "604px", "593px", "583px", "572px", "562px", "551px", "541px", "530px", "520px", "509px", "498px", "488px", "477px", "467px", "456px", "446px", "435px", "425px", "414px", "404px", "393px", "382px", "372px", "361px", "351px", "340px", "330px", "319px", "309px", "298px", "288px", "277px", "266px", "256px", "245px", "235px", "224px", "214px", "203px", "193px", "182px", "172px", "161px");
    else
        document.MM_Time[0][0].values[0] = new Array(625,614,604,593,583,572,562,551,541,530,520,509,498,488,477,467,456,446,435,425,414,404,393,382,372,361,351,340,330,319,309,298,288,277,266,256,245,235,224,214,203,193,182,172,161);
    document.MM_Time[0][0].values[0].prop = "left";
    if (ns5)
        document.MM_Time[0][0].values[1] = new Array("121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px", "121px");
    else
        document.MM_Time[0][0].values[1] = new Array(121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121);
    document.MM_Time[0][0].values[1].prop = "top";
    if (!ns4) {
        document.MM_Time[0][0].values[0].prop2 = "style";
        document.MM_Time[0][0].values[1].prop2 = "style";
    }
    document.MM_Time[0][0].values[2] = new Array("hidden","visible");
    document.MM_Time[0][0].values[2].prop = "visibility";
    if (!ns4)
        document.MM_Time[0][0].values[2].prop2 = "style";
    document.MM_Time[0][0].values[3] = new Array("1","1");
    document.MM_Time[0][0].values[3].prop = "zIndex";
    if (!ns4)
        document.MM_Time[0][0].values[3].prop2 = "style";
    document.MM_Time[0].lastFrame = 45;
    for (i=0; i<document.MM_Time.length; i++) {
        document.MM_Time[i].ID = null;
        document.MM_Time[i].curFrame = 0;
        document.MM_Time[i].delay = 1000/document.MM_Time[i].fps;
    }
}

//-------- menu ---------
function initialiseMenu(menutype)
{
	if(menutype == 'True')
	{
		document.visibleMenu = null;
		document.checkMenuTimer = null;
		document.closeMenuTimer = null;
		var menu = document.getElementById("mainmenu");
		if (menu != null)
		{
			var objLICollection = menu.getElementsByTagName("TD");
			for(var i = 0; i < objLICollection.length; i++)
			{
				var objLI = objLICollection[i];        
				processNodes(objLI);
			}
			objLICollection = menu.getElementsByTagName("LI");
			for(var i = 0; i < objLICollection.length; i++)
			{
				var objLI = objLICollection[i];        
				processNodes(objLI);
			}
		}
	}
	else
	{
		//nothing required
	}
}

function initialiseAdminMenu(menutype)
{
	if(menutype == 'True')
	{
		document.visibleMenu = null;
		document.checkMenuTimer = null;
		document.closeMenuTimer = null;
		var menu = document.getElementById("adminmainmenu");
		if (menu != null)
		{
			var objLICollection = menu.getElementsByTagName("TD");
			for(var i = 0; i < objLICollection.length; i++)
			{
				var objLI = objLICollection[i];        
				processNodes(objLI);
			}
			objLICollection = menu.getElementsByTagName("LI");
			for(var i = 0; i < objLICollection.length; i++)
			{
				var objLI = objLICollection[i];        
				processNodes(objLI);
			}
		}
	}
	else
	{
		//nothing required
	}
}

function processNodes(objLI)
{
    objLI.onmouseover=hideSubMenu;

		    objLI.onmouseout=menuLostFocus;

    var subMenus = objLI.getElementsByTagName("UL");
    for(var j = 0; j  < subMenus.length; j++)
    {
        var child = subMenus.item(j);
	    if(child.nodeName == "UL")
	    {
		    objLI.onmouseover=showSubMenu;
		    objLI.onmouseout=menuLostFocus;
            if (objLI.nodeName != "TD")
            {
		        for(var k = 0; k < objLI.childNodes.length; k++)
		        {
		            var link = objLI.childNodes.item(k);
			        if(link.nodeName == "A")
			        {
				        link.style.backgroundImage = "url(/wmsimages/arrows.gif)";
				        link.style.backgroundRepeat = "no-repeat";
				        link.style.backgroundPosition = "157px center"; //controls postition of arrow
				        link.style.paddingRight = "12px";
			        }
    		    }
		    }
		    child.onmouseover=menuGotFocus;
	    }
    }
}

function menuGotFocus()
{
	resetCloseTimer();
}

function menuLostFocus()
{
	startCloseTimer();
}

function startCloseTimer()
{
    resetCloseTimer();
    document.closeMenuTimer = window.setInterval("hideAllMenus()", 500);
}

function resetCloseTimer()
{
    if (document.closeMenuTimer != null)
    {
        window.clearInterval(document.closeMenuTimer);
    }
}

function showSubMenu()
{
    showSubMenuCore(this);
}

function isChild(parent, child)
{
    var par = child;
    while (par != null)
    {
        if (parent == par)
        {
            return true;
        }
        par = par.parentNode;
    }
    return false;
}

function showSubMenuCore(objThis)
{
	if (objThis.nodeName == "TD")
	{
		// objThis.style.backgroundImage="url(images/rollover.gif)";
	}
    resetCloseTimer();
    if (document.visibleMenu != null)
    {
        if (document.visibleMenu.owner == objThis | isChild(objThis, document.visibleMenu.owner))
        {
            return;
        }
        else
        {
            if (!isChild(document.visibleMenu.owner, objThis))
            {
                if (objThis.nodeName == "TD")
                {
                    hideMenuCore(document.visibleMenu, true);
                }
                else
                {
                    hideMenuCore(document.visibleMenu, false);
                }
            }
        }
    }
    for(var i = 0; i  < objThis.childNodes.length; i++)
    {
        var menu = objThis.childNodes.item(i);
        if(menu.nodeName == "UL")			
        {
            var style = menu.style;
            style.display = "block";
            if (objThis.nodeName == "TD")
            {
                style.left = getAbsoluteLeft(objThis) + "px"; //controls the x offset of the rollouts
                style.top = (getAbsoluteTop(objThis) + objThis.offsetHeight) + "px";
            }
            else
            {
                style.left = objThis.offsetWidth + "px";
                style.top = (objThis.offsetTop -1) + "px";
            }
            menu.parentMenu = document.visibleMenu;
            document.visibleMenu = menu;
            document.visibleMenu.has_focus = 1;
            menu.owner = objThis;
            if (document.checkMenuTimer != null)
            {
                window.clearInterval(document.checkMenuTimer);
                document.checkMenuTimer = null;
            }
            document.checkMenuTimer = window.setInterval("checkMenu()", 3000);
            
            resetCloseTimer();
            break;            
        }		
    }	
}

function checkMenu()
{
    if (document.visibleMenu != null)
    {
        if (!(document.visibleMenu.has_focus == 1))
        {
            hideMenuCore(document.visibleMenu, true);
        }
    }
}

function hideAllMenus()
{
    resetCloseTimer();
    hideMenuCore(document.visibleMenu, true);
}

function hideSubMenu()
{
    hideMenuCore(document.visibleMenu, false);
}


function hideMenuCore(menu, hideAll)
{
    if (hideAll & document.checkMenuTimer != null)
    {
        window.clearInterval(document.checkMenuTimer);
        document.checkMenuTimer = null;
    }
    if (hideAll)
    {
		var p = menu;
		while (p != null)
		{
			if (p.nodeName == "TD")
			{
				// p.style.backgroundImage="url(images/button.gif)";
				break;
			}
			p = p.parentNode;
		}
        while (menu != null)
        {
            menu.style.display = "none";
            menu = getParentMenu(menu);
        }
        document.visibleMenu = null;
    }
    else
    {
        if (menu != null)
        {
			if (menu.nodeName == "TD")
			{
				// menu.style.backgroundImage="url(images/button.gif)";
			}
            menu.style.display = "none";
            document.visibleMenu = menu.parentMenu;
        }
    }
}

function getParentMenu(menu)
{
    var element = menu.parentNode;
    while (element != null)
    {
        if (element.nodeName == "TD")
        {
            return null;
        }
        if (element.nodeName == "UL")
        {
            return element;
        }
        element = element.parentNode;
    }
    return null;
}

function getAbsoluteLeft(element)
{
	if (element == null)
	{
		return 0;
	}
	var pos;
	if (element.offsetParent == null)
	{
		pos = 0;
	}
	else
	{
		pos = 0; //element.offsetParent.clientLeft;
	}
	return pos + element.offsetLeft + getAbsoluteLeft(element.offsetParent);
}

function getAbsoluteTop(element)
{
	if (element == null)
	{
		return 0;
	}
	var pos;
	if (element.offsetParent == null)
	{
		pos = 0;
	}
	else
	{
		pos = 0; //element.offsetParent.clientTop;
	}
	return pos + element.offsetTop + getAbsoluteTop(element.offsetParent);
}

function showStandard(){
	var layerToShow = document.getElementById("StandardPanel");
	var layerToHide = document.getElementById("AdvancedPanel");


    layerToShow.style.display = 'inline';
    layerToHide.style.display  = 'none';
}


function showAdvanced(){
	var layerToShow = document.getElementById("AdvancedPanel");
	var layerToHide = document.getElementById("StandardPanel");


    layerToShow.style.display = 'inline';
    layerToHide.style.display  = 'none';
}

function openNewWindow(sURL, sName, iWidth, iHeight, bResizable, bScrollbars)
{
	var iTop  = (screen.height - iHeight) / 2 ;
	var iLeft = (screen.width  - iWidth) / 2 ;
	
	var sOptions = "toolbar=no" ;
	sOptions += ",width=" + iWidth ; 
	sOptions += ",height=" + iHeight ;
	sOptions += ",resizable="  + (bResizable  ? "yes" : "no") ;
	sOptions += ",scrollbars=" + (bScrollbars ? "yes" : "no") ;
	sOptions += ",left=" + iLeft ;
	sOptions += ",top=" + iTop ;
	
	var oWindow = window.open(sURL, sName, sOptions)
	oWindow.focus();
	
	return oWindow ;
}

// --- upload images
function OpenImageUpload(ownerWindow, strImageElement, strElementName, strImageFolder, parameters)
{
	var oWindow = dialog("/components/imageuploader.aspx?ImageElement="+strImageElement+"&ElementName="+strElementName+"&ImageLocation="+strImageFolder+"&parameters="+parameters, 'UploadWindow', "width=320,height=200,resizable=0", false);
	/*var oWindow = openNewWindow("/components/imageuploader.aspx?ImageElement="+strImageElement+"&ElementName="+strElementName+"&ImageLocation="+strImageFolder+"&parameters="+parameters, 'UploadWindow', 300, 150, false, false);*/
	oWindow.mainWindow=ownerWindow;
	oWindow.opener=ownerWindow;
}
function cloneElement(elementID)
{
	var imgIndex = document.imageUploadIndex;
	var element = document.getElementById(elementID);
	if (element != null)
	{
		var elements = document.getElementsByTagName(element.nodeName);
		for (var i = 0; i < elements.length; i++)
		{
			if (elementID != null && elementID != '' && elements[i].id == elementID)
			{
				element = elements[i];
				break;
			}
		}
		
		if (element != null)
		{
			if (imgIndex == null)
			{
				imgIndex = 0;
			}
			// the element to be cloned is hidden, 0 is reserved for it
			imgIndex++;
			var clone = cloneOne(element, imgIndex);
			element.parentNode.parentNode.appendChild(clone);
			document.imageUploadIndex = imgIndex;
			return clone;
		}
	}
	return null;
}
function cloneOne(element, index)
{
	var clone = document.createElement(element.nodeName);
	var oldText = "btnDeleteImage')";
	var oldText2 = "btnDeleteImage|productImage|0')";
	var newText = "btnDeleteImage|productImage|" + index + "')";
	var newHtml = element.innerHTML.replace(oldText, newText).replace(oldText, newText).replace(oldText2, newText).replace(oldText2, newText);
	clone.innerHTML = newHtml;
	clone.controlIndex = index;
	var oAttrColl = element.attributes;
	for (i = 0; i < oAttrColl.length; i++)
    {
        oAttr = oAttrColl.item(i);
        bSpecified = oAttr.specified;
        sName = oAttr.nodeName;
        vValue = oAttr.nodeValue;
        if (bSpecified)
        {
			clone.setAttribute(sName, vValue);
		}
    }
    clone.style.cssText = element.style.cssText;
	clone.style.display = 'block';
	
	return clone;
}
function setImage(file, imageUrl, elementID, imageElementID, parameters){
	// parameters: width|height|delete_image_button_id|index_if_multiple_controls_used
	var width = null;
	var height = null;
	var deleteBtnID = null;
	var controlIndex = null;
	var parentID = null;
	if (parameters != null)
	{
		var tmp = parameters.split("|");
		if (tmp.length > 0)
		{
			width = tmp[0];
		}
		if (tmp.length > 1)
		{
			height = tmp[1];
		}
		if (tmp.length > 2)
		{
			deleteBtnID = tmp[2];
		}
		if (tmp.length > 3)
		{
			parentID = tmp[3];
		}
		if (tmp.length > 4)
		{
			controlIndex = tmp[4];
			controlIndex = parseInt(controlIndex);
		}
	}
	
	var root;
	if (parentID == null || parentID == '' || controlIndex != null)
	{
		root = document;
	}
	else
	{
		root = document.getElementById(parentID);
	}

	var elements;
	var fields = new Array();
	var btns = new Array();
	var index = 0;
	elements = root.getElementsByTagName('input');
	for (var i = 0; i < elements.length; i++)
	{
		if (elementID != null && elementID != '' && elements[i].id == elementID)
		{
			fields[index] = elements[i];
			index++;
		}
	}
	index = 0;
	for (var i = 0; i < elements.length; i++)
	{
		if (deleteBtnID != null && deleteBtnID != '' && elements[i].id == deleteBtnID)
		{
			btns[index] = elements[i];
			index++;
		}
	}
	elements = root.getElementsByTagName('img');
	var images = new Array();
	index = 0;
	for (var i = 0; i < elements.length; i++)
	{
		if (imageElementID != null && imageElementID != '' && elements[i].id == imageElementID)
		{
			images[index] = elements[i];
			index++;
		}
	}
	
	var objelement = null;
    var objimageElement = null;
	var deleteBtn = null;
    if (controlIndex != null)
    {
		if (fields.length > controlIndex)
		{
			objelement = fields[controlIndex];
		}
		if (images.length > controlIndex)
		{
			objimageElement = images[controlIndex];
		}
		if (btns.length > controlIndex)
		{
			deleteBtn = btns[controlIndex];
		}
    }
    else
    {
		if (fields.length > 0)
		{
			objelement = fields[0];
		}
		if (images.length > 0)
		{
			objimageElement = images[0];
		}
		if (btns.length > 0)
		{
			deleteBtn = btns[0];
		}
    }
    
	if (objelement != null)
    {
		objelement.value=file;
	}
	if (objimageElement != null)
	{
		objimageElement.src=imageUrl;
	}
    if (deleteBtn != null)
	{
		deleteBtn.disabled = file == null || file == '';
	}
    /*if (objimageElement != null)
	{
		if (objimageElement.onimagechanged != null) 
		{
			objimageElement.parentNode.onimagechanged(objimageElement, true, controlIndex);
		}
	}*/
	if (parentID != null && parentID != '')
	{
		var pr = document.getElementById(parentID);
		if (pr != null && pr.onimagechanged != null)
		{
			pr.onimagechanged(pr, true, controlIndex);
		}
	}
}
function OpenImageUploadPublic(strImageSrcName, strElementName, strImagePath, strProdID)
{
	var oWindow = openNewWindow("/imageUpload.aspx?imageLocation="+strImagePath+"&ElementName="+strElementName+"&ImagePath="+strImageSrcName+"&prodID="+strProdID+"&serial=3r8g89a2d-gjmvb98jf", 'UploadWindow2', 300, 150, false, false);
}

// --------- for textarea control --------
// Keep user from entering more than maxLength characters
function doKeypress(control){
    maxLength = control.attributes["maxLength"].value;
    value = control.value;
     if(maxLength && value.length > maxLength-1){
          event.returnValue = false;
          maxLength = parseInt(maxLength);
     }
}
// Cancel default behavior
function doBeforePaste(control){
    maxLength = control.attributes["maxLength"].value;
     if(maxLength)
     {
          event.returnValue = false;
     }
}
// Cancel default behavior and create a new paste routine
function doPaste(control){
    maxLength = control.attributes["maxLength"].value;
    value = control.value;
     if(maxLength){
          event.returnValue = false;
          maxLength = parseInt(maxLength);
          var oTR = control.document.selection.createRange();
          var iInsertLength = maxLength - value.length + oTR.text.length;
          var sData = window.clipboardData.getData("Text").substr(0,iInsertLength);
          oTR.text = sData;
     }
}
function ValidContent()
{
    if(MyReplace(document.form1.frmtitle.value, ' ', '') == '')
    {
        alert('You must provide a title for this content');
        document.form1.frmtitle.focus();
        return false;
    }
    else
    {
        showLoad();
        document.form1.action='';
        document.form1.target='';
        return true;
    }
}
// -------- end textarea ----------

// -------- modal window ----------
String.prototype.isArgument=function()
{
	return /^([a-zA-Z]){1,}=([0-9]){1,}$/.test(this);
}

/*
call this function just work like window.open(url,name,feature);
however, for IE5.0+, it will open a showModelessDialog window;
and For Gecko(Mozilla or Netscape), the child window will stay on top focus untill user close it.
programmed by hedger
hedger@yahoo-inc.com
*/

function dialog(url,name,feature,isModal)
{
 if(url==null){return false;}
 url = url
 if(name==null){name=""}
 if(feature==null){feature=""};
 if(window.showModelessDialog)
 {
  	var WindowFeature = new Object();
	WindowFeature["width"] = 400;
	WindowFeature["height"]  =400;
	WindowFeature["left"]  = "";
	WindowFeature["top"]  =  "";
	WindowFeature["resizable"]  = "";

	if(feature !=null && feature!="")
	{
      feature = ( feature.toLowerCase()).split(",");
	
      for(var i=0;i< feature.length;i++)
		{
          if( feature[i].isArgument())
			{
               var featureName = feature[i].split("=")[0];
			   var featureValue = feature[i].split("=")[1];
			  
			   if(WindowFeature[featureName]!=null){WindowFeature[featureName] = featureValue; }
			}
		}
	}
 
  if(WindowFeature["resizable"]==1 || WindowFeature["resizable"]=="1" || WindowFeature["resizable"].toString().toLowerCase()=="yes"){WindowFeature["resizable"] = "resizable:1;minimize:1;maximize:1;"}
  if(WindowFeature["left"]!=""){WindowFeature["left"] ="dialogLeft:" +  WindowFeature["left"] +"px;";}
  if(WindowFeature["top"]!=""){WindowFeature["top"] ="dialogTop:" +  WindowFeature["Top"] +"px;"; }
  if(window.ModelessDialog ==null){window.ModelessDialog = new Object() ; };
  if(name!="")
  {
   if(window.ModelessDialog[name]!=null && !window.ModelessDialog[name].closed )
   {
     window.ModelessDialog[name].focus();
	 return window.ModelessDialog[name];
   }
  }
	var F = WindowFeature["left"] +WindowFeature["top"] +  "dialogWidth:"+WindowFeature["width"] +" px;dialogHeight:"+WindowFeature["height"]+"px;center:1;help:0;" + WindowFeature["resizable"] +"status:0;unadorned:0;edge: raised; ;border:thick;"
	if(isModal)
	{
		window.showModalDialog(url,self,F);
		return false;
	}
	else
	{
		window.ModelessDialog[name] = window.showModelessDialog(url,self,F);
		return window.ModelessDialog[name];
	}	
 }
 else
 {
   if(document.getBoxObjectFor)
   {
	

	 if(isModal)
	 {		 
		 var Modal = window.open(url,name,"modal=1," + feature);
		 var ModalFocus = function()
		 {
			if(!Modal.closed){Modal.focus();}
			else{Modal =null;window.removeEventListener(ModalFocus,"focus");ModalFocus = null; };					
		 }
		 window.addEventListener( "focus",ModalFocus, false ); 
		 return false;
	 }
	 else
	 {
		return window.open(url,name,"modal=1," + feature);
	 }	 
   }
   else
   { 
     return window.open(url,name,feature);
   }
   //
 }
 return null;
}
   
function modal(url,feature)
{
	dialog(url,"",feature,true);
	return false;
}
//-------- end ------------

function PopulateForm(arrElements)
{
	PopulateForm2(arrElements, true);
}

function PopulateForm2(arrElements, loadChildren)
{
	for (i=0; i<arrElements.length; i++)
	{
		//index of js arrays not always sequential
		if(arrElements[i] != null)
		{
			var elementObj = document.getElementById(arrElements[i][0]);
			if(elementObj!=null)
			{
				if (elementObj.nodeName.toUpperCase() == "INPUT" && elementObj.type.toUpperCase() == "RADIO")
				{
					elementObj.checked = elementObj.value == arrElements[i][1];
				}
				else if (elementObj.nodeName.toUpperCase() == "INPUT" && elementObj.type.toUpperCase() == "CHECKBOX")
				{
					elementObj.checked = arrElements[i][1].toUpperCase() == "TRUE";
				}
				else if (elementObj.nodeName.toUpperCase() == "INPUT" && elementObj.type.toUpperCase() == "HIDDEN")
				{
					elementObj.value=arrElements[i][1];
					var img = document.getElementById(arrElements[i][0] + '_src');
					if (img != null)
					{
						if (arrElements[i][1] == null || arrElements[i][1] == '')
						{
							img.src = '/wmsimages/no_image_supplied.jpg';
						}
						else
						{
							img.src = arrElements[i][1];
						}
					}
				}
				else
				{
					elementObj.value=arrElements[i][1];
				}
				if (loadChildren && elementObj.onchange != null)
				{
					elementObj.onchange();
					elementObj.upldateCallback = function(element)
					{
						element.upldateCallback = null;
						PopulateForm2(arrElements, false);
					}
				}
				if(arrElements[i][2]=='False')
				{
					elementObj.disabled = true;					
					elementObj.Title="Editing this field is not allowed.";
				}
			}
		}
	}
}

// ------------------
function trackChanges(parentTable, change, childTable, update)
{
	if (change != null && update != null)
	{
		var prev = change.onchange;
		change.onchange = function() 
		{
			var xmlhttp =  new XMLHttpRequest();
			xmlhttp.open('POST', '/options.aspx', true);
			xmlhttp.onreadystatechange = function()
			{
				if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
				{
					if (xmlhttp.status == 200)
					{
						updateOptions(xmlhttp.responseXML, update);
					}
					if (change.upldateCallback != null)
					{
						change.upldateCallback(change);
					}
				}
			}
			xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			var data = 'table=' + childTable + '&parentTable=' + parentTable + '&parentValue=' + change.value;
			xmlhttp.send(data);
			if (prev != null)
			{
				prev();
			}
		}
	}
}

function updateOptions(xml, el)
{
	var special = null;
	if (el.options.length > 0 && (el.options[0].value == null || el.options[0].value == ""))
	{
		special = el.options[0];
	}
	el.innerHTML = "";
	while (el.options.length > 0)
	{
		el.remove(0);
	}
	if (special != null)
	{
		el.options.add(special);
	}
	var opts =  xml.getElementsByTagName("option");
	for (var j = 0; j < opts.length; j++)
	{
		var option = document.createElement("OPTION");
		el.options.add(option);
		if (opts[j].firstChild == null)
		{
			option.appendChild(document.createTextNode(opts[j].text));
			option.value = opts[j].getAttribute("value");
		}
		else
		{
			option.appendChild(document.createTextNode(opts[j].firstChild.nodeValue));
			option.value = opts[j].getAttribute("value");
		}
	}
	if (el.onchange != null)
	{
		el.onchange();
	}
}

// for MLC 'Understanding Series'

var webcastWindowObject;
function openWindow(location, width, height) {
webcastWindowObject = window.open(location, 'webcast', 'width ='+width+',height='+ height+',toolbar=no,location=no,scrolling=none,directories=no,status=no,scrollbars=no,menubar=no,resizable=yes,vAlign=top,align=center');
if (webcastWindowObject.opener == null) webcastWindowObject.opener = window;
webcastWindowObject.opener.name = "opener";
}
// end MLC 'Understanding Series'

