// Fix the .toFixed bug for rounding
function Stretch(Q,L,c){var S=Q;if(c.length>0)while(S.length<L){S=c+S}return S}
function StrU(X,M,N){var T,S=new String(Math.round(X*Number("1e"+N)));if(S.search && S.search(/\D/)!=-1){return ''+X};with(new String(Stretch(S,M+N,'0')))return substring(0,T=(length-N))+'.'+substring(T);}
function Sign(X){return X<0 ? '-':'';}
function StrS(X,M,N){return Sign(X)+StrU(Math.abs(X),M,N)}
Number.prototype.toFixed=new Function('n','return StrS(this,1,n)')

function initwindow(){extL();addE();}

function extL(){if(!document.getElementsByTagName)return;var ax=document.getElementsByTagName('a');for(var i=0;i<ax.length;i++){if(ax[i].getAttribute('href') && ax[i].getAttribute('rel')=='external'){ax[i].target='_blank';}}}

function addE(){
	if(!document.getElementsByTagName){return;}
	//table row alternate colors;
	var el=document.getElementsByTagName('tr');
	for(var i=0;i<el.length;i++){
		if(el[i].id!=''&&el[i].id.indexOf('tr')==0){
			el[i].id.substring(2)%2?el[i].className='odd':el[i].className='even';
			EventManager.Add(el[i],'mouseover',tron);
			el[i].id.substring(2)%2?EventManager.Add(el[i],'mouseout',trodd):EventManager.Add(el[i],'mouseout',treven);
		}
	}
	//Calendar
	var el=document.getElementsByTagName('a');
	for(var i=0;i<el.length;i++){
		if(el[i].id!=''&&el[i].id.indexOf('calendar_')==0){
			EventManager.Add(el[i],'click',calendar);
		}
	}
}
function tron(evt){
		evt=evt||window.event;
		var target=getEventTarget(evt);
		while(target.tagName != 'TR'){
			target=target.parentNode;
		}
		target.style.backgroundColor='#ffffff';
}
function trodd(evt){
		evt=evt||window.event;
		var target=getEventTarget(evt);
		while(target.tagName != 'TR'){
			target=target.parentNode;
		}
		
		target.style.backgroundColor='#ebf1f7';
	return true;
}
function treven(evt){
		evt=evt||window.event;
		var target=getEventTarget(evt);
		while(target.tagName != 'TR'){
			target=target.parentNode;
		}
		target.style.backgroundColor='#d6e2ef';
	return true;
}
function calendar(evt){
	evt=evt||window.event;
	var target=getEventTarget(evt);
	$('calendarframe').src='/inc/calendar.cfm';
	$('calendar').style.visibility='visible';
	$('calendar').style.top=getTop(target);
	$('calendar').style.left=getLeft(target);
	datefield=$(target.id.substring(9));
	return false;
}
 




function $(id){return document.getElementById(id);}
function $i(id){var oDoc = $(id).contentWindow || $(id).contentDocument; if(oDoc.document){return oDoc.document}return oDoc;}
function getEventTarget(evt){return evt.target || evt.srcElement;}


if (!Array.prototype.push){Array.prototype.push = function(elem){this[this.length] = elem;}}var EventManager={_registry:null,Initialise:function(){if(this._registry==null){this._registry=[];EventManager.Add(window, "unload", this.CleanUp);}},Add:function(obj,type,fn,useCapture){this.Initialise();if(typeof obj=="string"){obj = document.getElementById(obj);}if(obj==null || fn==null){return false;}if(obj.addEventListener){obj.addEventListener(type,fn,useCapture);this._registry.push({obj:obj,type:type,fn:fn,useCapture:useCapture});return true;}if(obj.attachEvent && obj.attachEvent("on" + type, fn)){this._registry.push({obj:obj,type:type,fn:fn,useCapture:false});return true;}return false;},CleanUp:function(){for(var i=0;i<EventManager._registry.length;i++){with(EventManager._registry[i]){if(obj.removeEventListener){obj.removeEventListener(type,fn,useCapture);}else if (obj.detachEvent){obj.detachEvent("on" + type, fn);}}}EventManager._registry = null;}};








function roll(obj,sta,lay){
  iSrc=document[obj];
  if(document.layers && lay){iSrc=document.layers[lay].document[obj];}
  if(sta.length>1){iSrc.src="/img"+sta+".gif";return;}
  iSrc.src=iSrc.src.substring(0,iSrc.src.lastIndexOf('_')+1)+sta+".gif";
}

function loadnewframe(furl,bobj,bobl) {
	if (bobl == null) bobl = 0;
	document.newframe.location.href=furl;
	dialog.style.visibility='visible';
	dialog.style.top=getTop(bobj);
	dialog.style.left=getLeft(bobj) + bobl;
}

function getTop(el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
}
function getLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
}
function buildEditor(textarea,type,w,h){
	var sBasePath='/fckeditor/';var oFCKeditor=new FCKeditor(textarea);oFCKeditor.ToolbarSet=type;oFCKeditor.Width=w;oFCKeditor.Height=h;oFCKeditor.BasePath=sBasePath;oFCKeditor.ReplaceTextarea();	
}

datefield = "";
function setnewDate(newDate) {
	datefield.value = newDate;
	$('calendar').style.visibility='hidden';
}

