aMonths = Array("", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
aMaxDays = Array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
var aMaxDays = new Array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var epkWidth = 690;

var xor_key = 8;

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 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 MM_findObj(n, d) { //v4.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);
	if(!x && document.getElementById)
		x = document.getElementById(n);
	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_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_showHideLayers() { //v3.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 tmt_DivAlign(theDiv, h, v, hPx, vPx){
	var obj, fun, dw, dh, lw, lh, x, y;
	fun = (document.getElementById) ? "document.getElementById" : "MM_findObj";
	obj = (document.getElementById) ? document.getElementById(theDiv) : MM_findObj(theDiv);
	if(obj) {
		if(document.all){
			dw = document.body.clientWidth;
			dh = document.body.clientHeight;
		} else {
			dw = innerWidth;
			dh = innerHeight;
		}
		if(document.layers) {
			lw = obj.clip.width;
			lh = obj.clip.height;
		} else {
			lw = obj.style.width.replace("px","");
			lh = obj.style.height.replace("px","");
		}
		x = (document.layers) ? ".left" : ".style.left";
		y = (document.layers) ? ".top" : ".style.top";
		if(h == "l")
			eval(fun + "('" + theDiv + "')" + x + "=" + hPx);
		if(h == "c")
			eval(fun + "('" + theDiv + "')" + x + "=" + dw + "/2-" + lw + "/2");
		if(h == "r")
			eval(fun + "('" + theDiv + "')" + x + "=" + dw + "-" + lw + "-" + hPx);
		if(v == "t")
			eval(fun + "('" + theDiv + "')" + y + "=" + vPx);
		if(v == "m")
			eval(fun + "('" + theDiv + "')" + y + "=" + dh + "/2-" + lh + "/2");
		if(v == "b")
			eval(fun + "('" + theDiv + "')" + y + "=" + dh + "-" + lh + "-" + vPx);
	}
}


function fncPopUp(URL){
	var sName, sWidth, sHeight, sXpos, sYpos, sScroll, sResize;
	
	sName = 'popup';
	sWidth = epkWidth;
	sHeight = '640';
	sXpos = '20';
	sYpos = '40';
	sScroll = 'no';
	sResize = 'no';
	sWinbars = 'no';
			
	if (fncPopUp.arguments[0] == ''){
		fncPopUp.arguments[0] = '/error_popup.htm';
	}

	//handled agruments if they are left blank
	if (fncPopUp.arguments.length > 1)
		sName = fncPopUp.arguments[1];
	if (fncPopUp.arguments.length > 2)
		sWidth = fncPopUp.arguments[2];
	if (fncPopUp.arguments.length > 3)
		sHeight = fncPopUp.arguments[3];
	if (fncPopUp.arguments.length > 4)
		sXpos = fncPopUp.arguments[4];
	if (fncPopUp.arguments.length > 5)
		sYpos = fncPopUp.arguments[5];
	if (fncPopUp.arguments.length > 6)
		sScroll = fncPopUp.arguments[6];
	if (fncPopUp.arguments.length > 7)
		sResize = fncPopUp.arguments[7];
	if (fncPopUp.arguments.length > 8)
		sWinbars = fncPopUp.arguments[8];

	var winBars;
	if (sWinbars=='no')
		winBars = 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no';
	else
		winBars = 'directories=yes,location=yes,menubar=yes,status=yes,titlebar=yes,toolbar=yes';
				
	var winOptions = 'scrollbars='+ sScroll + ',resizable='+ sResize;
	var winSize = 'height=' + sHeight + ',width=' + sWidth;
	var winPosition = 'left=' + sXpos + ',top=' + sYpos;
	var winFeatures = winBars + ',' + winOptions + ',' + winSize + ',' + winPosition;			
	
	var theWindow = window.open(URL,sName,winFeatures);
	if (theWindow == null) 
	{
		alert('You seem to have popup blocking software enabled.\nIn order to use certain features of Sonicbids, including EPKs (Electronic Press Kits), please configure your popup blocker to allow popups from sonicbids.com.');
		document.location.replace('/support/popup_blockers.asp');
	}
	else
	{
	    theWindow.focus();
	}

    //return theWindow;
}


function fncPopUpNoBlockerCatcher(URL){
	var sName, sWidth, sHeight, sXpos, sYpos, sScroll, sResize;
	
	sName = 'popup';
	sWidth = epkWidth;
	sHeight = '520';
	sXpos = '20';
	sYpos = '40';
	sScroll = 'no';
	sResize = 'no';
	sWinbars = 'no';
			
	if (fncPopUpNoBlockerCatcher.arguments[0] == ''){
		fncPopUpNoBlockerCatcher.arguments[0] = '/error_popup.htm';
	}

	//handled agruments if they are left blank
	if (fncPopUpNoBlockerCatcher.arguments.length > 1)
		sName = fncPopUpNoBlockerCatcher.arguments[1];
	if (fncPopUpNoBlockerCatcher.arguments.length > 2)
		sWidth = fncPopUpNoBlockerCatcher.arguments[2];
	if (fncPopUpNoBlockerCatcher.arguments.length > 3)
		sHeight = fncPopUpNoBlockerCatcher.arguments[3];
	if (fncPopUpNoBlockerCatcher.arguments.length > 4)
		sXpos = fncPopUpNoBlockerCatcher.arguments[4];
	if (fncPopUpNoBlockerCatcher.arguments.length > 5)
		sYpos = fncPopUpNoBlockerCatcher.arguments[5];
	if (fncPopUpNoBlockerCatcher.arguments.length > 6)
		sScroll = fncPopUpNoBlockerCatcher.arguments[6];
	if (fncPopUpNoBlockerCatcher.arguments.length > 7)
		sResize = fncPopUpNoBlockerCatcher.arguments[7];
	if (fncPopUpNoBlockerCatcher.arguments.length > 8)
		sWinbars = fncPopUpNoBlockerCatcher.arguments[8];

	var winBars;
	if (sWinbars=='no')
		winBars = 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no';
	else
		winBars = 'directories=yes,location=yes,menubar=yes,status=yes,titlebar=yes,toolbar=yes';
				
	var winOptions = 'scrollbars='+ sScroll + ',resizable='+ sResize;
	var winSize = 'height=' + sHeight + ',width=' + sWidth;
	var winPosition = 'left=' + sXpos + ',top=' + sYpos;
	var winFeatures = winBars + ',' + winOptions + ',' + winSize + ',' + winPosition;			
	
	return window.open(URL,sName,winFeatures);
	
}


function fncPopUprefer(URL){
	var sName, sWidth, sHeight, sXpos, sYpos, sScroll, sResize, sWinbars;
	
	sName = 'popup';
	sWidth = '330';
	sHeight = '290';
	sXpos = '20';
	sYpos = '40';
	sScroll = 'no';
	sResize = 'no';
	sWinbars = 'no';
			
	if (fncPopUprefer.arguments[0] == ''){
		fncPopUprefer.arguments[0] = '/error_popup.htm';
	}

	//handled agruments if they are left blank
	if (fncPopUprefer.arguments.length > 1)
		sName = fncPopUprefer.arguments[1];
	if (fncPopUprefer.arguments.length > 2)
		sWidth = fncPopUprefer.arguments[2];
	if (fncPopUprefer.arguments.length > 3)
		sHeight = fncPopUprefer.arguments[3];
	if (fncPopUprefer.arguments.length > 4)
		sXpos = fncPopUprefer.arguments[4];
	if (fncPopUprefer.arguments.length > 5)
		sYpos = fncPopUprefer.arguments[5];
	if (fncPopUprefer.arguments.length > 6)
		sScroll = fncPopUprefer.arguments[6];
	if (fncPopUprefer.arguments.length > 7)
		sResize = fncPopUprefer.arguments[7];
	if (fncPopUprefer.arguments.length > 8)
		sWinbars = fncPopUprefer.arguments[8];
	
	fncPopUp(URL, sName, sWidth, sHeight, sXpos, sYpos, sScroll, sResize);			
}

function fncShowTip(strTipID) {

	var strAccountID = '';
	var intEPKID = '';

	if (fncShowTip.arguments.length > 1) {
		strAccountID = fncShowTip.arguments[1];
	}
	
	if (fncShowTip.arguments.length > 2) {
		intEPKID = fncShowTip.arguments[2];
	}

	return fncPopUp('/support/tip_view.asp?ref_id=' + strTipID + '&account_id=' + strAccountID + '&epk_id=' + intEPKID, 'tip_view', 450, 400, 20, 20, 'yes', 'no', 'no');
}


function fncOpenEPK(strEPKID) {
	strEPKURL = '/epk/epk.aspx?epk_id=' + strEPKID

	// Name
	if (fncOpenEPK.arguments.length > 1)
		strEPKURL += '&name=' + fncOpenEPK.arguments[1];
	
	// Skin ID
	if (fncOpenEPK.arguments.length > 2)
		strEPKURL += '&skin_id=' + fncOpenEPK.arguments[2];
		
	// Poll ID
	if (fncOpenEPK.arguments.length > 3)
		strEPKURL += '&poll_id=' + fncOpenEPK.arguments[3];
	
	// Update Chart (Log View)
	if (fncOpenEPK.arguments.length > 4)
		strEPKURL += '&lv=' + fncOpenEPK.arguments[4];
		
	// Cobrand
	if (fncOpenEPK.arguments.length > 5)
		strEPKURL += '&co_brand=' + fncOpenEPK.arguments[5];
	
	//arguments 6,7,8, and 9 
	if (fncOpenEPK.arguments.length > 6)
	{
	    //says the override is coming
	    strEPKURL += '&osk=1';
	    //6 primary color
	    strEPKURL += '&primary=' + fncOpenEPK.arguments[6];
	    //7 secondary color
	    strEPKURL += '&secondary=' + fncOpenEPK.arguments[7];
	    //8 button color
	    strEPKURL += '&btn=' + fncOpenEPK.arguments[8];
	    //9 button color
	    strEPKURL += '&btnh=' + fncOpenEPK.arguments[9];
	}
	//alert(strEPKURL);

    // Host
	if (fncOpenEPK.arguments.length > 10)
	{
	    strEPKURL = 'http://' + fncOpenEPK.arguments[10] + strEPKURL;
	}
	else
	{
	    if (window.location.hostname.indexOf('landshark') >= 0)
	    {
	        strEPKURL = 'http://www.sonicbids.com' + strEPKURL;
	    }
	}
		
	fncPopUp(strEPKURL, 'epk', epkWidth, 640, 20, 40, 'no', 'yes', 'no');
}


function fncOpenEPKNoBlockerCatcher(strEPKID) {
	strEPKURL = '/epk/epk.aspx?epk_id=' + strEPKID

	if (fncOpenEPKNoBlockerCatcher.arguments.length > 1)
		strEPKURL += '&name=' + fncOpenEPK.arguments[1];
	
	if (fncOpenEPKNoBlockerCatcher.arguments.length > 2)
		strEPKURL += '&skin_id=' + fncOpenEPK.arguments[2];
		
	if (fncOpenEPKNoBlockerCatcher.arguments.length > 3)
		strEPKURL += '&poll_id=' + fncOpenEPK.arguments[3];
		
	return fncPopUpNoBlockerCatcher(strEPKURL, 'epk', epkWidth, 640, 20, 40, 'no', 'yes', 'no');
}

function fncOpenEPKSubmission(strSubmissionID) {
	strEPKURL = '/epk/epk.aspx?submission_id=' + strSubmissionID

	if (fncOpenEPKSubmission.arguments.length > 1)
		strEPKURL += '&name=' + fncOpenEPKSubmission.arguments[1];
	
	if (fncOpenEPKSubmission.arguments.length > 2)
		strEPKURL += '&skin_id=' + fncOpenEPKSubmission.arguments[2];
	
	if (fncOpenEPKSubmission.arguments.length > 3)
		strEPKURL += '&poll_id=' + fncOpenEPKSubmission.arguments[3];
		
	return fncPopUp(strEPKURL, 'epk', epkWidth, 640, 20, 40, 'no', 'no', 'no');
}

function fncOpenEPKArtist(strArtistID) {
	strEPKURL = '/epk/epk.aspx?artist_id=' + strArtistID

	if (fncOpenEPKArtist.arguments.length > 1)
		strEPKURL += '&name=' + fncOpenEPKArtist.arguments[1];
	
	if (fncOpenEPKArtist.arguments.length > 2)
		strEPKURL += '&skin_id=' + fncOpenEPKArtist.arguments[2];
	
	if (fncOpenEPKArtist.arguments.length > 3)
		strEPKURL += '&poll_id=' + fncOpenEPKArtist.arguments[3];
		
	fncPopUp(strEPKURL, 'epk', epkWidth, 640, 20, 40, 'no', 'yes', 'no');
}

var expDays = 100;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal (offset) {  

	var endstr = document.cookie.indexOf (";", offset);  

	if (endstr == -1) 
		endstr = document.cookie.length;

	return unescape(document.cookie.substring(offset, endstr));
}



function GetCookie (name) {  

	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  

	while (i < clen) {    

		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg) 
			return getCookieVal (j);    

		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) 
			break;   
	}  
	return '';
}

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 TestCookies() {
	SetCookie("testingcookies", "testingcookies")
	var strResult = GetCookie("testingcookies")
	if (strResult == "testingcookies")
		return true;
	else
		return false;
}

	
var winSpellChecker;

