IE4 = document.all;
var helpTimeout = null;
var helpToggle = false;
var oXmlHttpThreadArray = null;
function popup(url, width, height) 
{
	var pWin = window.open(url,"NewWin","height=" + height + ",width=" + width + ",location=no,toolbar=no,scrollbars=yes,resizable=yes,menubar=no");	
    pWin.focus();
}

function limitLength( control, length )
{
	if( control.value.length > length )
	{
		control.value = control.value.substr( 0, length );
	}
}

function newConfirm(title,mess,icon,defbut,mods) {
   if (IE4) {
      icon = (icon==0) ? 0 : 2;
      defbut = (defbut==0) ? 0 : 1;
      retVal = makeMsgBox(title,mess,icon,4,defbut,mods);
      retVal = (retVal==6);
   }
   else {
      retVal = confirm(mess);
   }
   return retVal;
}

function doZxmlHttpGetRequest(id, type, url, func) 
{
	if (oXmlHttpThreadArray == null) oXmlHttpThreadArray = new zXmlHttpThreadArray("oXmlHttpThreadArray");
	var oXMLHTTPthread = new zXmlHttpThread(id, type);//XMLHTTP CREATED
	oXMLHTTPthread.register(oXmlHttpThreadArray);//XMLHTTP REGISTERED TO GLOBAL THREAD COLLECTION
	var oXMLHTTP = oXMLHTTPthread.getRequest();
	if (!oXMLHTTP) return false;//XMLHTTP NOT SUPPORTED BY BROWSER
	// Prepare the XMLHTTP object for a HTTP POST to our validation page
	oXMLHTTP.onreadystatechange = function()
	{
		document.body.style.cursor='wait';
		if (oXMLHTTP.readyState != 4) return;
		document.body.style.cursor='auto';
		if (oXMLHTTP.status == 200)
		{
			func(oXMLHTTP.responseText);
			oXmlHttpThreadArray.removeThread(id);
		}
		else
		{
			//code to handle bad data or no data
		}
	};
	// Prepare the XMLHTTP object for a HTTP POST to our validation page
	oXMLHTTP.open("GET", url, true);
	oXMLHTTP.send("");
	return true;
}

function doZxmlHttpPostRequest(id, type, url, content, func) 
{
	if (oXmlHttpThreadArray == null) oXmlHttpThreadArray = new zXmlHttpThreadArray("oXmlHttpThreadArray");
	var oXMLHTTPthread = new zXmlHttpThread(id, type);//XMLHTTP CREATED
	oXMLHTTPthread.register(oXmlHttpThreadArray);//XMLHTTP REGISTERED TO GLOBAL THREAD COLLECTION
	var oXMLHTTP = oXMLHTTPthread.getRequest();
	if (!oXMLHTTP) return false;//XMLHTTP NOT SUPPORTED BY BROWSER
	// Prepare the XMLHTTP object for a HTTP POST to our ajaxhandler
	oXMLHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oXMLHTTP.onreadystatechange = function()
	{
		document.body.style.cursor='wait';
		if (oXMLHTTP.readyState != 4) return;
		document.body.style.cursor='auto';
		if (oXMLHTTP.status == 200)
		{
			func(oXMLHTTP.responseText);
			oXmlHttpThreadArray.removeThread(id);
		}
		else
		{
			//code to handle bad data or no data
		}
	};
	// Prepare the XMLHTTP object for a HTTP POST to our validation page
	oXMLHTTP.open("POST", url, true);
	oXMLHTTP.send(content);
	return true;
}

function validatename(id, name, url, textbox)
{
	if (name == "") return false;
	doZxmlHttpGetRequest("validatename", "validatename", 
		url + "validatename.ashx?id=" + id + "&name=" + name, 
		function(response)
		{
			if (response == "exist")
			{
				alert("Sorry, the user name: " + name + "\nis already in use.");
				if (textbox)
				{
					textbox.value = '';
					textbox.focus();
				}
			}
		}
	);
}

