/*
openwindow.js - 1/10/08 - JAC
method summary - 
EVENT="return spawnWindow(keyword, loc, destWin);"
	keyword - "form", "mediasmall", "mediabig", "standard", "big", "max", or string of attributes, i.e., 'width=800,height=600,status=no,toolbar=no'.
	loc - 	  destination URL, i.e., "this.href" or "http://www.ibx.com".
	destWin - window.name property. Used to specify unique target window.
Documentation can be found at http://www.ibx.com/htdocs/generic_spawnwin_test.html
*/
function childWindow(strURL, strName, strChildType) {
	var e; //Dummy for Error Code
	
	//Property initialization
	this.url = strURL;
	this.name = strName;
	this.childType = strChildType;
	this.child = null;
	this.alwaysRaised = 'no';
	this.copyhistory = 'yes';
	this.height = '';
	this.left = 0;
	this.location = 'no';
	this.menubar = 'no';
	this.resizable = 'yes';
	this.scrollbars = 'yes';
	this.status = 'yes';
	this.toolbar = 'yes';
	this.width = '';
	this.top = 0;	
	this.strAttributes = '';
	
	try {
		if (typeof this.childType != 'undefined') 
			switch(this.childType.toLowerCase()) {
				case 'form':
					this.width = 530;
					this.height = 400;
					this.status = 'no';
					this.toolbar = 'no';
					this.left = screen.availWidth/3;
					this.height = screen.availHeight/3;
					break;
				case 'mediasmall':
					this.width = 300;
					this.height = 300;
					this.resizable = 'no';
					this.scrollbars = 'no';
					this.status = 'no';
					this.toolbar = 'no';
					this.copyhistory = 'no';
					break;
				case 'mediabig':
					this.width = 500;
					this.height = 400;
					this.resizable = 'no';
					this.scrollbars = 'no';
					this.status = 'no';
					this.toolbar = 'no';
					this.copyhistory = 'no';
					break;
				case 'standard':
					this.width = 800;
					this.height = 600;
					this.location = 'yes';
					this.menubar = 'yes';
					break;
				case 'big':
					this.width = 1024;
					this.height = 768;
					this.location = 'yes';
					this.menubar = 'yes';
					break;
				case 'max':
					this.height = screen.availHeight-48;
					this.width = screen.availWidth-8;
					this.toolbar = 'no';
					break;
				case 'notice':
					this.width = 460;
					this.height = 460;
					this.location = 'yes';
					this.menubar = 'yes';
					break;
				default:
					this.strAttributes = this.childType.toLowerCase();
					//throw(null);
					break;
			}
		else 
			throw(null);		
	}
	catch(e) {
		this.height = 800;
		this.width = 600;
		this.menubar = 'yes';
		this.resizable = 'yes';
		this.scrollbars = 'yes';
		this.status = 'yes';
		this.toolbar = 'yes';
		this.location = 'yes';
	}
	
	function childWindowOpen() {
		var e;
		if (this.strAttributes.indexOf("alwaysRaised") == -1) this.strAttributes += 'alwaysRaised=' + this.alwaysRaised;
		if (this.strAttributes.indexOf("copyhistory") == -1) this.strAttributes += ',copyhistory=' + this.copyhistory;
		if (typeof this.height == 'number')
			if (this.height > 0 && this.strAttributes.indexOf("height") == -1)
				this.strAttributes += ',height=' + this.height;
		
		if (this.strAttributes.indexOf("left") == -1) this.strAttributes += ',left=' + this.left;
		if (this.strAttributes.indexOf("location") == -1) this.strAttributes += ',location=' + this.location;
		if (this.strAttributes.indexOf("menubar") == -1) this.strAttributes += ',menubar=' + this.menubar;
		if (this.strAttributes.indexOf("resizable") == -1) this.strAttributes += ',resizable=' + this.resizable;
		if (this.strAttributes.indexOf("scrollbars") == -1) this.strAttributes += ',scrollbars=' + this.scrollbars;
		if (this.strAttributes.indexOf("status") == -1) this.strAttributes += ',status=' + this.status;
		if (this.strAttributes.indexOf("toolbar") == -1) this.strAttributes += ',toolbar=' + this.toolbar;
		if (this.strAttributes.indexOf("top") == -1) this.strAttributes += ',top=' + this.top;
		
		if (typeof this.width == 'number' && this.strAttributes.indexOf("width") == -1)
			if (this.width > 0)
				this.strAttributes += ',width=' + this.width;
		
		//try to open a child window
		try {
			this.child = window.open(this.url, this.name, this.strAttributes);
			if (window.opener.name == this.name)
				this.child = window.opener;
			else 
				if (window.opener.opener.name == this.name)
					this.child = window.opener.opener;
				else
					if (window.opener.opener.opener.name == this.name)
						this.child = window.opener.opener.opener;
			this.focus();
		}
		catch(e) {
			this.focus;
		}
	}
	
	function childWindowClose() {
		var e;
		try {
			this.child.close();
		}
		catch(e) {}
	}
	
	function childWindowFocus() {
		this.child.focus();
	}
	
	//Method initialization
	this.open = childWindowOpen;
	this.close = childWindowClose;
	this.focus = childWindowFocus;
	
}

