/***************************************************************
GENERAL PURPOSE SCRIPT API - This script contains all commonly used
javascript functionality that can be used on any page throughout
the site.
****************************************************************/
var browser = new Browser();

function FlipText(e){
	if(e.hold == null){
		e.hold = e.value;
		e.value = "";
		return;
	}
	if(e.value == e.hold)
		e.value = "";
}
function UnflipText(e){
	if(e.hold != null && e.value == "")
		e.value = e.hold;
}
	
function GetCallingElement(){
	if(this.browser.IE)
		return event.srcElement;
	else
		return Event.target;
}
function Redirect(url){
	window.location = url;
}
function FlipChild(e){
	if(e.children.length == 0)
		return;
	e = e.children[0];
	
	var disp = "block";
	if(e.style.display == "block")
		disp = "none";
	e.style.display = disp;
}
function FlipElementByID(id){
	var e = document.getElementById(id);
	var disp = "block";
	if(e.style.display == "block")
		disp = "none";
	e.style.display = disp;
}

///TRIGGER A POSTBACK
function Submit(){
	var f = document.forms["Form"];
	if(f == null) 
		f = document.Form; 
	if(f == null) 
		f = document.forms[0]; 
	f.submit();
	
}
/***************************************************************
TRACING - This is a simple tracing/debugging mechanism used
to display and track information by any script on the site.

To enable tracing, simply call EnableTracing() from the onload 
event of the <body> tag. (e.g. <body onload='EnableTracing();'>...)

To disable tracing, call DisableTracing()
****************************************************************/
var trace;
function EnableTracing(){
	trace = new Tracing();
	trace.Enable();
	window.onerror = WriteEx;
}
function DisableTracing(){
	if(trace == null)
		return;
	trace.Disable();
}
function Write(msg){
	if(trace == null)
		return;
	trace.Write(msg);
}
function WriteEx(ex){
	if(trace == null)
		return false;
	trace.WriteEx(ex);
	return true;
}
function MinimizeWindow(){
	if(trace == null)
		return;
	trace.Minimize();
}
function Tracing(){
		var width = '100%';
		var max_height = '300px';
		var min_height = '25px'
		var right = '0px';
		var bottom = '0px';
		var bg = '#EEF';
		var zIndex = '10000000';
		var position = 'absolute';
		var id = 'edifice_tracer';
		var list;
		var div;
		function enable(){	
			list = document.createElement("select");
			list.id = id;
			list.style.bottom = bottom;
			list.style.right = right;
			list.style.position = position;			
			list.style.width = width;
			list.style.height = min_height;	
			list.multiple = "true";
			list.style.borderStyle = 'solid';
			list.style.borderWidth = '1px';
			list.style.borderColor = 'black';
			list.style.zindex = zIndex;
			list.style.backgroundColor = bg;
			list.onmouseover = Expand;
			list.onmouseout = Contract;
			document.body.appendChild(list);
			window.onerror = writeEx;
		}
		function Expand(){
			list.style.height = max_height;
		}
		function Contract(){
			list.style.height = min_height;
		}
		function write(msg){
			var newOption = new Option();
			newOption.text = msg;
			newOption.value = msg;
			list.options.add(newOption);
			Expand();
			window.setTimeout("MinimizeWindow();",500);
		}
		function writeEx(ex){
			var o = new Option();
			o.text = 'ERROR: '+ex;
			list.options.add(o);
			Expand();
			window.setTimeout("MinimizeWindow();",500);
		}

		function disable(){
			document.body.removeChild(list);
			list = null;
		}
		this.Enable = enable;
		this.Disable = disable;
		this.Write = write;
		this.WriteEx = writeEx;
		this.Minimize = Contract;
}

function Browser(){
	var ie = false;
	var moz = false;
	
	function detect(){
		var agt = navigator.userAgent.toLowerCase();
		if(agt.indexOf('msie') > -1)
			ie = true;
		else
			moz = true;
	}
	function type(){
		if(ie)
			return "IE";
		else
			return "MOZILLA";
	}
	detect();
	this.IE = ie;
	this.MOZ = moz;
	this.Type = type;
}

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_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_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.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];}
}
/***********************************************
* IFrame SSI script II- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/
//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
var iframeids=["myframe","relatedItemsFrame"]

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes"

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i])
//reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide=="no"){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display="block"
}
}
}

function resizeIframe(frameid){
var currentfr=document.getElementById(frameid);
if (currentfr && !window.opera){
currentfr.style.display="block"
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
else if (currentfr.contentWindow) //ie5+ syntax
currentfr.style.height=this.document.body.scrollHeight+"px"; 
if (currentfr.addEventListener)
currentfr.addEventListener("load", readjustIframe, false)
else if (currentfr.attachEvent){
currentfr.detachEvent("onload", readjustIframe) // Bug fix line
currentfr.attachEvent("onload", readjustIframe)
}
}
}

function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot)
resizeIframe(iframeroot.id);
}
//Used in Brand / Event Dropdowns
function loadintoMainIframe(iframeid, url){
if (parent.document.getElementById && url !="-1")
parent.document.getElementById(iframeid).src=url
}

function resetDropdownList(objName){
var brandObj = document.getElementById("ddlBrands");
var eventObj = document.getElementById("ddlEvents");
if(objName=="ddlBrands" && brandObj.selectedIndex !=0){
eventObj.selectedIndex=0;
eventObj.focus()=false;
}
if(objName=="ddlEvents" && eventObj.selectedIndex !=0){
brandObj.selectedIndex=0;
brandObj.focus()=false;
}
}

function resetDropdownListFromParent(){
var brandObj = parent.frames['mydropdownframe'].document.getElementById('ddlBrands');
var eventObj = parent.frames['mydropdownframe'].document.getElementById('ddlEvents');
if(brandObj.selectedIndex !=0){
brandObj.selectedIndex=0;
}
if(eventObj.selectedIndex !=0){
eventObj.selectedIndex=0;
}
}

function loadintoIframe(iframeid, url){
if (document.getElementById)
parent.document.getElementById(iframeid).src=url;
}

//Used in LDA and called from the onload 
function checkLocation(){
if(window.name =="myframe"){
//alert(window.name);
window.parent.location.href="./LDA/LDA.jsp";
}
}


//if (window.addEventListener)
//window.addEventListener("click", redirectCaller, false)
//else if (window.attachEvent)
//window.attachEvent("click", redirectCaller)
//else
//window.click=redirectCaller