function validateemail(contactId, supplierId, email, url, textbox)
{
	if (email == "") return false;
	doZxmlHttpGetRequest("validateemail", "validateemail", 
		url + "validateemail.ashx?contactId=" + contactId + "&supplierId=" + supplierId + "&email=" + email, 
		function(response)
		{
			if (response == "exist")
			{
				alert("Sorry - the email address is already in use.");
				if (textbox)
				{
					textbox.value = '';
					textbox.focus();
				}
			}
		}
	);
}

function validateduns(duns, url, supplierId, textbox) 
{
	if (duns == "") return false;
	doZxmlHttpGetRequest("validateduns", "validateduns", 
		url + "validateduns.ashx?duns=" + duns + "&supplierId=" + supplierId, 
		function(response)
		{
			if (response == "exist")
			{
				alert("Sorry - the DUN and Bradstreet Number: " + duns + "\nis already in use.");
				if (textbox)
				{
					textbox.value = '';
					textbox.focus();
				}
			}
		}
	);
}

function getTop(o, sBreakAt) 
{
	var iTop = 0;
	if (o.offsetParent) {
		if(sBreakAt && (oParent = getElement(sBreakAt))) 
		{
			while (o.offsetParent && (o.offsetParent != oParent)){
				iTop += o.offsetTop;o = o.offsetParent;
			}
		}
		else
		{	
			while (o.offsetParent){
				iTop += o.offsetTop;o = o.offsetParent;
			}
		}
		
	} else if (o.y) {
		iTop += o.y;
	}
	return iTop;
}

function getLeft(o) 
{
	var iLeft = 0;
	if (o.offsetParent) {
		while (o.offsetParent) {
			iLeft += o.offsetLeft;o = o.offsetParent;
		}
	} else if (o.x) {
		iLeft += o.x;
	}
	return iLeft;
}

function setEvent(oElement, sEventType, fEventHandler) 
{
	if (typeof(oElement) == 'string')
		oElement = getElement(oElement);
	if(window.attachEvent) {
		oElement.attachEvent('on'+sEventType, fEventHandler);
	} else if (window.addEventListener) {
		oElement.addEventListener(sEventType, fEventHandler, false);
	} else {
		
		if(oElement['on'+sEventType]) {		
			oldFunc = oElement['on'+sEventType];
			oElement['on'+sEventType] = function() {
				oldFunc;
				fEventHandler;
			}
		} else {
			oElement['on'+sEventType] = fEventHandler;
		}
	}
}

function getElementsByTagAndClass(a_sTagName, a_sClassName) 
{
	var aReturnElements = [];
	if(document.getElementsByTagName) {
		var aAllTags = document.getElementsByTagName(a_sTagName);
		for(j = 0; j < aAllTags.length; j++) {
			var oCurrentTag = aAllTags[j];
			if(oCurrentTag.className == a_sClassName) {
				aReturnElements[aReturnElements.length] = oCurrentTag;
			}
		}
	}
	return aReturnElements;
}

function getElement(a_sElementId) 
{
	if (typeof(a_sElementId) != "string")
		return a_sElementId;
	var oElement = (document.getElementById) ? document.getElementById(a_sElementId) : (document.all) ? document.all[a_sElementId] : null;
	if(oElement == null) {	
		for(i = 0; i < document.forms.length; i++) {
			var form = document.forms[i];
			if(form.name == a_sElementId) {
				return form;
			} else {
				for(j = 0; j < form.elements.length; j++) {
					element = form.elements[j];
					if(element.name == a_sElementId) {
						return element;
					}
				}
			}
		}
		if(document.images[a_sElementId]) {
			return document.images[a_sElementId];
		} else if(document.anchors[a_sElementId]) {
			return document.anchors[a_sElementId];
		} else if (document.layers) { 
		}
	}
	return oElement;
}

