// New Window
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


// Image Swap Function
function doDetailSwap(newVal, newImage, id)
{
	if (newVal.length)
	{
		var colorSwap = document.getElementById(id);
		colorSwap.src = '/_media/' + newImage + '.jpg';
	}
}


// INPUT BOX CLEAR

function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

// PRINT FUNCTIONS

function printit(){  
	if (window.print) {
	    window.print() ;  
	} else {
	    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
	document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
	    WebBrowser1.ExecWB(6, 2); //Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
	}
}

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=330,height=335,left = 325,top = 120');");
}

function printFrame(iFr) {
	window.top[iFr].focus();
	window.top[iFr].print();
}

function printDiv(id) {
	var content = document.getElementById(id).innerHTML
	tmpStr = "location=no,menubar=no,directories=no,toolbar=no,status=no,personalbar=no,titlebar=no,scrollbars=yes,dependent=yes,resizable=yes";
	
	newWindow=window.open('','newWin',tmpStr);
	newWindow.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><title>Print Page<\/title><link href="/_media/_css/main.css" rel="stylesheet" type="text/css" media="all"><link href="/_media/_css/printable.css" rel="stylesheet" type="text/css" media="all"><link href="/_media/_css/print_hide.css" rel="stylesheet" type="text/css" media="print"><link href="/_media/_css/sIFR-print.css" rel="stylesheet" type="text/css" media="all"><script type="text/javascript" src="/_media/_js/main.js" language="javascript"></script><\/head><body><div id="printable_buttons"><div style="float:left;"><input type="button" name="print" value="SEND TO PRINTER" onclick="printit();return false;" class="btn" \/><\/div><div align="right"><input type="button" name="close" value="CLOSE WINDOW" onclick="window.close();return false;" class="btn" \/><\/div><\/div><div style="height: 20px;"><\/div>'+content+'<\/body><\/html>');
	
	winStatus = 1;
	
	newWindow.document.close();
	newWindow.focus();
}

// POP-UP DIV HANDLERS

function doMeasure() {
	var doc;

	if (document.documentElement) { // poor-man's check for DOC TYPE
		doc = top.document.documentElement;
	} else {
		doc = document.body;
	}

	var obj = new Object();

	obj.scrollTop = doc.scrollTop;
	obj.scrollHeight = doc.scrollHeight;
	obj.winWidth = doc.clientWidth;
	obj.winHeight = doc.clientHeight;
	
	return obj;
}

function doScrn() {
	var obj = doMeasure();

	var popScrn = top.document.getElementById('popScrn');
	var popFrame = top.document.getElementById('popFrame');
	
	popFrame.style.display = 'block';
	popFrame.style.height = obj.scrollHeight+'px';
	
	popScrn.style.display = 'block';
	if (obj.winHeight <= obj.scrollHeight) {
		popScrn.style.height = obj.scrollHeight+'px';
	} else {
		popScrn.style.height = obj.winHeight+'px';
	}
	
	// alert("winHeight: "+obj.winHeight+" | scrollHeight: "+obj.scrollHeight+" | scrollTop: "+obj.scrollTop);
	
	return obj;
}

function showInfo(id,wd,ht,frm,src) {
	var obj = doScrn();
	
	var popDiv = top.document.getElementById(id);
	popDiv.style.display = 'block';
	
	xPos = (obj.winWidth - wd)/2;
	yPos = (obj.winHeight - ht)/2 + obj.scrollTop;

	popDiv.style.left = xPos+'px';
	popDiv.style.top = yPos+'px';
	
	if (frm) {
		var popBody = top.document.getElementById(frm);
		popBody.innerHTML = '<iframe src='+src+' name="srcFrame" id="srcFrame" width='+wd+' marginwidth="0" height='+ht+' marginheight="0" scrolling="auto" frameborder="0"></iframe>';
	}
}

function showPop(path,thumb,factor,caption,div) {
	var obj = doScrn();
	
	if (!caption) {
		caption = '';
	}
	if (!div) {
		div = 'popDiv';
	}	

	var popDiv = top.document.getElementById(div);
	var popCaption = top.document.getElementById('popCaption');
	var imgLarge = top.document.getElementById('largeImg');
	var imgThumb = top.document.getElementById(thumb);	
	var imgWidth = ((imgThumb.width)*factor);
	var imgHeight = ((imgThumb.height)*factor);
	
	imgLarge.src = path;	
	popDiv.style.display = 'block';
	
	capWidth = imgWidth + 40; // added width is determined by popDiv padding in stylesheet
	popCaption.style.width = capWidth+'px';
	popCaption.innerHTML = caption;
	
	xPos = (obj.winWidth - imgWidth)/2;
	yPos = (obj.winHeight - imgHeight)/2 + obj.scrollTop;

	popDiv.style.left = xPos+'px';
	popDiv.style.top = yPos+'px';
	
	//alert ('div width: '+imgWidth+' | div height: '+imgHeight+' | caption width:'+capWidth+'');
}

function hidePop(id) {
	if (!id) {
		id = 'popDiv';
	}
	top.document.getElementById('popFrame').style.display='none';
	top.document.getElementById('popScrn').style.display='none';
	top.document.getElementById(id).style.display = 'none';
	top.document.getElementById('largeImg').src = '/_media/spacer.gif';
}

function showME(id) {
	document.getElementById(id).style.display = 'block';
}

function hideME(id) {
	document.getElementById(id).style.display = 'none';
}

function showLarge(imgsrc,imgcap,id) {
	var caption = document.getElementById(imgcap).innerHTML;
	var thumb = document.getElementById(imgsrc);
	var src = thumb.getAttribute('src');
	var imgWidth = ((thumb.width)*3.33);
	var imgHeight = ((thumb.height)*3.33);
	var fileName = src.substring(src.lastIndexOf('/'), src.length);
	var path = 'http://creativegrids.caxiamgroup.net/_media/'+fileName;
	//document.getElementById(large).style.backgroundImage = 'url('+path+')';
	showPop(imgWidth,imgHeight,path,caption);
}

// BASIC SHOW/HIDE
function showHide(event,node) {
	event.cancelBubble=true;
	document.getElementById(node).style.display =
		 (document.getElementById(node).style.display == "none")?"":"none";
	event.cancelBubble=true;
}
