// <SCRIPT>
//

baseURL	=	"";

function openWindow(pageURL)
{
	return popup(pageURL, 400, 350, "newWin");
}

function popup(pageURL, width, height, targetName)
{
	targetName = targetName || 'popup';
	var popup = window.open(pageURL, targetName, 'toolbars=0,scrollbars=1,location=0,statusbars=0,menubars=0,resizable=1,width='+(width ? width : 600)+',height='+(height ? height : 420));
	return false;
}


function openWindowWH(pageURL, width, height){
	var newWin = window.open(pageURL, 'newWin', 'toolbars=no,scrollbars=yes,location=no,status=yes,menubars=no,resizable=yes,width='+ width +',height='+ height);
	return false;
}

function popupImage(imgUrl){
	width=400;
	height=450;
	window.open(baseURL+ '/asp/popup_image.asp?img=' + imgUrl, 'pop', 'toolbars=no,scrollbars=yes,location=no,status=yes,menubars=no,resizable=yes,width='+ width +',height='+ height +',top=100,left=100');
	return false;
}

function jumpMenu(select){
	strURL	=	select.options[select.options.selectedIndex].value;
	if (testNullString(strURL))
		document.location.href = strURL;
	return false;
}

function alertWindow(strAlertContent){
	
	// Create an object for a WINDOW popup
	newWin = new PopupWindow('divAlert1'); 

	// Set the window to automatically hide itself when the user clicks 
	// anywhere else on the page except the popup
	newWin.autoHide(); 

	// Hide the popup after 12 seconds
	self.setTimeout('hideAlertWindow()', 12000)  ;

	// Populate the contents of the popup window that will be shown. If you 
	// change the contents while it is displayed, you will need to refresh()
	newWin.populate(strAlertContent);

	newWin.showPopup("anchorTop");

}

function hideAlertWindow(){
	if("undefined" != typeof(newWin))
		newWin.hidePopup();
}

function getbrowserwidth(){
	if (navigator.userAgent.indexOf("MSIE") > 0)
		return(document.body.clientWidth);
	else
		return window.outerWidth;
}

function getbrowserheight(){
	if (navigator.userAgent.indexOf("MSIE") > 0)
		return(document.body.clientHeight);
	else
		return window.outerHeight;
}

function toggleVisibility(strTagId, boolFlag) {
	if(document.getElementById && document.getElementById(strTagId) != null)
		s	=	document.getElementById(strTagId).style;
	else if(document.layers && document.layers[strTagId] != null)
		s	=	document.layers[strTagId];
	else if(document.all)
		s	=	document.all[strTagId].style;

	if(boolFlag === false){
		node	=	s.display	=	"none";
	}else if(boolFlag === true){
		node	=	s.display	=	"";
	}else{
		if(s.display == "")
			node	=	s.display	=	"none";
		else
			node	=	s.display	=	"";
	}
}

function anyChecked(formItems, boolFlag){
	if(boolFlag){
		for(var counter=0; counter < formItems.length; counter++){
			formItems[counter].checked = false;
		}
	}
}
function oneChecked(i, boolFlag){
	if(boolFlag){
		i.checked	=	false;
	}
}

// LINK GENERATORS
// str = "";returnstr = "";for(counter=1; counter <= str.length; counter++){returnstr += (str.charCodeAt(counter-1) + (counter + counter/10)) + ",";}returnstr;

function cafemocha(astr, bstr){

	var a	=	astr.split(",");
	var b	=	bstr.split(",");
	
	document.write("<a href=\"");
	sodapop(a);
	document.write("\">");
	sodapop(b);
	document.write("</a>");
}

function sodapop(a){
	var b,c,d;
	
	for(var counter=0; counter < a.length; counter++){
		b	=	a[counter];
		c	=	counter+1;
		
		d	=	Math.round(b - (c + c/10));
		
		document.write(String.fromCharCode(d));
	}
}

// RETURN NULL IF THE STRING'S VALUE IS UNDEFINED, EMPTY, OR NULL
//
function testNullString(str, strAltReturn){
	var str	=	String(str);
	var strAltReturn;
	
	if(strAltReturn == undefined || strAltReturn == null)
		strReturn	=	null;
	else
		strReturn	=	strAltReturn;
	
	if(str == "undefined" || str == "null" || str == "")
		return strReturn;
	else
		return str;	
}