function doCheckForSpellCheckerPopup(strInputID) {
	
	if (winSpellChecker.closed)
		document.getElementById(strInputID).disabled = false;
	else
		setTimeout('doCheckForSpellCheckerPopup(\'' + strInputID + '\')', 500);
	
}
	
function doCheckSpelling(strInput) {
	objInput = document.getElementById(strInput);
	objInput.disabled = true;
	winSpellChecker = fncPopUpNoBlockerCatcher('/spellchecker/spellchecker.asp?text=' + escape(objInput.value) + '&inputhandle=' + objInput.id, 'spellchecker', 550, 400, 10, 10, 'no', 'no', 'no');
	doCheckForSpellCheckerPopup(objInput.id);	
}

function fncOpenVenueDetails(strVenueID) {

	fncPopUp('/buyer/venue_view.asp?venue_id=' + strVenueID, 'winVenueDetails', 400, 300, 20, 20, 'no', 'no', 'no');

}

function isLeapYear(year)
{
	if ( year % 4 == 0 )
		if ( year % 400 == 0 )
			return true;
		else if ( year % 100 == 0 )
			return false;
		else
			return true;		
	else return false;	//if it's not divisible by 400 or 100, then it's still divisible by 4, so true
}

function DateAdd(strInterval, intNumber, datStart) {
	
    // get the milliseconds for this Date object. 
    var buffer = Date.parse(datStart);
	
    // check that the start parameter is a valid Date. 
    if (isNaN(buffer)) {
        return null;
    }
	
    // check that an interval parameter was not numeric. 
    if ( strInterval.charAt == 'undefined' ) {
        return null;
    }

    // check that the number parameter is numeric. 
    if (isNaN(intNumber)) {
        return null;
    }

    // so far, so good...
    //
    // what kind of add to do? 
    switch (strInterval.charAt(0))
    {
		case 'm': case 'M':
			var intDaysAdded = 0;
			var datTemp = new Date(buffer);
			var intCurrentYear = datTemp.getYear();
			var intCurrentMonth = datTemp.getMonth() + 1;
			if (intNumber > 0)
				for (var intMonthsAdded=0; intMonthsAdded < intNumber; intMonthsAdded++) {
					intCurrentMonth++;
					if (intCurrentMonth > 12) {
						intCurrentMonth = 1;
						intCurrentYear++;
					}
				}
			else
				for (var intMonthsAdded=0; intMonthsAdded > intNumber; intMonthsAdded--) {
					intCurrentMonth--;
					if (intCurrentMonth < 1) {
						intCurrentMonth = 12;
						intCurrentYear--;
					}
				}
			
			var intDay = new Date(buffer).getDate();
			var intMaxDays = aMaxDays[intCurrentMonth];
			if (intCurrentMonth==2 && isLeapYear(intCurrentYear))
				intMaxDays++;

			if (intMaxDays < intDay) {
				intDay = intMaxDays;
			}
			
			datTemp.setDate(intDay)
			datTemp.setMonth(intCurrentMonth - 1);
			datTemp.setYear(intCurrentYear);
			
			intNumber = datTemp.valueOf() - buffer;
			
			break;
        case 'd': case 'D': 
            intNumber *= 24; // days to hours
            // fall through! 
        case 'h': case 'H':
            intNumber *= 60; // hours to minutes
            // fall through! 
        case 'm': case 'M':
            intNumber *= 60; // minutes to seconds
            // fall through! 
        case 's': case 'S':
            intNumber *= 1000; // seconds to milliseconds
            break;
        default:
	        return null;
    }
    return new Date( buffer + intNumber ) ;
}