function spawnWindow(keyword, loc, destWin) {
	var child = new childWindow(loc, destWin, keyword);
	child.open();
	return false;
}



function spawnModWindow(elementId, params) {
	if (typeof(params) == 'undefined') params = {};//Check for existance of custom params
	// Begin default params
	var thisWidth = (typeof(params.width) == 'number') ? params.width + 'px' : params.width || '300px';
	var thisHeight = (typeof(params.height) == 'number') ? params.height + 'px' : params.height || 'auto';
	var thisPadding = (typeof(params.padding) == 'number') ? params.padding + 'px' : params.padding || '10px';
	var thisBorder = params.border || 'solid 1px #000';
	var thisBackground = params.background || '#FFF';
	var thisKeyName = params.keyName || false;
	var thisKeyValue = params.keyValue || false;
	var thisRandom = params.random || 0;
	// End default params
	if (!thisKeyName || readCookie(thisKeyName) != thisKeyValue) {
		if (Math.floor(Math.random()*thisRandom) != 0) return;
		baseElement = document.getElementById(elementId);
		contentString = baseElement.innerHTML;
		baseElement.innerHTML = "<div class='modularWindowBg' style='display: block; width: 100%; height: 100%; background-color: #000000; /* for IE */ filter:alpha(opacity=60); /* CSS3 standard */ opacity:0.6; position: fixed; top: 0px; left: 0px;'></div><div id='modularWindowContainer' style='display: block; position: absolute; border: " + thisBorder + "; width: " + thisWidth + ";'><div id='modularWindowContent' style='background: " + thisBackground + "; padding: " + thisPadding + ";'>" + contentString + "</div></div>";
		if( typeof( window.innerWidth ) == 'number' ) {
			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;
		}	
		baseElement.style.display = "inline";
		var scrollPos = (document.all) ? ((document.documentElement) ? document.documentElement.scrollTop : document.body.scrollTop) : window.pageYOffset;
		document.getElementById('modularWindowContainer').style.top = myHeight/2 - document.getElementById('modularWindowContent').offsetHeight/2 + scrollPos + "px";
		document.getElementById('modularWindowContainer').style.left = myWidth/2 - document.getElementById('modularWindowContent').offsetWidth/2 + "px";
	
		var date = new Date();
		date.setFullYear(2100);//set the cookie's expiration to sometime well into the future
		if (thisKeyName) document.cookie = thisKeyName + "=" + thisKeyValue + "; expires=" + date.toGMTString() + "; path=/";
	}
} 

function closeModWindow(elementId) {
	baseElement = document.getElementById(elementId);
	baseElement.style.display = 'none';
	baseElement.innerHTML = contentString;
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}




//
// Specialized calls migrated from old script - JC
//
// 1/21/2005 - bahnck
function spawnDisclaimerWindow(destPage) {
  if (!(destPage)) { return false; }
  var newWin = window.open("/htdocs/legal/external_link_disclaimer.html" + "?dest=" + destPage, "discWindow");
}

function disclaimerProceed() {
  if (location.search != "?" && location.search != "") {
    location.href = location.search.substring(6);  
  }
  return false;
}

