/* Preload Images */
function preloadImages() {
	var d=document; if(d.images){ if(!d.p) d.p=new Array();
	var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
	}

function swapImgRestore() {
	var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}

function findObj(n, d) {
	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=findObj(n,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(n); return x;
	}

function swapImage() {
	var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}

/* Location: based redirect */
function goToURL() {
	var i, args=goToURL.arguments; document.returnValue = false;
	for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
	}

/* Popup Window */
function spawnWindow(theURL,winName,features,posX,posY) {
	myWindow=window.open(theURL,winName,features);
	if (!myWindow.opener) myWindow.opener = self;
	myWindow.focus();
	if(posX || posY){
		myWindow.moveTo(posX,posY);
		}
	}

/* Set status line text */
function displayStatusMsg(msgStr) {
	status=msgStr;
	document.returnValue = true;
	}

/* Get Window Size */
function getWinSize() {
	if ((document.layers||document.getElementById)&&(!document.all)) {
		winWidth = innerWidth;
		winHeight = innerHeight;
		}
	if (document.all) {
		winWidth = document.body.clientWidth;
		winHeight = document.body.clientHeight-3;
		}
	}

/* DIV visiblity/invisibility */
function toggleVisibility(id, NNtype, IEtype, WC3type) {
    if (document.getElementById) {
    	eval("document.getElementById(id).style.visibility = \"" + WC3type + "\"");
        } else {
        	if (document.layers) {
        		document.layers[id].visibility = NNtype;
       			 } else {
            		if (document.all) {
                		eval("document.all." + id + ".style.visibility = \"" + IEtype + "\"");
            			}
        			}
    			}
			}

/* Mmmm...Coookies! */
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
	document.cookie = curCookie;
	}


function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
		}
	else
    	begin += 2;
  		var end = document.cookie.indexOf(";", begin);
  		if (end == -1)
    	end = dc.length;
		return unescape(dc.substring(begin + prefix.length, end));
	}


function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
    	((path) ? "; path=" + path : "") +
    	((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
		}
	}

function jumpMenu(targ,selObj,restore){
	if(selObj.options[selObj.selectedIndex].value != "#"){
		eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
		}
	if (restore) selObj.selectedIndex=0;
	}


/* [S] dynamic tooltip */

/*
This code is from Dynamic Web Coding
www.dyn-web.com
Copyright 2001 by Sharon Paine
Permission granted to use this code as long as this
entire notice is included.
*/