function CleanRedirect(strURL) {

	if (window.opener == null)
		document.location = strURL;
	else {
		window.opener.location = strURL;
		window.opener.focus();
		window.close();
	}
}

function TextBox_onkeypress(strControlID, postBackReference) {

	if (window.event.keyCode==13) {
		eval(postBackReference);
	}
	return false;
}

function showToolTip(evt, toolTipID)
{
    var theToolTip = document.getElementById(toolTipID);
    if (theToolTip)
    {
        if (theToolTip.style.display != 'block')
        {
            var e = (window.event) ? window.event : evt;
			var ua = navigator.userAgent;
			
			if (navigator.appName == 'Microsoft Internet Explorer')
			{
				theToolTip.style.left = (e.clientX) + 10;
				theToolTip.style.top = (e.clientY + document.documentElement.scrollTop + document.body.scrollTop) - 35;
			}
			else if(ua.indexOf("Safari") > -1)
			{
				theToolTip.style.left = (e.clientX) + 10;
				theToolTip.style.top = (e.clientY + getScrollY()) - 35;
			}
			else
			{
				theToolTip.style.left = (e.clientX) + 10;
				theToolTip.style.top = (e.clientY + getScrollY()) - 35;
			}
						
			theToolTip.style.position = 'absolute';
			theToolTip.style.visibility = 'visible';
			theToolTip.style.display = 'block';
        }
    }
}

