// new popup window script
// finds all links with rel="popup" and assigns popup function and optionally adds popup icon to link
// also finds all PDF links and adds PDF icon

// main event listener for user input
// used to activate popups
function addEvent(elm, evType, fn, useCapture){if(elm.addEventListener){elm.addEventListener(evType, fn, useCapture);return true;}else if (elm.attachEvent){var r = elm.attachEvent('on' + evType, fn);return r;}else{elm['on' + evType] = fn;}}

var newWindow = null;

function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	
	closeWin();
		
	type = type.toLowerCase();
	
	if (type == "fullscreen"){
		strWidth = screen.availWidth;
		strHeight = screen.availHeight;
	}
	var tools="";
	if (type == "standard") tools = "resizable,toolbar=no,location=no,scrollbars=yes,menubar=no,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console" || type == "fullscreen") tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=0,top=0";
	if (type == "gift") tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+500+",height="+500+",left=0,top=0";
	if (type == "window") tools = "";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}

function doPopUp(e)
{
//set defaults - if nothing in rel attrib, these will be used
var t = "standard";
var w = "450";
var h = "450";
//look for parameters
attribs = this.rel.split(" ");
if (attribs[1]!=null && attribs[1]!="noicon") {t = attribs[1];}
if (attribs[2]!=null && attribs[1]!="noicon") {w = attribs[2];}
if (attribs[3]!=null && attribs[1]!="noicon") {h = attribs[3];}
//call the popup script
popUpWin(this.href,t,w,h);
//cancel the default link action if pop-up activated
if (window.event) 
	{
	window.event.returnValue = false;
	window.event.cancelBubble = true;
	} 
else if (e) 
	{
	e.stopPropagation();
	e.preventDefault();
	}
}

function findPopUps()
{
var popups = document.getElementsByTagName("a");
for (i=0;i<popups.length;i++)
	{
	if (popups[i].rel.indexOf("popup")!=-1)
		{
		// attach popup behaviour
		popups[i].onclick = doPopUp;
		// add popup indicator
		if (popups[i].rel.indexOf("noicon")==-1)
			{
			popups[i].className = "noUnderline"
			popups[i].innerHTML = "<span class=\"underline\">" + popups[i].innerHTML
			popups[i].innerHTML += "</span>&nbsp;<img src=\"/images/popup.jpg\"/>";
			} 
		// add info to title attribute to alert fact that it's a pop-up window
			popups[i].title = popups[i].title + " [Opens in pop-up window]";
		}
	if(popups[i].href.indexOf(".pdf")!=-1)
		{
		if (popups[i].rel.indexOf("noicon")==-1)
			{
			popups[i].className = "noUnderline"
			popups[i].innerHTML = "<span class=\"underline\">" + popups[i].innerHTML
			popups[i].innerHTML += "</span>&nbsp;<img class=\"javascriptImage\" src=\"/images/pdficon_small.gif\"/>";
			}
		// add info to title attribute to alert fact that it's a pop-up window
		popups[i].title = popups[i].title + " [Opens in new window]";
		popups[i].target = "_blank";
		}
	}
}

addEvent(window, 'load', findPopUps, false);


// old popup window script
function additional_info(url, width, height){
	if (width == undefined)
	{
		width = "450";
	}
	
	if (height == undefined)
	{
		height = "450";
	}

  window.open(url,"_blank","toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, width=" + width + ", height=" + height + "")
}

function img_act(imgName)
{
	if (document.images) 
	{
		turnon(imgName);
	}
}

function img_inact(imgName)
{
	if (document.images) 
	{
		turnoff(imgName);
	}			
}

function img_click(imgName)
{
	if (document.images) 
	{
		turnoff(imgName);
	}			
}
/*
function img_click(imgName)
{
	if (document.images) 
	{
		document[imgName].src = eval(imgName + "click.src");
		
		if (imageStay != imgName)
		{
			if (imageStay != "")
			{ document[imageStay].src = eval(imageStay + ".src"); }
		}
		imageStay = imgName;
	}
}
*/

function turnon(name)
{
	if(imagestay != name)
	{
		document [name].src = eval(name + "on.src");
	}
}

function turnoff(name)
{
	if(imagestay != name)
	{
		document [name].src = eval(name + "off.src");
	}
}


function goSearch() {
	
	if(document.atomz.elements[0].value == '') {
		alert('Search cannot be blank. Please enter a keyword.');
		document.atomz.elements[0].focus();
	} else {
		document.atomz.submit();
	}
}
function openWin(URL) {
   mapWindow = window.open(URL,
     "mapWin","width=400,height=130,scrollbars=no");
}