function showFormHelp(sHeader, sInfo)
{
	var oHelp = getElement('formHelp');
	var oHelpHeader = getElement('formHelpHeader');
	var oHelpText = getElement('formHelpInfo');
	
	if(sHeader && sInfo)
	{
		oHelpHeader.innerHTML = sHeader;
		oHelpText.innerHTML = sInfo;
		oHelp.style.display = 'block';
	}
	else
		oHelp.style.display = 'none';
}

function hideFormHelp(thisElement)
{
	var oHelp = getElement('formHelp');
	var oHelpToggle = getElement('formHelpMini');
	
	oHelpToggle.innerHTML = '&nbsp;';
	oHelp.className = 'formHelpOff';
	moveHelp(thisElement, oHelp);
}

function toggleFormHelp(thisElement)
{
	var oHelp = getElement('formHelp');
	var oHelpToggle = getElement('formHelpMini');
	if (oHelp.className == 'formHelpOff')
	{
		oHelp.className = 'formHelpOn';
		oHelpToggle.innerHTML = '&ndash;';
		helpToggle = true;
		if (thisElement != null)
			moveHelp(thisElement, oHelp);
	}
	else
	{
		hideFormHelp(thisElement);
		helpToggle = false;
	}
	clearTimeout(helpTimeout);
}

function setFormHelp(thisElement)
{
	if (typeof(thisElement) == 'string')
		thisElement = getElement(thisElement);
	var id = thisElement.id || thisElement.name;
	var oHelp = getElement('formHelp');
	var oHelpToggle = getElement('formHelpMini');
	
	oHelpToggle.href = "javascript:toggleFormHelp(\'" + id + "\');";
	if (id.indexOf('Link') != -1 && !helpToggle)
		toggleFormHelp(id);
	showFormHelp(helptips[id + 'Title'], helptips[id + 'Text']);
	if (helpToggle)
	{
		oHelp.className = 'formHelpOn';
		oHelpToggle.innerHTML = '&ndash;';
	}
	moveHelp(thisElement, oHelp);
	clearTimeout(helpTimeout);
	helpTimeout = setTimeout("hideFormHelp(\'" + id + "\')", Math.pow(oHelp.offsetHeight - 15,1.1) * 100 );
}

function moveHelp(thisElement, oHelp)
{
	if (typeof(thisElement) == 'string')
		thisElement = getElement(thisElement);
	if (typeof(oHelp) == 'string')
		oHelp = getElement(oHelp);
	var y = getTop(thisElement);
	var x = getLeft(thisElement);
	var id = thisElement.id || thisElement.name;
	var anchor = helptips[id + 'Anchor'];
	var theme = getElement("ctl00_content_tooltip_themeName").value;
	var backgroundStyle = "url(" + theme + "/images/bg_help_box_YLOCXLOC.gif) no-repeat YALIGN XALIGN";
	
	if(isNaN(helptips[id + '_OffsetX']) == false)
		x += parseInt(helptips[id + '_OffsetX']);
	if(isNaN(helptips[id + '_OffsetY']) == false)
		y += parseInt(helptips[id + '_OffsetY']);
	if(anchor) {
		if( anchor.indexOf('top') >= 0 )
		{
			oHelp.style.top = (y - oHelp.offsetHeight) + "px";
			backgroundStyle = backgroundStyle.replace(/YLOC/,'b');
			backgroundStyle = backgroundStyle.replace(/YALIGN/,'bottom');
		}
		else if( anchor.indexOf('middle') >= 0 )
		{
			oHelp.style.top = (y + (thisElement.offsetHeight/2) - (oHelp.offsetHeight/2)) + "px";
			backgroundStyle = backgroundStyle.replace(/YLOC/,'m');
			backgroundStyle = backgroundStyle.replace(/YALIGN/,'center');
		}
		else if( anchor.indexOf('bottom') >= 0 )
		{
			oHelp.style.top = (y + thisElement.offsetHeight) + "px";
			backgroundStyle = backgroundStyle.replace(/YLOC/,'t');
			backgroundStyle = backgroundStyle.replace(/YALIGN/,'top');
		}
		if( anchor.indexOf('left') >= 0 )
		{
			oHelp.style.left = (x - oHelp.offsetWidth) + "px";
			backgroundStyle = backgroundStyle.replace(/XLOC/,'r');
			backgroundStyle = backgroundStyle.replace(/XALIGN/,'right');
		}
		else if( anchor.indexOf('center') >= 0 )
		{
			oHelp.style.left = (x + (thisElement.offsetWidth/2) - (oHelp.offsetWidth/2)) + "px";
			backgroundStyle = backgroundStyle.replace(/XLOC/,'c');
			backgroundStyle = backgroundStyle.replace(/XALIGN/,'center');
		}
		else if( anchor.indexOf('right') >= 0 )
		{
			oHelp.style.left = (x + thisElement.offsetWidth) + "px";
			backgroundStyle = backgroundStyle.replace(/XLOC/,'l');
			backgroundStyle = backgroundStyle.replace(/XALIGN/,'left');
		}
	}
	else
	{
		oHelp.style.top = (y + (thisElement.offsetHeight/2) - (oHelp.offsetHeight/2)) + "px";
		backgroundStyle = backgroundStyle.replace(/YLOC/,'m');
		backgroundStyle = backgroundStyle.replace(/YALIGN/,'center');
		oHelp.style.left = (x + thisElement.offsetWidth) + "px";
		backgroundStyle = backgroundStyle.replace(/XLOC/,'l');
		backgroundStyle = backgroundStyle.replace(/XALIGN/,'left');
	}
	oHelp.style.background = backgroundStyle;
}