function showToolTipRelative(evt, toolTipID)
{
    var theToolTip = document.getElementById(toolTipID);
    if (theToolTip)
    {
        if (theToolTip.style.display != 'block')
        {
						
			theToolTip.style.position = 'absolute';
			theToolTip.style.visibility = 'visible';
			theToolTip.style.display = 'block';
        }
    }
}

function getScrollY()
{
	var scrollY = 0;
	if( document.documentElement && document.documentElement.scrollTop )
	{
		scrollY = document.documentElement.scrollTop;
	}
	else if(document.body && document.body.scrollTop)
	{
		scrollY = document.body.scrollTop;
	}
	else if(window.pageYOffset)
	{
		scrollY = window.pageYOffset;
	}
	else if(window.scrollY) {
		scrollY = window.scrollY;
	}
	
	return scrollY;
}

function hideToolTip(elementID)
{
    var tooltip = document.getElementById(elementID);
    if (tooltip)
    {
        if (tooltip.style.display == 'block')
        {
            tooltip.style.display = 'none';
        }
    }
}

function preventPasteFromKeyboard(e, textbox)
{
    if (e.ctrlKey)
    {
        textbox.value = "";
    }
}

function preventPasteFromMenu(textbox)
{
   return false;
}

function zeroize(value, length) 
{
    if (!length) length = 2; value = String(value);
    for (var i = 0, zeros = ''; i < (length - value.length); i++)
    {
        zeros += '0';
    } 
    
    return zeros + value;
}

