
    
////////////////////////
// TOOLTIP
////////////////////////
// Extended Tooltip Javascript
// copyright 9th August 2002, 3rd July 2005
// by Stephen Chapman, Felgall Pty Ltd

// permission is granted to use this javascript provided that the below code is not altered
var DH = 0;
var an = 0;
var al = 0;
var ai = 0;
if (document.getElementById) {
    ai = 1;
    DH = 1;
} else {
    if (document.all) {
        al = 1;
        DH = 1;
    } else {
        browserVersion = parseInt(navigator.appVersion);
        if ((navigator.appName.indexOf("Netscape") != -1) && (browserVersion == 4)) {
            an = 1;
            DH = 1;
        }
    }
}
function fd(oi, wS) {
    if (ai) {
        return wS ? document.getElementById(oi).style : document.getElementById(oi);
    }
    if (al) {
        return wS ? document.all[oi].style : document.all[oi];
    }
    if (an) {
        return document.layers[oi];
    }
}
function pw() {
    return window.innerWidth != null ? window.innerWidth : document.body.clientWidth != null ? document.body.clientWidth : null;
}
function mouseX(evt) {
    if (evt.pageX) {
        return evt.pageX;
    } else {
        if (evt.clientX) {
            return evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
        } else {
            return null;
        }
    }
}
function mouseY(evt) {
    if (evt.pageY) {
        return evt.pageY;
    } else {
        if (evt.clientY) {
            return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
        } else {
            return null;
        }
    }
}
function popUpTip(evt, oi) {
    if (DH) {
        var wp = pw();
        ds = fd(oi, 1);
        dm = fd(oi, 0);
        st = ds.visibility;
        if (dm.offsetWidth) {
            ew = dm.offsetWidth;
        } else {
            if (dm.clip.width) {
                ew = dm.clip.width;
            }
        }
        if (st == "visible" || st == "show") {
            ds.visibility = "hidden";
        } else {
            tv = mouseY(evt) + 20;
            lv = mouseX(evt) - (ew / 4);
            if (lv < 2) {
                lv = 2;
            } else {
                if (lv + ew > wp) {
                    lv -= ew / 2;
                }
            }
            if (!an) {
                lv += "px";
                tv += "px";
            }
            ds.left = lv;
            ds.top = tv;
            ds.visibility = "visible";
        }
    }
}
    
    
/////////////////////////////
// POPUP
/////////////////////////////
function popUp(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=400,left = 320,top = 312');");
}
        
function previewAdText(elemID ) {
		newwindow2=window.open('','name','top=100,left=100,height=600,width=700');
		var tmp = newwindow2.document;
		
		var element = document.getElementById(elemID);
		
		tmp.write('<html><head><title>Ad Preview</title>');
		tmp.write('<style>.adtext-preview {	font-family: "times";	font-size: 24pt;	width: 6.6in;	text-align: center;background-color: #ffffff;	border: thin solid #999999;	padding: 5px;}</style>');
		tmp.write('</head><body>');
		
		tmp.write('<center><div class="adtext-preview">');
		tmp.write(element.innerHTML);
		tmp.write('</div>');
		element = document.getElementById('issues');
		tmp.write(element.innerHTML);
		element = document.getElementById('cost');
		tmp.write(element.innerHTML);
		tmp.write('<p><a class="action" href="javascript:self.close()">close</a></p>');
		tmp.write('</center></body></html>');
		tmp.close();
	}        
        