function attachHelpTexts()
{	
	for(var i = 0; i < document.forms[0].elements.length; i++) {
		if (document.forms[0].elements[i].type == "button" || document.forms[0].elements[i].type == "submit")
		{
			var element = document.forms[0].elements[i];
			element.onmouseover = function (){setFormHelp(this);};
			element.onmouseout = function (){setFormHelp(this);};
		}
		else if (document.forms[0].elements[i].getAttribute('id')) 
		{
			var element = document.forms[0].elements[i];
			element.onfocus = function (){setFormHelp(this);};
		}
	}
}

function toggleElementDisplay(elementRef, newdisplay)
{
	var oElement = getElement(elementRef);
	if (newdisplay == null) newdisplay = "";
	if (oElement.style.display == 'none')
		oElement.style.display = newdisplay;
	else
		oElement.style.display = 'none';
}

function delayElementDisplay(id, newdisplay, milliseconds)
{
	var toggleFuncString = "toggleElementDisplay('" + id + "','" + newdisplay + "')";
	setTimeout( toggleFuncString, milliseconds);
}

function toggleElementOverflow(id, newoverflow)
{
	var oElement = getElement(id);
	if (oElement.style.overflow == 'auto')
		oElement.style.overflow = newoverflow;
	else
		oElement.style.overflow = 'auto';
}

function checkElementDisplay()
{
	var argsArray = checkElementDisplay.arguments;
	var isDisplayed = true;
	var errmsg = "";
	for ( var i = 0; i < argsArray.length; i++ )
	{
		var oElement = getElement( argsArray[i] );
		if ( oElement )
			isDisplayed = ( isDisplayed && oElement.style.display != 'none' );
		else
			errmsg += "Developer Error: \"" +  argsArray[i]+ "\" is not an object.\n";
	}
	if ( errmsg.length > 0 )
		alert(errmsg + "Please Contact Technical Support.");
	return isDisplayed;
}

function getImgSrcName( oElement )
{
	if( typeof(oElement) == 'string' )
		oElement = getElement( oElement );
	var imgSrc = oElement.src;
	var imgSrcArray = imgSrc.split("/");
	return imgSrcArray[ imgSrcArray.length - 1 ];
}

function btnImgSwap(thisElement, str)
{
	thisElement.src = thisElement.src.replace(/rollup|rolldown|rollover/ , str);
}