function setImageDimensions(imageInput, size)
{
    var oImg = new Image();
    oImg.src = imageInput.src;  
    
    
    if (oImg.height >= oImg.width)
    {
        var newWidth = Math.floor((size/oImg.height) * oImg.width);
        
        imageInput.style.height = size + "px";
        imageInput.style.width = newWidth + "px";
        
        imageInput.style.marginLeft = ((size - newWidth) / 2) + "px";
        imageInput.style.marginRight = ((size - newWidth) / 2) + "px";
        
    }
    else if (oImg.width > oImg.height)
    {
        var newHeight = Math.floor((size/oImg.width) * oImg.height);
        
        imageInput.style.height = newHeight + "px";
        imageInput.style.width = size + "px";
        
        imageInput.style.marginTop = ((size - newHeight) / 2) + "px";
        imageInput.style.marginBottom = ((size - newHeight) / 2) + "px";
    }
    else
    {
        imageInput.style.height = size + "px";
        imageInput.style.width = size + "px";
        imageInput.style.marginLeft = "0px";
        imageInput.style.marginRight = "0px";
        imageInput.style.marginTop = "0px";
        imageInput.style.marginBottom = "0px";
    }
}

function printPage()
{
    window.print();
}

function toggleLabel(labelID, fieldID, linkID)
{
    
    var label = document.getElementById(labelID);
    var field = document.getElementById(fieldID);
    var link = document.getElementById(linkID);
    var fieldValue = field.value;
    var labelText = label.innerHTML;
    
    blnLabelExpanded = (link.innerHTML == "[+] more");
    
    if (blnLabelExpanded)
    {
        label.innerHTML = fieldValue;
        field.value = labelText;
        link.innerHTML = "[-] less";
    }
    else
    {
        label.innerHTML = fieldValue;
        field.value = labelText;
        link.innerHTML = "[+] more";
    }
    
    link.blur();
}