var dom = (document.getElementById) ? true : false;
var ns5 = ((navigator.userAgent.indexOf("Gecko")>-1) && dom) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var ns4 = (document.layers && !dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var nodyn = (!ns5 && !ns4 && !ie4 && !ie5) ? true : false;

// resize fix for ns4
var origWidth, origHeight;
if (ns4) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

// avoid error of passing event object in older browsers
if (nodyn) event = "nope";

///////////////////////  CUSTOMIZE HERE   ////////////////////
// settings for tooltip
// Do you want tip to move with mouse movement along link?
var tipFollowMouse	= true;
var tipWidth 			 	= 300;
var offX					 	= 8;	// how far from mouse to show tip
var offY					 	= 12;
var tipFontFamily 	= "Tahoma,Verdana,arial,helvetica,sans-serif";
var tipFontSize			= "9pt";
var tipFontColor		= "#000000";
var tipBgColor 			= "#DDECFF";
var tipBorderColor 	= "#6699CC";
var tipBorderWidth 	= 1;
var tipBorderStyle 	= "solid";
var tipPadding		 	= 4;

// preload images to be placed in tooltip
//var img1 = new Image(100,100);	// (width,height)
// img1.src = "your.gif";

// variables for tooltip content
var tip1 = "--"


////////////////////  END OF CUSTOMIZATION AREA  ///////////////////

////////////////////////////////////////////////////////////
//  initTip	- initialization for tooltip.
//		Global variables for tooltip.
//		Set styles for all but ns4.
//		Set up mousemove capture if tipFollowMouse set true.
////////////////////////////////////////////////////////////
var tooltip, tipcss;
function initTip() {
	if (nodyn) return;
	tooltip = (ns4)? document.tipDiv.document: (ie4)? document.all['tipDiv']: (ie5||ns5)? document.getElementById('tipDiv'): null;
	if(tooltip){
		tipcss = (ns4)? document.tipDiv: tooltip.style;

		if (ie4||ie5||ns5) {	// ns4 would lose all this on rewrites
			tipcss.width = tipWidth+"px";
			tipcss.fontFamily = tipFontFamily;
			tipcss.fontSize = tipFontSize;
			tipcss.color = tipFontColor;
			tipcss.backgroundColor = tipBgColor;
			tipcss.borderColor = tipBorderColor;
			tipcss.borderWidth = tipBorderWidth+"px";
			tipcss.padding = tipPadding+"px";
			tipcss.borderStyle = tipBorderStyle;
		}
		if (tooltip&&tipFollowMouse) {
			if (ns4) document.captureEvents(Event.MOUSEMOVE);
			document.onmousemove = trackMouse;
		}
	}

}

/////////////////////////////////////////////////////////////
//  doTooltip function
//			Assembles content for tooltip and writes it to tipDiv.
//			Call positionTip function from here if tipFollowMouse
//			is set to false.
//////////////////////////////////////////////////////////////
var t1,t2;	// for setTimeouts
var tipOn = false;	// check if over tooltip link
function doTooltip(evt,txt) {
	if (!tooltip) return;
	if (t1) clearTimeout(t1);	if (t2) clearTimeout(t2);
	tipOn = true;
	if (ns4) {
		tip = '<table bgcolor="' + tipBorderColor + '" width="' + tipWidth + '" cellspacing="0" cellpadding="' + tipBorderWidth + '" border="0"><tr><td><table bgcolor="' + tipBgColor + '" width="100%" cellspacing="0" cellpadding="' + tipPadding + '" border="0"><tr><td><span style="font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + tipFontColor + ';">' + txt  + '</span></td></tr></table></td></tr></table>';
		tooltip.write(tip);
		tooltip.close();
	} else if (ie4||ie5||ns5) {
		tip = txt;
	 	tooltip.innerHTML = tip;
	}
	if (!tipFollowMouse) positionTip(evt);
	else t1=setTimeout("tipcss.visibility='visible'",100);
}

var mouseX, mouseY;
function trackMouse(evt) {
	mouseX = (ns4||ns5)? evt.pageX: window.event.clientX + document.body.scrollLeft;
	mouseY = (ns4||ns5)? evt.pageY: window.event.clientY + document.body.scrollTop;
	if (tipOn) positionTip(evt);
}

/////////////////////////////////////////////////////////////
//  positionTip function
//		If tipFollowMouse set false, so trackMouse function
//		not being used, get position of mouseover event.
//		Calculations use mouseover event position,
//		offset amounts and tooltip width to position
//		tooltip within window.
/////////////////////////////////////////////////////////////
function positionTip(evt) {
	if (!tipFollowMouse) {
		mouseX = (ns4||ns5)? evt.pageX: window.event.clientX + document.body.scrollLeft;
		mouseY = (ns4||ns5)? evt.pageY: window.event.clientY + document.body.scrollTop;
	}
	// tooltip width and height
	var tpWd = (ns4)? tooltip.width: (ie4||ie5)? tooltip.clientWidth: tooltip.offsetWidth;
	var tpHt = (ns4)? tooltip.height: (ie4||ie5)? tooltip.clientHeight: tooltip.offsetHeight;
	// document area in view (subtract scrollbar width for ns)
	var winWd = (ns4||ns5)? window.innerWidth-20+window.pageXOffset: document.body.clientWidth+document.body.scrollLeft;
	var winHt = (ns4||ns5)? window.innerHeight+window.pageYOffset: document.body.clientHeight+document.body.scrollTop;
	// check mouse position against tip and window dimensions
	// and position the tooltip
	if ((mouseX+offX+tpWd)>winWd)
		tipcss.left = (ns4)? mouseX-(tpWd+offX): mouseX-(tpWd+offX)+"px";
	else tipcss.left = (ns4)? mouseX+offX: mouseX+offX+"px";
	if ((mouseY+offY+tpHt)>winHt)
		tipcss.top = (ns4)? mouseY-(tpHt+offY): mouseY-(tpHt+offY)+"px";
	else tipcss.top = (ns4)? mouseY+offY: mouseY+offY+"px";
	if (!tipFollowMouse) t1=setTimeout("tipcss.visibility='visible'",100);
}

function hideTip() {
	if (!tooltip) return;
//	tipcss.visibility = "hidden";
	t2=setTimeout("tipcss.visibility='hidden'",100);
	tipOn = false;
}

/* [E] dynamic tooltip */



/* [S] Handy Form Utils */


var arrOldValues;

function SelectAllList(CONTROL){
	for(var i = 0;i < CONTROL.length;i++){
		CONTROL.options[i].selected = true;
		}
	}

function DeselectAllList(CONTROL){
	if(CONTROL.options){
		for(var i = 0;i < CONTROL.length;i++){
			CONTROL.options[i].selected = false;
			}
		}
	}


function FillListValues(CONTROL){
	var arrNewValues;
	var intNewPos;
	var strTemp = GetSelectValues(CONTROL);
	arrNewValues = strTemp.split(",");
	for(var i=0;i<arrNewValues.length-1;i++){
		if(arrNewValues[i]==1){
			intNewPos = i;
			}
		}

	for(var i=0;i<arrOldValues.length-1;i++){
		if(arrOldValues[i]==1 && i != intNewPos){
		CONTROL.options[i].selected= true;
		}
		else if(arrOldValues[i]==0 && i != intNewPos){
			CONTROL.options[i].selected= false;
			}
		if(arrOldValues[intNewPos]== 1){
			CONTROL.options[intNewPos].selected = false;
			}
		else{
			CONTROL.options[intNewPos].selected = true;
			}
		}
	}


function GetSelectValues(CONTROL){
	var strTemp = "";
	for(var i = 0;i < CONTROL.length;i++){
		if(CONTROL.options[i].selected == true){
			strTemp += "1,";
			}
		else{
			strTemp += "0,";
			}
		}
	return strTemp;
	}


function GetCurrentListValues(CONTROL){
	var strValues = "";
	strValues = GetSelectValues(CONTROL);
	arrOldValues = strValues.split(",")
	}




function CheckAll(){
	void(d=document);
	void(el=d.getElementsByTagName('INPUT'));
	for(i=0;i<el.length;i++){
		void(el[i].checked=1);
		Toggle(el[i]);
		}
	}

function UncheckAll(){
	void(d=document);
	void(el=d.getElementsByTagName('INPUT'));
	for(i=0;i<el.length;i++){
		void(el[i].checked=0);
		Toggle(el[i]);
		}
	}

function Highlight(e){
	var r = null;
	if(e.parentNode && e.parentNode.parentNode){
		r = e.parentNode.parentNode;
		}
	else if(e.parentElement && e.parentElement.parentElement){
    	r = e.parentElement.parentElement;
		}
	if(r){
		if(r.className == "listeven"){
			r.className = "listevensel";
 			}
		else if(r.className == "listodd"){
			r.className = "listoddsel";
    		}
		}
	}

function Unhighlight(e){
	var r = null;
	if(e.parentNode && e.parentNode.parentNode){
    	r = e.parentNode.parentNode;
		}
	else if(e.parentElement && e.parentElement.parentElement){
    	r = e.parentElement.parentElement;
		}
	if(r){
    	if(r.className == "listevensel"){
			r.className = "listeven";
    		}
		else if(r.className == "listoddsel"){
			r.className = "listodd";
    		}
		}
	}

function Toggle(e){
	if(e.checked){
    	Highlight(e);
		}
	else{
    	Unhighlight(e);
		}
	}

/* [E] Handy Form Utils */


/* [S] Multi-form element select (for split multi-selects using different form elements) */
function SelectMoveRows(SS1,SS2,move){
	var SelID='';
	var SelText='';
	var ItemExists='';
	// Move rows from SS1 to SS2 from bottom to top
	for (i=SS1.options.length - 1; i>=0; i--){
		if (SS1.options[i].selected == true){
			SelID=SS1.options[i].value;
			SelText=SS1.options[i].text;

			// Scan Option/Value Pairs in Destination
			// If it's new, add option
			for (j = 0; j < SS2.options.length; j++){
				if( (SelID == SS2.options[j].value) && (SelText == SS2.options[j].text) ){
					ItemExists = 1;
					}
				}
			// If Item wasn't there, Add it
			if(ItemExists != 1){
				var newRow = new Option(SelText,SelID);
				SS2.options[SS2.length]=newRow;
				}
			if(move){
				SS1.options[i]=null;
				}
			}
		}
	}

function SelectSort(SelList){
	var ID='';
	var Text='';
	for (x=0; x < SelList.length - 1; x++){
		for (y=x + 1; y < SelList.length; y++){
			if (SelList[x].text > SelList[y].text){
				// Swap rows
				ID=SelList[x].value;
				Text=SelList[x].text;
				SelList[x].value=SelList[y].value;
				SelList[x].text=SelList[y].text;
				SelList[y].value=ID;
				SelList[y].text=Text;
				}
			}
		}
	}

function ConfirmSelect(SelList){
	for (x=0; x < SelList.length; x++){
		SelList.options[x].selected = true
		}
	}
/* [E] Multi-form element select (for split multi-selects using different form elements) */

/* [S] Move Items up & down in Select Lists (handy for items in functions above */
function moveUpList(listField) {
	if ( listField.length == -1) {  // If the list is empty
		alert("There are no values which can be moved!");
		}
	else {
		var selected = listField.selectedIndex;
		if (selected == -1) {
			alert("You must select an entry to be moved!");
			}
		else {  // Something is selected
			if ( listField.length == 0 ) {  // If there's only one in the list
				alert("There is only one entry!\nThe one entry will remain in place.");
				}
			else {  // There's more than one in the list, rearrange the list order
				if ( selected == 0 ) {
					alert("The first entry in the list cannot be moved up.");
					}
				else {
					// Get the text/value of the one directly above the hightlighted entry as
					// well as the highlighted entry; then flip them
					var moveText1 = listField[selected-1].text;
					var moveText2 = listField[selected].text;
					var moveValue1 = listField[selected-1].value;
					var moveValue2 = listField[selected].value;
					listField[selected].text = moveText1;
					listField[selected].value = moveValue1;
					listField[selected-1].text = moveText2;
					listField[selected-1].value = moveValue2;
					listField.selectedIndex = selected-1; // Select the one that was selected before
					}  // Ends the check for selecting one which can be moved
				}  // Ends the check for there only being one in the list to begin with
			}  // Ends the check for there being something selected
		}  // Ends the check for there being none in the list
	}

function moveDownList(listField) {
	if ( listField.length == -1) {  // If the list is empty
		alert("There are no values which can be moved!");
		}
	else {
		var selected = listField.selectedIndex;
		if (selected == -1) {
			alert("You must select an entry to be moved!");
			}
		else {  // Something is selected
			if ( listField.length == 0 ) {  // If there's only one in the list
				alert("There is only one entry!\nThe one entry will remain in place.");
				}
			else {  // There's more than one in the list, rearrange the list order
				if ( selected == listField.length-1 ) {
					alert("The last entry in the list cannot be moved down.");
					}
				else {
					// Get the text/value of the one directly below the hightlighted entry as
					// well as the highlighted entry; then flip them
					var moveText1 = listField[selected+1].text;
					var moveText2 = listField[selected].text;
					var moveValue1 = listField[selected+1].value;
					var moveValue2 = listField[selected].value;
					listField[selected].text = moveText1;
					listField[selected].value = moveValue1;
					listField[selected+1].text = moveText2;
					listField[selected+1].value = moveValue2;
					listField.selectedIndex = selected+1; // Select the one that was selected before
					}  // Ends the check for selecting one which can be moved
				}  // Ends the check for there only being one in the list to begin with
			}  // Ends the check for there being something selected
		}  // Ends the check for there being none in the list
	}
/* [E] Move Items up & down in Select Lists (handy for items in functions above */

function change_company_select(object) {

   if (object.value == "custom") {

      document.getElementById("Company").style.visibility='visible';
      document.getElementById("Company").focus();

   } else {

      document.getElementById("Company").style.visibility='hidden';

   }

}

function reset_form() {

   var i;

   var input = document.getElementsByTagName("input");
   var textarea = document.getElementsByTagName("textarea");
   var select = document.getElementsByTagName("select");

   for (i = 0; i < input.length; i++) { if (input[i].type == "text") { input[i].value = ""; } }
   for (i = 0; i < input.length; i++) { if (input[i].type == "radio") { input[i].checked = ""; } }
   for (i = 0; i < input.length; i++) { if (input[i].type == "checkbox") { input[i].checked = ""; } }
   for (i = 0; i < textarea.length; i++) { textarea[i].value = ""; }
   for (i = 0; i < select.length; i++) { select[i].selectedIndex = 0; }

}

function check_category(object) {

   var value = object.value;

   if (value == "{add}") {

      var new_value = prompt("Please enter the new category name:","");

      if (new_value != null) {

         object.options[object.length] = new Option(new_value,new_value);

         alert("The category " + new_value + " has been added to the list.");

         object.selectedIndex = object.options.length - 1;

      } else { object.selectedIndex = 0; }

   }

}

function rotate_quotes() {

   if (document.getElementById("quotes")) { var object = document.getElementById("quotes"); }
   else if (document.all.quotes) { var object = document.all.quotes; }

   if (object) {

      var quotes = new Array();

      quotes[0] = "Joe Girard, Guinness Book of World Records #1 salesman eight times in a row. His secret? Staying in touch with customers by newsletters.";
      quotes[1] = "Jay Conrad Levinson, Guerrilla Marketing creator, author of nine books, paid $12,000 a day to speak, booked six months in advance. His #1 weapon? The newsletter.";
      quotes[2] = "Dr. Robert Cialdini, author of Influence, the most quoted book on the planet for influencing prospects to become customers, speaks around the world. His #1 “influencer” is “reciprocity,” such as newsletters.";
      quotes[3] = "Dan Kennedy, America’s top direct response copywriter, speaker to millions worldwide alongside Colin Powell, Brian Tracy, President Bush and other leaders. His #1 recommendation for upsells, resells, loyalty and getting referrals? Newsletters.";

      object.innerHTML = "<i><b>&ldquo;" + quotes[num] + "&rdquo;</b></i>";

      num++;
      if (num == quotes.length) num = 0;
   }

}

/* Not using random quotes anymore, see above rotate_quotes() */
function choose_random_quote() {

   if (document.getElementById("quotes")) { var object = document.getElementById("quotes"); }
   else if (document.all.quotes) { var object = document.all.quotes; }

   if (object) {

      var quotes = new Array();

      quotes[0] = "Joe Girard, Guinness Book of World Records #1 salesman eight times in a row. His secret? Staying in touch with customers by newsletters.";
      quotes[1] = "Jay Conrad Levinson, Guerrilla Marketing creator, author of nine books, paid $12,000 a day to speak, booked six months in advance. His #1 weapon? The newsletter.";
      quotes[2] = "Dr. Robert Cialdini, author of Influence, the most quoted book on the plant for influencing prospects to become customers, speaks around the world. His #1 “influencer” is “reciprocity,” such as newsletters.";
      quotes[3] = "Dan Kennedy, America’s top direct response copywriter, speaker to millions worldwide alongside Colin Powell, Brian Tracy, President Bush and other leaders. His #1 recommendation for upsells, resells, loyalty and getting referrals? Newsletters.";

      random_num = Math.round(3*Math.random());

      object.innerHTML = "<i><b>&ldquo;" + quotes[random_num] + "&rdquo;</b></i>";

   }

}

function submit_form(form) {

   var object = document.getElementById(form);
   if (!object) { object = document.all.login; }

   object.submit();

}

window.onload = new function() {
   initTip;
}