function showRange() {
	if (document.all.checkfri.checked && document.all.checksat.checked)
	{
		document.all.frisat.style.visibility = 'visible';
  }
	else {
		document.all.frisat.style.visibility = 'hidden';
		document.all.checkfrisat.checked = false;
	}
	
	if (document.all.checkfri.checked && document.all.checksun.checked)
	{
		document.all.frisun.style.visibility = 'visible';
  }
	else {
		document.all.frisun.style.visibility = 'hidden';
		document.all.checkfrisun.checked = false;
	}
	
	if (document.all.checksat.checked && document.all.checksun.checked)
	{
		document.all.satsun.style.visibility = 'visible';
  }
	else {
		document.all.satsun.style.visibility = 'hidden';
		document.all.checksatsun.checked = false;
	}
	
	if (document.all.checkfri.checked && document.all.checksat.checked && document.all.checksun.checked)
	{
		document.all.frisatsun.style.visibility = 'visible';
  }
	else {
		document.all.frisatsun.style.visibility = 'hidden';
		document.all.checkfrisatsun.checked = false;
	}
}

// load htmlarea
_editor_url = "/htmlarea/";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
	document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
	document.write(' language="Javascript1.2"></scr' + 'ipt>');
}
else {
	document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>');
}
// -->
function showNav(section) {
	if (this[section + "Nav"].style.display == 'none') {
		this[section + "Nav"].style.display = 'inline';
	}
	else {
		this[section + "Nav"].style.display = 'none';
	}
	return false;
}

function pageNext(obj,val) {
	switch(val)
	{
		case 0:
			obj.style.cursor = 'hand';
			obj.style.textDecoration = 'underline';
			break;
		case 1:
			obj.style.textDecoration = 'none';
			break;
	}
}
function addLoc(val,label) {
	//document.getElementById('location').appendChild(document.createElement("input").appendChild(document.createTextNode(startprice.toFixed(2))));
	var obj = document.getElementById(val);
	if(obj.value.length > 0) {
	
	var newLabel = document.createElement("label");
	newLabel.setAttribute("for",label + document.getElementById('location').childNodes.length);
	
	
	
	
	

	
	var newCB = document.createElement("input");
	newCB.setAttribute("type","checkbox");
	newCB.setAttribute("name","location");
	newCB.setAttribute("value",obj.value);
	newCB.setAttribute("id",label + document.getElementById('location').childNodes.length);
	
	newLabel.appendChild(newCB);
	
	document.getElementById('location').appendChild(newLabel);
	document.getElementById('location').lastChild.firstChild.setAttribute("checked","true");
	document.getElementById('location').lastChild.className='checkbox';
	document.getElementById('location').lastChild.name='location';
	document.getElementById('location').lastChild.appendChild(document.createTextNode(obj.value.toLowerCase()));
	
	return false;
}
	/*
	
	
	
	
var oForm = document.createElement("form");
var oCheckB = document.createElement("input");
var oButton = document.createElement("input");

oCheckB.setAttribute("type","checkbox");
oCheckB.checked = true;

oButton.setAttribute("type","button");
oButton.onclick = function()
{
document.forms[0].elements[0].checked = !oCheckB.checked;
}

oForm.appendChild(oCheckB);
oForm.appendChild(oButton);

document.body.appendChild(oForm);
}
	
	
	
	
	
	
	<label for="test"><input type="checkbox" value="" id="" name="">#URL#</label>
	*/
}
function textLimit(obj,limit){if(obj.value.length>limit){obj.value=obj.value.substring(0,limit);}}



function validatecustomlist(searchType) {
   var f=document.forms[0];
   var message="";
   var firstErrField;

   f.emailListName.value = f.emailListName.value;
   f.productSearchString.value = f.productSearchString.value;

   if (f.emailListName.value == ''){
      message = message + "Name is in a required field.\n";
      if (!firstErrField) { firstErrField = f.emailListName; }
      }

   if (f.queryDateRange.selectedIndex == 0)
      {
      message = message + "Date Range is in a required field.\n";
      if (!firstErrField) { firstErrField = f.queryDateRange; }
      }

    if (searchType == 'Product')
       {
       if (f.productCategoryID.selectedIndex != 0)
          {
          var re = /\|\S\S\S/gi;
          message = message + "You chose a product search, but selected the category " + f.productCategoryID.options[f.productCategoryID.selectedIndex].text.replace(re,'') + ".\n";
          if (!firstErrField) { firstErrField = f.productCategoryID; }
          }
       }
    else
       {
       if (f.productCategoryID.selectedIndex == 0) {
          {
          message = message + "You must select a product category if you are choosing to create mailing list based on a product category.\n";
          if (!firstErrField) { firstErrField = f.productCategoryID; }
          }
       }
       if (f.productSearchString.value != '')
          {
          message = message + "You chose a category search, but entered a value of " + f.productSearchString.value + " for a product search.\n"
          if (!firstErrField) { firstErrField = f.productSearchString; }
          }
       }

   if (message) {
      alert("The following fields contain invalid information\n\n" + message);
      firstErrField.focus();
      return false;
      }

   if (
      (f.productSearchString.value)=='' &&
      (f.productCategoryID.selectedIndex == 0)
      )
      {

       if (!
            confirm('You have not selected either a product or category search.' +
               '\nThe results of this search will be your entire product catalog.' +
               '\nIs this correct?\n\nChoose OK to continue, Cancel to quit.')
          ) {
          return false;
          }


      }

    f.searchType.value = searchType;

    //alert("Hurray, the document is going to be submitted " + searchType);
    return true;

   }







window.onload = initwindow;