function zoom(sku)
{
	var url = './zoom.jsp?sku=' + sku;
	if((window.windowZoom) && (!windowZoom.closed))
	{
		windowZoom.location.href= url;
		setTimeout('windowZoom.focus()',500);
	}
	else
	{
		windowZoom = window.open(url,"zoom_window", "status=no,toolbar=no,location=no,menubar=yes,scrollbars=yes, resizable=no,width=450,height=450,left=0,top=0,screenX=0,screenY=0");
		setTimeout('windowZoom.focus()',500);
	}
}

function zoomjsp(sku)
{
	var url = './' + sku + '-zoom.jsp';
	if((window.windowZoom) && (!windowZoom.closed))
	{
		windowZoom.location.href= url;
		setTimeout('windowZoom.focus()',500);
	}
	else
	{
		windowZoom = window.open(url,"zoom_window", "status=no,toolbar=no,location=no,menubar=yes,scrollbars=yes, resizable=no,width=450,height=450,left=0,top=0,screenX=0,screenY=0");
		setTimeout('windowZoom.focus()',500);
	}
}

function zoomjsp2(sku, year)
{
	var url = './' + year + '-zoom.jsp?sku=' + sku;
	if((window.windowZoom) && (!windowZoom.closed))
	{
		windowZoom.location.href= url;
		setTimeout('windowZoom.focus()',500);
	}
	else
	{
		windowZoom = window.open(url,"zoom_window", "status=no,toolbar=no,location=no,menubar=yes,scrollbars=yes, resizable=no,width=450,height=450,left=0,top=0,screenX=0,screenY=0");
		setTimeout('windowZoom.focus()',500);
	}
}

function img_act_zoom(imgName)
{
	if (document.images) 
	{
		document [imgName].src = zoomon.src;
	}
}
function img_inact_zoom(imgName)
{
	if (document.images) 
	{
		document [imgName].src = zoomoff.src;
	}			
}

// function that clears all associated radio buttons
function de_radio(element, num)
{
	var checked = element.checked;
	for (var i=0; i < document.purchase.elements.length; i++)
	{
		document.purchase.elements[i].checked = false;
	}
	if(checked == true)
	{
		element.checked = true;
	}
	
}

// function that clears all other elements when one element is selected
function de_click(element, num)
{
	
	if(element.type ==  "checkbox") {
		var checked = element.checked;
	}
	if(element.type ==  "radio") {
		var checked = element.checked;
	}
	if(element.type ==  "select-one") {
		var checked = element.value;
	}
		
	for (var i=0; i < document.purchase.elements.length; i++)
	{
     	// clear checkbox
     	if(document.purchase.elements[i].type ==  "checkbox") {
			document.purchase.elements[i].checked = false;
		}
		// radio buttons
    	else if(document.purchase.elements[i].type ==  "radio") {
      		document.purchase.elements[i].checked = false;
    	}
    	// dropdown
    	else if(document.purchase.elements[i].type ==  "select-one") {
	    	document.purchase.elements[i].value = "";
    	}
	}
	if(checked == true)
	{
		element.checked = true;
	}
	if(checked != ""){
		element.value = checked;
	}
}