function plusMinusImgSwap(oElement)
{
	if( typeof(oElement) == 'string')
		oElement = getElement(oElement);
	var str = "plus";
	if( oElement.src.search("minus") == -1 )
		str = 'minus';
	oElement.src = oElement.src.replace(/plus|minus/ , str);
	return str;
}

//Sidebar
function sidebarToggle( oElement, hiddenElement )
{
	if (typeof(hiddenElement) == 'string')
		hiddenElement = getElement(hiddenElement);
	if (typeof(oElement) == 'string')
		oElement = getElement(oElement);
	if(getElement("sidebarCell").style.display == "none") 
	{
		oElement.src = oElement.src.replace( /sidebarclosed/, "sidebaropen");
		getElement("sidebarCell").style.display = "";
		hiddenElement.value = "open";
	}
	else
	{
		oElement.src = oElement.src.replace( /sidebaropen/, "sidebarclosed");
		getElement("sidebarCell").style.display = "none";
		hiddenElement.value = "closed";
	}
}
function toggleSidebarPanel( oElement, elementPrefix )
{
	if (typeof(oElement) == 'string')
		oElement = getElement(oElement);
	btnElement = getElement( elementPrefix + 'Btn');
	hiddenElement = getElement( elementPrefix );
	if( oElement.style.display == "none" ) 
	{
		btnElement.src = btnElement.src.replace( /panelclosed/, "panelopen");
		hiddenElement.value = "open";
		oElement.style.display = "";
	} else {
		btnElement.src = btnElement.src.replace( /panelopen/, "panelclosed");
		hiddenElement.value = "closed";
		oElement.style.display = "none";
	}
	return false;
}
function getNextSibling(startBrother){
  endBrother=startBrother.nextSibling;
  while(endBrother.nodeType!=1){
    endBrother = endBrother.nextSibling;
  }
  return endBrother;
}
document.write('<link rel="stylesheet" type="text/css" media="print" href="../controls/print.css" />');

/*
**  Sets the caret (cursor) position of the specified text field.
**  Valid positions are 0-oField.length.
*/
function setCaretPosition(oField, iCaretPos)
{
	if (document.selection)// IE Support
	{
		oField.focus();
		var oSel = document.selection.createRange();
		oSel.moveStart('character', -oField.value.length);
		oSel.moveEnd('character', -oField.value.length);
		// Move selection start and end to desired position
		oSel.moveStart('character', iCaretPos);
		oSel.moveEnd('character', 0);
		oSel.select();
	}
	else if (oField.selectionStart || oField.selectionStart == '0')//Firefox support
	{
		oField.selectionStart = iCaretPos;
		oField.selectionEnd = iCaretPos;
		oField.focus();
	}
}

function selectAll(oField)
{
	if (document.selection)// IE Support
	{
		oField.focus();
		var oSel = document.selection.createRange();
		oSel.expand("textedit");
		oSel.select();
	}
	else if (oField.selectionStart || oField.selectionStart == '0')//Firefox support
	{
		oField.selectionStart = 0;
		oField.selectionEnd = oField.value.length;
		oField.focus();
	}
}

function selectCaretToEnd(oField, iCaretPos)
{
	if (document.selection)// IE Support
	{
		oField.focus();
		var oSel = document.selection.createRange();
		oSel.expand("textedit");
		oSel.moveStart('character', iCaretPos);
		oSel.select();
	}
	else if (oField.selectionStart || oField.selectionStart == '0')//Firefox support
	{
		oField.selectionStart = iCaretPos;
		oField.selectionEnd = oField.value.length;
		oField.focus();
	}
}

function selectStartToCaret(oField, iCaretPos)
{
	if (document.selection)// IE Support
	{
		oField.focus();
		var oSel = document.selection.createRange();
		oSel.expand("textedit");
		oSel.moveEnd('character', -(oField.value.length - iCaretPos));
		oSel.select();
	}
	else if (oField.selectionStart || oField.selectionStart == '0')//Firefox support
	{
		oField.selectionStart = 0;
		oField.selectionEnd = iCaretPos;
		oField.focus();
	}
}