// UPDATES MATH.ROUND TO INCLUDE DECIMAL PLACES
//
function math_round(expression, decimalplaces, isEurope){
	var multiplier;

	if(decimalplaces != null && decimalplaces != 0)
		multiplier = Math.pow(10, decimalplaces);
	else
		multiplier	=	1;

	strExpression	=	String(expression);
	
	if(isEurope){

		if(strExpression.indexOf(".") != -1)
			strExpression	=	strExpression.replace(/\./g, "");
		
		expression	=	strExpression.replace(/,/, ".").replace(/,/g, "");
			
	}else{
		if(strExpression.indexOf(",") != -1)
			expression	=	strExpression.replace(/,/g, "");
	}
	
	if(isNaN(parseFloat(expression)))
		expression	=	0;
	else
		expression	=	parseFloat(expression) * 1;
	
	return Math.round(expression * multiplier)/multiplier;
}

// FORMAT THE NUMBER TO SHOW 2 DIGITS PAST THE DECIMAL PLACE
//
function priceFormat(n, isSplitThousands){
	
	var n,nstr;
	
	n		=	math_round(n,2)+.001;
	nstr	=	String(n);
	nstr	=	nstr.substring(0, nstr.indexOf(".") + 3);
	
	if(!isSplitThousands)
		return nstr;
	else
		return (splitThousands(nstr, ",") + jsRight(nstr, 3));
		
}

	// FORMAT INPUT NUMBER USING SEPARATOR TO MARK THOUSANDS
	//
	function splitThousands(input, strSeparator, numDigitsAfterDecimal, incLeadingDig, parenForNegatives){
		var retVal = numberFormat(input, strSeparator, numDigitsAfterDecimal, incLeadingDig, parenForNegatives);
		return testNullString(retVal, "");
	}
	function numberFormat(origInput, strSeparator, numDigitsAfterDecimal, incLeadingDig, parenForNegatives) {

		if(origInput){
			
			//european assumption -- that is, if the thousands separator is a period, the decimal sep will be a comma
			var decSeparator ="."
			if(strSeparator == "."){
				decSeparator	=	",";
				
				var input		=	testNullString(origInput, "0");
				var intPart		=	numDigitsAfterDecimal ? origInput.replace(/,\d*$/, "").replace(/\D/g, "") : Math.abs(math_round(origInput, 0, true));
				var decimalPart	=	numDigitsAfterDecimal ? origInput.replace(/^.*,/, "").replace(/\D/g, "") : "";//make it a number like 0.232
				var output		=	"";
			
			}else{
				strSeparator	=	",";
				
				var input		=	testNullString(origInput, "0");
				var intPart		=	numDigitsAfterDecimal ? origInput.replace(/\.\d*$/, "").replace(/\D/g, "") : Math.abs(math_round(origInput));
				var decimalPart	=	numDigitsAfterDecimal ? origInput.replace(/^.*\./, "").replace(/\D/g, "") : "";//make it a number like 0.232
				var output		=	"";
			}
			
			if(!math_round(intPart)){
				if(!incLeadingDig)
					intPart = "";
				else
					intPart = "0";
			}else{
				
				intPart = String(intPart);

				for(var counter = intPart.length; counter > 0; counter--){
					output = ((counter != 1 && counter != intPart.length + 1 && (intPart.length - counter + 1) % 3 == 0) ? strSeparator : "" ) + intPart.charAt(counter - 1) + output;
				}
			}
			
			if (numDigitsAfterDecimal){
				if(math_round(decimalPart))
					decimalPart = math_round(decimalPart * Math.pow(10, numDigitsAfterDecimal - String(decimalPart).length));
				else
					decimalPart = String(Math.pow(10, numDigitsAfterDecimal)).substring(1);
				
				output += decSeparator + decimalPart;
			}
			
			//handle how negative numbers are displayed
			if (testNullString(origInput,"").search(/^-/) != -1 && output){
				if(parenForNegatives)
					output = "("+(output.replace(/-/,""))+")";	
				else
					output = "-"+output;//add negative sign back if necessary	
			}
				
			return output;
		}
		return;
	}