/////////////////////////////////////
// CHANGE SELECTLIST TO CHECKMARKS
/////////////////////////////////////
function buildMultiselects() {
    do {
        found = 0;
        a = document.getElementsByTagName("select");
        for (b = 0; b < a.length, !found; b++) {
            var ms = a[b];
            if (ms == null) {
                break;
            }
            if (ms.name.substring(ms.name.length - 2, ms.name.length) == "[]") {
                found = 1;
                disabled = (ms.disabled) ? 1 : 0;
                width = ms.offsetWidth;
                height = ms.offsetHeight;
                el = document.createElement("div");
                el.style.overflow = "auto";
                el.style.width = width + "px";
                el.style.height = height + "px";
                el.style.border = "2px solid #000";
                el.style.borderColor = "#333 #ccc #ccc #333";
                c = ms.getElementsByTagName("option");
                for (d = 0; d < c.length; d++) {
                    el2 = document.createElement("span");
                    el2.style.display = "block";
                    el2.style.border = "1px solid #eee";
                    el2.style.borderWidth = "1px 0";
                    el2.style.font = "10px arial";
                    el2.style.lineHeight = "10px";
                    el2.style.paddingLeft = "20px";
                    el3 = document.createElement("input");
                    el3.type = "checkbox";
                    if (c[d].selected) {
                        el3.checked = "checked";
                        el3.defaultChecked = true;
                    }
                    if (disabled) {
                        el3.disabled = "disabled";
                    }
                    el3.value = c[d].value;
                    el3.style.marginLeft = "-16px";
                    el3.style.marginTop = "-2px";
                    el3.name = ms.name;
                    el4 = document.createTextNode(c[d].innerHTML);
                    el2.appendChild(el3);
                    el2.appendChild(el4);
                    el.appendChild(el2);
                }
                ms.parentNode.insertBefore(el, ms);
                ms.parentNode.removeChild(ms);
            }
        }
    } while (found);
}

///////////////////////
// GENERAL
///////////////////////
function yesNo(msg) {
    var msg = (msg == null) ? "Are you sure?" : msg;
    return confirm(msg);
}
function clearSearch(theFormName) {
    theform = document.forms[theFormName];
    theform.searchterms.value = "";
    theform.submit();
}
function getWindowWidth() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == "number") {
    //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else {
        if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
    //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth;
            myHeight = document.documentElement.clientHeight;
        } else {
            if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
    //IE 4 compatible
                myWidth = document.body.clientWidth;
                myHeight = document.body.clientHeight;
            }
        }
    }
    return myWidth;
}
function validateBatchBill() {
    var theForm = document.forms["goofyform"];
    var total = 0;
    //alert(theForm.selectedads.length);
    for (var i = 0; i < theForm.elements["selectedads[]"].length; i++) {
        if (theForm.elements["selectedads[]"][i].checked) {
            total++;
        }
    }
    if (total == 0) {
        alert("You did not select any ads to bill");
        return false;
    } else {
        return true;
    }
    return false;
}
/********************************************************************************
Copyright (C) 1999 Thomas Brattli
This script is made by and copyrighted to Thomas Brattli at www.bratta.com
Visit for more great scripts. This may be used freely as long as this msg is intact!
I will also appriciate any links you could give me.
********************************************************************************/
//Default browsercheck, added to all scripts!
function checkBrowser() {
    this.ver = navigator.appVersion;
    this.dom = document.getElementById ? 1 : 0;
    this.ie5 = (this.ver.indexOf("MSIE 5") > -1 && this.dom) ? 1 : 0;
    this.ie4 = (document.all && !this.dom) ? 1 : 0;
    this.ns5 = (this.dom && parseInt(this.ver) >= 5) ? 1 : 0;
    this.ns4 = (document.layers && !this.dom) ? 1 : 0;
    this.bw = (this.ie5 || this.ie4 || this.ns4 || this.ns5);
    return this;
}
bw = new checkBrowser();
//With nested layers for netscape, this function hides the layer if it's visible and visa versa
function showHide(div, nest) {
    obj = bw.dom ? document.getElementById(div).style : bw.ie4 ? document.all[div].style : bw.ns4 ? nest ? document[nest].document[div] : document[div] : 0;
    if (obj.display != "none") {
        obj.display = "none";
    } else {
        obj.display = "block";
    }
}
//Shows the div
function show(div, nest) {
    obj = bw.dom ? document.getElementById(div).style : bw.ie4 ? document.all[div].style : bw.ns4 ? nest ? document[nest].document[div] : document[div] : 0;
    obj.display = "block";
}
//Hides the div
function hide(div, nest) {
    obj = bw.dom ? document.getElementById(div).style : bw.ie4 ? document.all[div].style : bw.ns4 ? nest ? document[nest].document[div] : document[div] : 0;
    obj.display = "none";
}
function checkAll(field) {
    for (i = 0; i < field.length; i++) {
        field[i].checked = true;
    }
}
function uncheckAll(field) {
    for (i = 0; i < field.length; i++) {
        field[i].checked = false;
    }
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
	
function URLEncode(input )
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var	plaintext = input + "";
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return  encoded;
};

function URLDecode(input )
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = input + "";
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
};