function setImage(imageID, imageURL)
{
    var image = document.getElementById(imageID);
    
    //alert(image.src)
    if (image && imageURL != '')
    {
        image.src = imageURL;
    }
}

function showLinkInIframe(url, iFrameID)
{
    var iframe = document.getElementById(iFrameID);
    
    if (iframe)
    {
        iframe.src = url;
    }
}

function isChildOf(parent, child)
{
    if (child == parent)
    {
        return true;
    }
    else if (parent.hasChildNodes)
    {
        for (var i=0; i < parent.childNodes.length; i++)
        {
            //alert(parent.childNodes[i].nodeName + ' ' + child.nodeName);
            
            if (parent.childNodes[i] == child)
            {
                return true;
            }
            else
            {
                if (isChildOf(parent.childNodes[i], child))
                {
                    return true;
                }
            }
        }
    }
    else
    {
        return false;
    }
    
    return false;
}

function pauseJS(millis)
{
    var date = new Date();
    var curDate = null;

    do 
    { 
        curDate = new Date(); 
    } 
    while(curDate-date < millis);
} 

function setBandPicDimensions(imageInput, leftCornerID, rightCornerID, widthOfPanel)
{
    var oImg = new Image();
    oImg.src = imageInput.src;  
    
    if (parseInt(oImg.width) == 0 || parseInt(oImg.height) == 0)
    {
        oImg.src = imageInput.src;  
        imageInput.style.width = widthOfPanel;
        
        return;
    }
    else
    {
        if (oImg.width < widthOfPanel)
        {
            imageInput.style.marginLeft = Math.floor(((widthOfPanel - oImg.width) / 2)) + "px";
            imageInput.style.marginRight = Math.ceil(((widthOfPanel - oImg.width) / 2)) + "px";
            
            var leftCornerPiece = document.getElementById(leftCornerID);
            var rightCornerPiece = document.getElementById(rightCornerID);

            if (leftCornerPiece)
            {
                leftCornerPiece.style.left = Math.floor(((widthOfPanel - oImg.width) / 2)) + "px";
            }

            if (rightCornerPiece)
            {
                rightCornerPiece.style.right = Math.ceil(((widthOfPanel - oImg.width) / 2)) + "px";
            }
        }
        else
        {
            imageInput.style.width = widthOfPanel;
        }
    }
    
}