function changeURL(strURL, strQueryStringChanges){

		var strItem, strItemValue, reItemValue, strHash;
		var strURL					=	strURL;
		var isQueryString			=	(strURL.indexOf("?") != -1);
		if(strURL.indexOf("#") != -1){
			strHash	=	strURL.substring(strURL.indexOf("#"));
			strURL	=	strURL.substring(0,strURL.indexOf("#"));
		}
		if(strQueryStringChanges.indexOf("#") != -1){
			strHash						=	strQueryStringChanges.substring(strQueryStringChanges.indexOf("#"));
			strQueryStringChanges	=	strQueryStringChanges.substring(0,strQueryStringChanges.indexOf("#"));
		}
		var aQueryStringChanges	=	strQueryStringChanges.split("&");
		
		// CHECK FOR EXISTING QUERYSTRING
		if(isQueryString){
			var strScriptName		=	strURL.substring(0, strURL.indexOf("?"));
			var strQueryString	=	strURL.substring(strURL.indexOf("?"));
		}else{
			var strScriptName		=	strURL;
			var strQueryString	=	"";
		}
		
		for(var counter=0; counter < aQueryStringChanges.length; counter++){
			strItemValue	=	String(aQueryStringChanges[counter]);
			strItem			=	strItemValue.substring(0, strItemValue.indexOf("="));
			reItemValue		=	new RegExp("([\?&])"+ strItem +"=[^&]*", "i");
			
			// CHECK FOR BLANK VALUES
			if(strItemValue.indexOf("=") + 1 == strItemValue.length)
				strItemValue	=	"";

			if(strQueryString.search(reItemValue) != -1){
		
				if(strItemValue.indexOf("order=") != -1 && strQueryString.indexOf(strItemValue.replace(/\*/g,"")) != -1){
					if(strItemValue.indexOf("*ASC*") != -1)
						strItemValue	=	strItemValue.replace(/\*ASC\*/gi, "DESC");
					else if(strItemValue.indexOf("*DESC*") != -1)
						strItemValue	=	strItemValue.replace(/\*DESC\*/gi, "ASC");
				}
				strQueryString		=	strQueryString.replace(reItemValue, "$1"+ strItemValue);
			}else if(strItemValue != "" && !isQueryString){
				strQueryString		+=	String("?" + strItemValue);
				isQueryString		=	true;
			}else if(strItemValue != "" && isQueryString)
				strQueryString		+=	String("&" + strItemValue);
		}
		
		// REPLACE TRAILING FIGURES, AND DOUBLE FIGURES
		strQueryString	=	strQueryString.replace(/\*ASC\*/g, "ASC");
		strQueryString	=	strQueryString.replace(/\*DESC\*/g, "DESC");
		strQueryString	=	strQueryString.replace(/^\?&+/, "?");
		strQueryString	=	strQueryString.replace(/&{2,}/g, "&");
		strQueryString	=	strQueryString.replace(/(?:&|\?)$/, "");
		
		strURL	=	strScriptName.concat(strQueryString);
		
		if(strHash){
			strURL	=	changeURL(changeURL(strURL, "1="), "1=1").concat(strHash);
		}
		
		return strURL;
	}
	
	function getDateString(y_obj,m_obj,d_obj) {
		var y = y_obj.options[y_obj.selectedIndex].value;
		var m = m_obj.options[m_obj.selectedIndex].value;
		var d = d_obj.options[d_obj.selectedIndex].value;
		if (y=="" || m=="") { return null; }
		if (d=="") { d=1; }
		return str= y+'-'+m+'-'+d;
	}
	
// ADD BOOKMARK
// By Eddie Traversa
// ADD BOOKMARK
function addBookmark()
{
	if (window.sidebar && window.sidebar.addPanel)
	{
		//Gecko (Netscape 6 etc.) - add to Sidebar
		window.sidebar.addPanel(this.title, 'http://www.galleriapangaea.com/', '');
	}
	else if (window.external && (navigator.platform == 'Win32' || (window.ScriptEngine && ScriptEngine().indexOf('InScript') + 1)))
	{
		//IE Win32 or iCab - checking for AddFavorite produces errors in
		//IE for no good reason, so I use a platform and browser detect.
		//adds the current page page as a favourite; if this is unwanted,
		//simply write the desired page in here instead of 'location.href'
		window.external.AddFavorite('http://www.galleriapangaea.com/', document.title);
	}
	else if (window.opera && window.print)
	{
		//Opera 6+ - add as sidebar panel to Hotlist
		return true;
	}
	else if (document.layers)
	{
		//NS4 & Escape - tell them how to add a bookmark quickly (adds current page,
		//not target page)
		alert('Please click OK then press Ctrl+D to create a bookmark');
	}
	else
	{
		//other browsers - tell them to add a bookmark (adds current page, not target page)
		alert('Please use your browser\'s bookmarking facility to create a bookmark');
	}
	return false;
}

function custom_print() {
    self.print();
    return false;
}

function addTitle(strUrl)
{
	strUrl = '/send_to_friend.asp?url='+ strUrl +"&title="+ escape(document.title);
	document.location.href = strUrl;
	return false;
}

//
// </SCRIPT>