function spawnExtWindow(url) {
	var ExternalWindow = window.open(url, "BigWindow","width=800,height=600,location=yes,menubar=yes,scrollbars=yes,toolbar=yes,resizable=yes");
	return false;
}

/**
 * Added 10/15/2004 - bahnck
 * Rewrites ibxpress login page hostname based on current hostname. If on live
 * or unrecognized server, this opens the url passed unmodified.  
 */
function spawnLoginWindow(loginBox) {
  if (!loginBox) { return false; }
  
  // DEBUG: override hostname detection
  // loginServerCurr = "";
  
  if (typeof loginServerCurr != "undefined") {
    loginBox.action = loginServerCurr;
  }
  // loginBox.target = "_blank";

  return true;
} // end spawnLoginWindow 
 
/**
 * Added 10/01/2004 - bahnck
 * Rewrites form page hostname based on current hostname. If on live
 * or unrecognized server, this opens the url passed unmodified.  
 */

function spawnSecureWindow(url) {
  if (!url) { return false; }
  var modUrl = url;
  
  // DEBUG: override hostname detection
  // secureServerCurr = "";
  
  if (typeof secureServerCurr != "undefined") {
    modUrl = url.substr(0, url.indexOf(secureServerLive));
    modUrl += secureServerCurr;
    modUrl += url.substr(url.indexOf(secureServerLive) + secureServerLive.length);
  }
  
  var ExternalWindow = window.open(modUrl, "BigWindow", "width=800,height=600,location=yes,menubar=yes,scrollbars=yes,toolbar=yes,resizable=yes");
  return false;
} // end spawnSecureWindow

function spawnFlexPlanWindow(url) {
  if (!url) { return false; }
  var modUrl = url;
  
  // DEBUG: override hostname detection
  // secureServerCurr = "";
  
  if (typeof secureServerCurr != "undefined") {
    modUrl = url.substr(0, url.indexOf(secureServerLive));
    modUrl += secureServerCurr;
    modUrl += url.substr(url.indexOf(secureServerLive) + secureServerLive.length);
  }
  
  var ExternalWindow = window.open(modUrl, "FlexPlanWindow", "width=750,height=525,location=yes,menubar=yes,scrollbars=yes,toolbar=yes,resizable=yes");
  return false;
} // end spawnFlexPlanWindow

function closeWindow() {
	self.close();
}

function openInParent(sURL) {
	window.opener.location.href = sURL;
	self.close();
}

function jumpToSubmit(){
	//alert("here should be");
    var index1= document.getElementById("findPlanCoverage").selectedIndex;
    var index2 =document.getElementById("findPlanState").selectedIndex;
	if((index1 >0)&& index2>0  ){	 	  	
	 	 document.getElementById("findaPlan").submit();
	 	 }
}

function jumpTo(what,size){
	var size = size;
	//alert("size="+size);
    var index =what.selectedIndex;
   // alert(index);
	if(index >0 ){	
		 document.getElementById("planCoverage").value = size;
		 document.getElementById("planState").value = what.value;
		// alert(document.getElementById("planState").value );
		//alert(document.getElementById("findaPlan").action);
	 	 document.getElementById("findaPlan").submit();
	 	 }
}
function newWindow(url,w,h)
	{
	var winProps = 'width=' + w + ',' + 'height=' + h + ',' + 'resizable=yes,scrollbars=yes';
	window.open(url, 'new', winProps);
	}

function backPlanSearchResult(){
	var strHref = window.location.href;	
	var index ;	 
	var state;
	var size;
	index = strHref.lastIndexOf("/");
	strHref = strHref.substring(0,index);	
	index = strHref.lastIndexOf("/");
	size = strHref.substring(index+1); 	
	strHref = strHref.substring(0,index); 	
	index = strHref.lastIndexOf("/");
	state = strHref.substring(index+1);
	var url = '../../searchPlanResults.html?planState='+state+'&planCoverage='+size;
	window.location.href = url;
	return false;
}
 function spawnSendpageWindow() {
 var title = document.title;
  spawnSecureWindow("https://ecom.ibx.com/ibx/jsps/sendpage/sendpage.jsp?requesturl=" + window.location +"&pagetitle="+ title, "pageWindow");
}