function setBandPicDimensionsWithHeight(imageInput, topLeftCornerID, topRightCornerID, bottomLeftCornerID, bottomRightCornerID, widthOfPanel, heightOfPanel, centeredVertically)
{
    var oImg = new Image();
    oImg.src = imageInput.src;  
    //oImg.width = imageInput.width;
    //oImg.height = imageInput.height;

    //alert('test');
    if (!centeredVertically)
    {
        centeredVertically = false;
    }
    
    if (parseInt(oImg.width) == 0 || parseInt(oImg.height) == 0)
    {
        oImg.src = imageInput.src;  
        imageInput.style.maxWidth = widthOfPanel;
        imageInput.style.maxHeight = heightOfPanel;
        
        return;
    }
    else
    {
        var topLeftCornerPiece = document.getElementById(topLeftCornerID);
        var topRightCornerPiece = document.getElementById(topRightCornerID);
        var bottomLeftCornerPiece = document.getElementById(bottomLeftCornerID);
        var bottomRightCornerPiece = document.getElementById(bottomRightCornerID);
        
        var adjustedWidth = 0;
        var adjustedHeight = 0;
        
        if (oImg.width > oImg.height)
        {
            adjustedWidth = Math.min(widthOfPanel, oImg.width);
            adjustedHeight = Math.min(Math.floor((adjustedWidth/oImg.width) * oImg.height), heightOfPanel);
        }
        else
        {
            adjustedHeight = Math.min(heightOfPanel, oImg.height);
            adjustedWidth = Math.min(Math.floor((adjustedHeight/oImg.height) * oImg.width), widthOfPanel);
        }
        
//        alert(oImg.width + " " + oImg.height);
//        alert(adjustedWidth + " " + adjustedHeight);
        imageInput.style.width = adjustedWidth + "px";
        imageInput.style.height = adjustedHeight + "px";
        
        if (adjustedWidth < widthOfPanel)
        {
            imageInput.style.marginLeft = Math.floor(((widthOfPanel - adjustedWidth) / 2)) + "px";
            imageInput.style.marginRight = Math.ceil(((widthOfPanel - adjustedWidth) / 2)) + "px";
            
            if (topLeftCornerPiece)
            {
                topLeftCornerPiece.style.left = Math.floor(((widthOfPanel - adjustedWidth) / 2)) + "px";
            }
            
            if (bottomLeftCornerPiece)
            {
                bottomLeftCornerPiece.style.left = Math.floor(((widthOfPanel - adjustedWidth) / 2)) + "px";
            }
            
            if (topRightCornerPiece)
            {
                topRightCornerPiece.style.right = Math.ceil(((widthOfPanel - adjustedWidth) / 2)) + "px";
            }
            
            if (bottomRightCornerPiece)
            {
                bottomRightCornerPiece.style.right = Math.ceil(((widthOfPanel - adjustedWidth) / 2)) + "px";
            }
            
        }
        
        if (adjustedHeight < heightOfPanel)
        {
            if (centeredVertically)
            {
                imageInput.style.marginTop = Math.ceil(((heightOfPanel - adjustedHeight) / 2)) + "px";
            }
            else
            {
                imageInput.style.marginBottom = Math.ceil(heightOfPanel - adjustedHeight) + "px";
            }
            
            if (bottomLeftCornerPiece)
            {
                if (!centeredVertically)
                {
                    bottomLeftCornerPiece.style.bottom = Math.ceil(heightOfPanel - adjustedHeight) + "px";
                }
                else
                {
                    bottomLeftCornerPiece.style.bottom = Math.floor(((heightOfPanel - adjustedHeight) / 2)) + "px";
                }
                
            }
            
            if (bottomRightCornerPiece)
            {
                if (!centeredVertically)
                {
                    bottomRightCornerPiece.style.bottom = Math.ceil(heightOfPanel - adjustedHeight) + "px";
                }
                else
                {
                    bottomRightCornerPiece.style.bottom = Math.floor(((heightOfPanel - adjustedHeight) / 2)) + "px";
                }
            }

            if (centeredVertically)
            {
                if (topLeftCornerPiece)
                {
                    topLeftCornerPiece.style.top = Math.ceil(((heightOfPanel - adjustedHeight) / 2)) + "px";
                }

                if (topRightCornerPiece)
                {
                    topRightCornerPiece.style.top = Math.ceil(((heightOfPanel - adjustedHeight) / 2)) + "px";
                }
            }
            
        }
    }
    
}