// function that takes abreviated name and converts to full name to display
function getFullName(nameSelected) {

var abreviatedName = nameSelected;
var fullName = "";

	// series
	if (abreviatedName == 'roundtable') {
		fullName = 'Advanced Roundtable Series';
	} else if (abreviatedName == 'annotated') {
		fullName = 'Annotated Document Series';
	} else if (abreviatedName == 'webcasting') {
		fullName = 'BAR-ex Live Webcasting';	
	} else if (abreviatedName == 'casefile') {	
		fullName = 'The Case File Series';
	} else if (abreviatedName == 'ILN') {
		fullName = 'Interactive Learning Network';
	} else if (abreviatedName == 'practicegems') {
		fullName = 'Practice Gems Series';		
	} else if (abreviatedName == 'sixminute') {
		fullName = 'The Six-Minute Series';
	} else if (abreviatedName == 'summit') {
		fullName = 'Summit Series';
	} else if (abreviatedName == 'twelveminute') {
		fullName = 'The Twelve-Minute Series';
	} else if (abreviatedName == 'newlawyer') {
		fullName = 'New Lawyer Practice Series';
	} else if (abreviatedName == 'familylawnow') {
		fullName = 'Family Law Now Teleseminar Series';
		
		
		// practice areas			
	} else if (abreviatedName == 'AD') {
		fullName = 'Administrative Law';
	} else if (abreviatedName == 'AP') {
		fullName = 'Practice Management';
	} else if (abreviatedName == 'BA') {
		fullName = 'Bar Admission Course';
	} else if (abreviatedName == 'BI') {
		fullName = 'Bankruptcy and Insolvency Law';
	} else if (abreviatedName == 'CM') {
		fullName = 'Business';
	} else if (abreviatedName == 'CR') {
		fullName = 'Criminal Law';
	} else if (abreviatedName == 'CV') {
		fullName = 'Civil Litigation';											
	} else if (abreviatedName == 'EL') {
		fullName = 'Employment and Labour Law';
	} else if (abreviatedName == 'FM') {
		fullName = 'Family Law';
	} else if (abreviatedName == 'IM') {
		fullName = 'Immigration Law';					
	} else if (abreviatedName == 'IP') {
		fullName = 'Intellectual Property Law';
	} else if (abreviatedName == 'IM') {
		fullName = 'Immigration Law';
	} else if (abreviatedName == 'LC') {
		fullName = 'Law Clerks';
	} else if (abreviatedName == 'RE') {
		fullName = 'Real Estate Law';
	} else if (abreviatedName == 'WE') {
		fullName = 'Estates and Trusts Law';
	} else if (abreviatedName == 'PA') {
		fullName = 'Paralegal';
	
	// month
	} else if ((abreviatedName == '01') || (abreviatedName == '1')) {
		fullName = 'January';
	} else if ((abreviatedName == '02') || (abreviatedName == '2')){
		fullName = 'February';
	} else if ((abreviatedName == '03') || (abreviatedName == '3')){
		fullName = 'March';
	} else if ((abreviatedName == '04') || (abreviatedName == '4')){
		fullName = 'April';
	} else if ((abreviatedName == '05') || (abreviatedName == '5')){
		fullName = 'May';
	} else if ((abreviatedName == '06') || (abreviatedName == '6')){
		fullName = 'June';
	} else if ((abreviatedName == '07') || (abreviatedName == '7')){
		fullName = 'July';
	} else if ((abreviatedName == '08') || (abreviatedName == '8')){
		fullName = 'August';
	} else if ((abreviatedName == '09') || (abreviatedName == '9')){
		fullName = 'September';
	} else if (abreviatedName == '10') {
		fullName = 'October';
	} else if (abreviatedName == '11') {
		fullName = 'November';
	} else if (abreviatedName == '12') {
		fullName = 'December';										
	}		
						

return (fullName)
}

// email format validation
function isEmailAddress(email) {

  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0) {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
		  result = true;
  }
  return result;
}


// script to toggle between normal stlyesheet to printer friendly stylesheet
   function printerFriendlyView()
   {
   	  if (browser_type == "Microsoft Internet Explorer"){
      	document.styleSheets[0].href = "lsuc_print.css";
      	
      } else { 
        document.styleSheets[0].disabled = true;
      	document.styleSheets[1].disabled = false;
      }
   }

   function normalView()
   {
   	 if (browser_type == "Microsoft Internet Explorer"){
      	document.styleSheets[0].href = "lsuc.css";
      }else { 
        document.styleSheets[0].disabled = false;
      	document.styleSheets[1].disabled = true;
      }
   }

// function that create digital good session cookie
function createDGCookie(name,value)
{
	document.cookie = "advansis_ecom_dg=true; path=/";
	
}

// function to display logout link if dg cookie exists
function checkDGCookie ()
{
  var results = document.cookie.match ( '(^|;) ?advansis_ecom_dg=([^;]*)(;|$)' );

  if ( results )
    document.write('<li><a href=\"../cle/logout.jsp\" title=\"Logout\">Logout</a></li>');
}


// functions for the BAC selection criteria pages
function de_select(element, num)
{
	var checked = element.checked;
	for (var i=1; i < 9; i++)
	{
		document.purchase.elements[i].checked = false;
	}
}

function de_select1(element, num)
{
	var checked = element.checked;
	{
		document.purchase.elements[9].checked = false;
	}
}


// function to disable the backspace button

function key(e) {

var k = document.layers ? e.which : document.all ? event.keyCode : document.getElementById ? e.keyCode : 0;

	if (k==8) {
		return false;
	}
		
}

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function getCurrentYear(){

	var current = new Date(); // a new instance
	fixDate(current);

	return current.getFullYear();
}

function advReminder(element, years, type){

	
	//message to warn user that registration is for advanced lawyers
	if(element.checked == true){
		if(type == "LC"){
			alert('This Advanced Roundtable program is open to law clerks with at least ' + years + ' years of experience.');
		}else{
			alert('This Advanced Roundtable program is open to senior counsel with at least ' + years + ' years of experience.');
		}
	}
}

function openPopupWindow(url, name){
  window.open(url, name, "right=0, top=20, width=750, height=500, menubar=no, toolbar=no, scrollbars=yes, status=no, resizable=yes");
}

function collapseTopics(){
	
	$('collapseLink').style.display = 'none';
	$('expandLink').style.display = 'block';

	Effect.SlideUp('topics');
	return false;
}

function expandTopics(){
	
	Effect.SlideDown('topics');
	$('expandLink').style.display = 'none';
	$('collapseLink').style.display = 'block';
	
	return false;
}


// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