function addOnLoadEvent(e)
{
    var currentOnLoad = window.onload;
    
    window.onload = function() 
    {
        if (currentOnLoad)
        {
            currentOnLoad();
        }
        
        e();
    }
}

function clientHeight()
{
    var 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 myHeight;
}

function clientWidth()
{
    var myWidth = 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 getPageX(control)
{
    var x = 0;
    
    while (control)
	{
		x += parseInt(control.offsetLeft);
		control = control.offsetParent || null;
	}
	
	return x;
}

function getPageY(control)
{
    var y = 0;
    
    while (control)
	{
		y += parseInt(control.offsetTop);
		control = control.offsetParent || null;
	}
	
	return y;
}

function IsMatch(id, pattern)
{
    var regularExpresssion = new RegExp(pattern);

    return (regularExpresssion.test(id));
}

function IsCheckBox(input)
{
    return (input.type == 'checkbox');
}

function AddBookmark(title, url) {
    if (window.sidebar) {
        // Firefox
        window.sidebar.addPanel(title, url, "");
    }
    else if (window.opera && window.print) {
        // Opera
        alert('Press Ctrl+D on your keyboard to bookmark this page.');
    }
    else if (navigator.userAgent.indexOf('Safari') > -1) {
        // Safari
        alert('Press Ctrl+D on your keyboard to bookmark this page.');
    }
    else if (document.all) {
        // IE
        window.external.AddFavorite(url, title);
    }
}

function TextFieldCounter(f, cf, maxLimit) {
	var field = document.getElementById(f);
	var counterField = document.getElementById(cf);
	
	if (field.value.length > maxLimit) {
		// if too long...trim it!
		alert("You have entered " + field.value.length + " characters. You may only enter up to " + maxLimit + " characters.");
		field.value = field.value.substring(0, maxLimit);
	}
	else
	{
		// otherwise, update 'characters left' counter
		counterField.value = maxLimit - field.value.length;
	}
}

function getQuerystring(key, default_)
{
    if (default_ == null) default_ = "";
    
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if (qs == null)
        return default_;
    else
        return qs[1];
}

function SetUniqueRadioButton(nameregex, current)
{
    re = new RegExp(nameregex);

    for (i = 0; i < document.forms[0].elements.length; i++)
    {

        elm = document.forms[0].elements[i]

        if (elm.type == 'radio')
        {
            if (re.test(elm.name))
            {
                elm.checked = false;
            }
        }
    }

    current.checked = true;

}

function xor_str(inputString) 
{

    var the_res = ""; //the result will be here
    for (i = 0; i < inputString.length; ++i) {
        the_res += String.fromCharCode(xor_key ^ inputString.charCodeAt(i));
    }
    return the_res;
}

function decrypt_str(inputString) 
{
    var decryptedString = "";
    for (i = 0; i < inputString.length; i++) {
        decryptedString += String.fromCharCode(xor_key ^ inputString.charCodeAt(i));
    }

    return decryptedString;
}
 
