// JavaScript Document

var clientScreenDimensions = new Object(); 
/* Double click variables */
var axel = Math.random() + "";
var ord = axel * 1000000000000000000;
/* Double click variables */

/* featured tabs rotation interval */
var rotateInterval = 15000;
var rotateMode = "2"; 

var loginTimer;
var featuredTimer;
var currentTab;

var featuredTabs = new Array();
featuredTabs[0] = "";
featuredTabs[1] = "news_network";
featuredTabs[2] = "tracking_network";
featuredTabs[3] = "votes_network";
featuredTabs[4] = "coverage_network";
featuredTabs[5] = "newsletters_network";


$(document).ready(function(){
//Start JQuery Code

  $("#productselect1").change(function(){ 	
	$('#productfindForm_1').submit();
  });
  
  $("#productselect2").change(function(){ 	
	$('#productfindForm_2').submit();
  });
  
  $("#productselect3").change(function(){ 	
	$('#productfindForm_3').submit();
  });
  
  $("#productselect4").change(function(){ 	
	$('#productfindForm_4').submit();
  });
  
  $("#productselect5").change(function(){ 	
	$('#productfindForm_5').submit();
  });


  $('input[name="selection"]').attr('checked','');


  if ($("body").attr("class") == "home") {
   rotateMode = $.trim($('#featureMode').text());
   if(rotateMode == 1) {
     currentTab = $.trim($('#featureStart').text());
     featuredTimer=setInterval("rotateFeaturedContent()",rotateInterval);
     //alert(currentTab);
   }
 
   
  }

  
   
   var config = {    
     sensitivity: 8, // number = sensitivity threshold (must be 1 or higher)    
     interval: 100, // number = milliseconds for onMouseOver polling interval    
     over: showFlyOut, // function = onMouseOver callback (REQUIRED)    
     timeout: 140, // number = milliseconds delay before onMouseOut    
     out: hideFlyOut // function = onMouseOut callback (REQUIRED)    
};

$("ul#primary li a.toplevel").hoverIntent( config )


$('ul#primary li a.toplevel').mouseout(function(){																			      										
		flyOutState();
});	

$('div.sublevel').mouseover(function(){																			
 $(this).removeClass("hide");
 $(this).parent("li").addClass("flyout");
 if(featuredTimer) {
  clearTimeout(featuredTimer);		 
 }	
});	
	
	$('div.sublevel').mouseout(function(){							
		flyOutState();
		
	});	
	
	
    $('.featureblock').mouseover(function(){	
        if(featuredTimer) {
		 clearTimeout(featuredTimer);	
		}		
	});
	
	$('.featureblock').mouseout(function(){	
        if(featuredTimer) {
		 clearTimeout(featuredTimer);	
		 featuredTimer=null;
		 featuredTimer=setInterval("rotateFeaturedContent()",rotateInterval);
		}		
	});


   
	
    /*var beenHit = false;
	
	//Tooltip Display - Changed 4/8/10
	var text = "";
	$("#loginArea label, a.toolTipLink").hover(
		function() {                                         
			if($(this).attr("title") != null) {
				text = $(this).attr("title");
				tooltip = "<span class=\"tooltip\">" + text + "</span>";
				$(this).attr("title","");
				$(this).after(tooltip);
				$("span.tooltip").css("display","block");
			};
		}, function() {
			$("span.tooltip").remove();
			$(this).attr("title",text);
			text = "";
		}
	);	*/
	
	var beenHit = false;
	var text = "";
	 $("#loginArea label").hover(       

                                function() {                                         

                                                if($(this).attr("title") != null) {

                                                                text = $(this).attr("title");
                                                                if($(this).attr('class').indexOf('smalltip') == -1) {
                                                                tooltip = "<span class=\"tooltip\">" + text + "</span>";
																}
																else {
																tooltip = "<span class=\"tooltip small\">" + text + "</span>";	
																}

                                                                $(this).attr("title","");

                                                                $(this).after(tooltip);

                                                                $("span.tooltip").css("display","block");

 

                                                };                                             

                                },                             

                                function() {                                         

                                                $("span.tooltip").remove();

                                                $(this).attr("title",text);                

                                                text = "";

                                }

                );
	
	//Button Hovers
	$(".submit, #print img, #productdescription #col_a li a img").hover(	
		function() {			
			off_img = $(this).attr('src');			
			over_img = off_img.replace('/off/','/on/');																			
			$(this).attr('src', over_img);		
		},		
		function() {		
			$(this).attr('src', off_img);
		}
	);

	//Print Button
	$("#print").click(function(){
		window.print();
		return false;
	});

	//Print Window Button
	$("#printlink").click(function(){
		window.print();
		return false;
	});
	
	
	
	
	//Email Background Stretch
	$("#emaillayer").height($("body").height());
			
	//Email Button
	$("#emaillink").click(function(){
		$("#emaillayer").css('display','block');
		$("#email").css('display','block');
		return false;
	});
	
	$('#emailPageForm').ajaxForm( { resetForm: true, success: closeEmailFormWin } );
	
	$("#emailPageForm").validate({
     rules: {     
      recipient_name: "required" ,	  
	  recipient_email: "required",
	  sender_name: "required",
	  sender_email: "required"	 
     },
	 messages: {
			recipient_name: "<div style='font-size: 10px; color: red; margin-bottom: -3px;'><img src='frame-images/cq/icons/exclamation.gif' style='position: relative; top: 2px;' /> Required field.</div>",
			recipient_email: "<div style='font-size: 10px; color: red; margin-bottom: -3px;'><img src='frame-images/cq/icons/exclamation.gif' style='position: relative; top: 2px;' /> Required field.</div>",
			sender_name: "<div style='font-size: 10px; color: red; margin-bottom: -3px;'><img src='frame-images/cq/icons/exclamation.gif' style='position: relative; top: 2px;' /> Required field.</div>",
			sender_email: "<div style='font-size: 10px; color: red; margin-bottom: -3px;'><img src='frame-images/cq/icons/exclamation.gif' style='position: relative; top: 2px;' /> Required field.</div>"
			
		}, errorPlacement: function(error, element) {				
				error.appendTo($('label[for="'+element.attr('id')+'"]'));			
			}
	
    });					
	
	
	if(Get_Cookie('login_dir')) {
      var login_dir = Get_Cookie('login_dir'); 
	  var user = Get_Cookie('user'); 
	  $('#login_dir').val(login_dir);
	  $('#knowlegisUser').val(user);
	  
	  $('#kl1').attr('checked','checked');	
	}
	
	
	
	$("#cqLoginBtn").click(function(){
	  $('#cqLoginForm').submit();									
	});
	
	$("#cqStateTrackLoginBtn").click(function(){
	  $('#cqStateTrackLoginForm').submit();									
	});
	
	$("#capwizLoginBtn").click(function(){
      $('#capwizLoginForm').attr('action','https://ssl.capwiz.com/'+$('#dir').val()+'/dbq/admin/');										
	  $('#capwizLoginForm').submit();									
	});
	
	$("#knowlegisLoginBtn").click(function(){									   
      var uAction = 'https://ssl.capwiz.com/'+$('#login_dir').val()+'/admin/kl/index.tt';									   	  
	  $('#knowlegisLoginForm').attr('action',uAction);											   										  	  
	  if($('#kl1').attr('checked')) {
		Set_Cookie('login_dir',$('#login_dir').val(),14);		
		Set_Cookie('user',$('#knowlegisUser').val(),14);
		Set_Cookie('remembermeKL',1,14);
	  }
	  else {
	   Delete_Cookie('login_dir');
	   Delete_Cookie('user');
	   Delete_Cookie('remembermeKL');
	  }	  
	  $('#knowlegisLoginForm').submit();										 
	});
	
	$("#rollCallLoginBtn").click(function(){	  									   										  
	  $('#rollCallLoginForm').submit();									
	});
	
	
	
	
	
	
	
	//Close Window Button - Email
	$("#email a.closewindow").click(function(){
		$('#emaillayer').css('display','none');
		$('#email').css('display','none');
		return false;
	});

	//Close Window Button - Print
	$("body.print a.closewindow").click(function(){
		window.close();
		return false;
	});	

	//Search Operators
	$("#searchoperators").toggle(	
		function() {			
			$("#searchHelpContainer").css('display','block');
		},		
		function() {		
			$("#searchHelpContainer").css('display','none');
		}
	);


	//Product Table - Initialization
	$(".productdisplay tr td:odd").css('border-left','40px solid white');
	$(".productdisplay :checkbox").attr('checked','');
	if ($(".productdisplay td:last").html() == "&nbsp;") $(".productdisplay tr td:last").css('border-bottom','1px solid white');

	//Product Table Rollovers
	$(".productdisplay td a").hover(	
		function() {			
			$(this).siblings("div").css('display','block');	
		},		
		function() {		
			$(this).siblings("div").css('display','none');	
		}
	);
	
	$(".productdisplay .sublevel a").hover(	
		function() {			
			$(this).siblings("div").css('display','block');	
		},		
		function() {		
			$(this).siblings("div").css('display','none');	
		}
	);	

	
	// Product Form
	$("#productlist").submit(function(){   
	 var selectedURL = $('#products').val();
	 if(selectedURL != "") {
	  window.location=selectedURL; 
	 }
	 return false;	 
    });	
	
	// Product drop down 
	$("#productselect").change(function(){ 	
	 if($("#productselect").val() != "") {									
	  window.location=$("#productselect").val();										  
	 }
    });	
	
	$("#products").change(function(){   
	 var selectedURL = $('#products').val();
	 if(selectedURL != "") {
	  window.location=selectedURL; 
	 }
	 return false;	 
    });	
	
	//Product Page/Network Features

	$("#productdescription #col_a li a").hover(	
		function() {			
			$(this).siblings("div").css('display','block');	
		},		
		function() {		
			$(this).siblings("div").css('display','none');	
		}
	);

	//Product Page/Image Picker
	$(".moreimages li a").click(function(){
		imageshow = $(this).attr('class');
	
		//Images
		$("#productdescription #col_b img").css('display','none');
		$("#productdescription #col_b img." + imageshow).css('display','inline');

		//Description Divs
		$(".moreimages div").css('display','none');
		$(".moreimages div." + imageshow).css('display','block');
	});


	//Homepage Module - Changed 3/8/10
	$("#featurenav a").click(function(){
									  
        if(featuredTimer) {
		 clearTimeout(featuredTimer);
		 featuredTimer=null;		 
		}
		$("#featurenav a").each(function(){
			$(this).removeClass('selected');
		});	
		$("div.featureblock").css('display','none');		
		
		anchor = $(this).attr('href');	
		
		$("div.featureblock" + anchor).fadeIn(1000);	
		$(this).addClass('selected');
		$(this).blur();
		return false;
	});
	
	$("#prNavID").change(function(){
		document.getElementById('prArchiveForm').submit();
		return false;
	});
	
	//Home page find drop down for all tabs
	$('form[name=productfindForm]').submit(function(){													
      var id = $(this).attr('id').split("_");													
	  window.location=$('#productselect'+id[1]).val();	 
	  return false;
	});
	
	
	
	$('#requestRatesForm').ajaxForm( { beforeSubmit:  validateRequestRate, url: '/actions/_postRequestRates.cfm', type: 'post', clearForm: true, success: registrationThankYou} );
	
	$('#enewsform').ajaxForm( { beforeSubmit:  validateNewsletterSignUp, url: '/actions/_postNewsletterSignUp.cfm', type: 'post', clearForm: true, success: registrationThankYou} );
	
	$('#eventRegistration').ajaxForm( { beforeSubmit:  validateEventRegistration, url: '/actions/_postEventRegistration.cfm', type: 'post', clearForm: true, success: registrationThankYou} );
	

	//Safari Hack - 5/28/08
	if (($.browser.safari) && (parseInt($.browser.version) < 500)) {
		$("a#login").css("margin-top", "-2px");
	}

	//Login Code - Changed 4/8/10
	$("a#login").toggle(
		function(){
			if ($("#loginbox").css("visibility") == "hidden") loginshow();
			else loginnoshow();
		},function(){
			if ($("#loginbox").css("visibility") == "visible") loginnoshow();
			else loginshow();			
	});

	$("#loginbox a.closewindow").click(function(){
		loginnoshow();
	});
	
	$("#loginBox input").focus(function(){
	  if(loginTimer) {	 
	   clearTimeout(loginTimer);
	  }
	});


	if($("body").attr("class") == "home") {		
		loginshow();
		loginTimer = setTimeout("loginnoshow()", 5000);	
	};	
	
	// Added by KH supports multiple CQ logins
	$(".loginSelection").click(function(){												
		$(".loginForms").addClass("hide");								
		$("#loginArea").removeClass("hide");		
		$("#"+$(this).val()).removeClass("hide");			
		// had to add this for IE8 hack.  Enter button stops working when the div is hidden and then displayed.
		//$("#"+$(this).val()).html($("#"+$(this).val()).html());
		
	    clearTimeout(loginTimer);				
	});
	
	// Added by KH supports external CQ logins
	$(".ExternalLoginSelection").click(function(){										
		$(".loginForms").addClass("hide");
		window.location=$(this).val();		
	});
	
	/*$(".tip").tooltip({
		cssClass: "tooltip", 
		delay : 0,// time in milliseconds that you must leave the mouse over the link until the tooltip appears
		duration : 700,//time in milliseconds that the tooltip will stay visible after you remove the mouse over the link
		xOffset : -225,
		yOffset : -30,
		opacity : 10, 
		fadeDuration: 400
		});*/
	 

	//Target Links - opening outside windows
	$("a.target").click(function(){
		window.open($(this).attr("href"));
		return false;
	});
	
	 $('#userguideactionbtn').click(function(){
		window.open($('#userguides').val());
		return false;
	});

	
	//Flyout windows
	//End JQuery Code
});

function flyOverState(e) {
	if (e.siblings("div").attr("class") == "sublevel hide") {
		e.siblings(".sublevel").removeClass("hide");			
		e.parent("li").addClass("flyout");
	};
};

function flyOutState() {
	$("ul#primary li .sublevel").addClass("hide");			
	$("ul#primary li a.toplevel").parent("li").removeClass("flyout");  
	
	if(featuredTimer) {
		  
		 clearTimeout(featuredTimer);	
		 featuredTimer=null;
		 featuredTimer=setInterval("rotateFeaturedContent()",rotateInterval);
		}	
	
};

function validateEmailPage() {
//	alert("got here");
//	alert($("#emailPageForm fieldset").length);
 //$("#emailPageForm label").addClass('error');
 //var oDiv = document.createElement("div");
 //oDiv.className='error';
 
// $("#recipient_name").wrap(oDiv);

 //$("#recipient_name").after('<img src="frame-images/cq/icons/exclamation.gif" alt="This field needs attention" title="This field needs attention" class="errorIcon" />');

 return false;	
	
}




function closeEmailFormWin() {	
  $('#emaillayer').css('display','none');
  $('#email').css('display','none');
  alert("Email sent");
  return false;
}

function registrationThankYou(str) {
 //document.write(str);
 updateStatusMsg('Thank you for registering.');
 setTimeout('removeOverlay()',1000); 
}

function showRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
    alert('About to submit: \n\n' + queryString); 
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true; 
} 

function validateRequestRate() {
 clearFormErrors();		
 var errorData = new Object();
 errorData.fieldId = new Array();
 errorData.msg = new Array();	
	
 if($.trim($('#firstname').val()) == "") {
  errorData.fieldId[errorData.fieldId.length]="firstname";
  errorData.msg[errorData.msg.length]="Required field.";
 }
 
 if($.trim($('#lastname').val()) == "") {
  errorData.fieldId[errorData.fieldId.length]="lastname";
  errorData.msg[errorData.msg.length]="Required field.";
 }
 
 if($.trim($('#company').val()) == "") {
  errorData.fieldId[errorData.fieldId.length]="company";
  errorData.msg[errorData.msg.length]="Required field.";
 }
 
 if($.trim($('#address').val()) == "") {
  errorData.fieldId[errorData.fieldId.length]="address";
  errorData.msg[errorData.msg.length]="Required field.";
 }
 
  if($.trim($('#city').val()) == "") {
  errorData.fieldId[errorData.fieldId.length]="city";
  errorData.msg[errorData.msg.length]="Required field.";
 }
 
 if($.trim($('#state').val()) == "") {
  errorData.fieldId[errorData.fieldId.length]="state";
  errorData.msg[errorData.msg.length]="Required field.";
 } 

 if(isNaN($('#zip').val()) || $('#zip').val().length != 5) {
  errorData.fieldId[errorData.fieldId.length]="zip";
  errorData.msg[errorData.msg.length]="Required field. Must be a five digit number xxxxx.";
 }
 
 if(!isValidEmail($('#emailaddress').val())) {
  errorData.fieldId[errorData.fieldId.length]="emailaddress";
  errorData.msg[errorData.msg.length]="Required field. must be a valid email address.";	 
 }
 
 if($.trim($('#phone').val()) == "") {
  errorData.fieldId[errorData.fieldId.length]="phone";
  errorData.msg[errorData.msg.length]="Required field.";
 }  
 
 if(!isCheckboxGroupChecked('adOpportunity')) {
  errorData.fieldId[errorData.fieldId.length]="adOpportunity";
  errorData.msg[errorData.msg.length]="Required field. Please select at least one opportunity.";	 	 
 } 
 
 if(errorData.fieldId.length > 0 || errorData.msg.length > 0) {
  displayFormErrors(errorData);	 
  return false;	
 }
 else {
  addOverlay();
  displayStatusWindow('Please wait while your information is being submitted.');	 
  return true;	 
 }
}

function validateNewsletterSignUp() {	
 clearFormErrors();	
 var errorData = new Object();
 errorData.fieldId = new Array();
 errorData.msg = new Array();		
 
  if(!isCheckboxGroupChecked('newsletters')) {
  errorData.fieldId[errorData.fieldId.length]="newsletters";
  errorData.msg[errorData.msg.length]="Required field. Please select at least one newsletter to sign up for.";	 	 
 }
 
 if(!isValidEmail($('#emailaddress').val())) {
  errorData.fieldId[errorData.fieldId.length]="emailaddress";
  errorData.msg[errorData.msg.length]="Required field. must be a valid email address.";	 
 }
 
 if($.trim($('#firstname').val()) == "") {
  errorData.fieldId[errorData.fieldId.length]="firstname";
  errorData.msg[errorData.msg.length]="Required field.";
 }
 
 if($.trim($('#lastname').val()) == "") {
  errorData.fieldId[errorData.fieldId.length]="lastname";
  errorData.msg[errorData.msg.length]="Required field.";
 }
 
 if($.trim($('#companyCategory').val()) == "") {
  errorData.fieldId[errorData.fieldId.length]="companyCategory";
  errorData.msg[errorData.msg.length]="Required field.";
 }
 
 if(isNaN($('#zip').val()) || $('#zip').val().length != 5) {
  errorData.fieldId[errorData.fieldId.length]="zip";
  errorData.msg[errorData.msg.length]="Required field. Must be a five digit number xxxxx.";
 } 
 
 if($('#issues').attr('selectedIndex') == -1) {
  errorData.fieldId[errorData.fieldId.length]="issues";
  errorData.msg[errorData.msg.length]="Required field.";
 }
 
 if(errorData.fieldId.length > 0 || errorData.msg.length > 0) {
  displayFormErrors(errorData);	 
  return false;	
 }
 else {	
  addOverlay();
  displayStatusWindow('Please wait while your information is being submitted.');  
  return true;	 
 }	
}

function validateEventRegistration() {
 clearFormErrors();		
 var errorData = new Object();
 errorData.fieldId = new Array();
 errorData.msg = new Array();
 var eventSelected=false; 
 
 for(var x = 1; x < 6; x++) {
  if(document.getElementById('event_'+x).checked) {
   eventSelected=true;
   break;
  }
 } 
 
 if(!eventSelected) {
  errorData.fieldId[errorData.fieldId.length]="dncEvent";
  errorData.fieldId[errorData.fieldId.length]="rncEvent";
  errorData.msg[errorData.msg.length]="Required field. Please select at least one event to register for.";
  errorData.msg[errorData.msg.length]="Required field. Please select at least one event to register for.";
 } 
	
 if($.trim($('#firstname').val()) == "") {
  errorData.fieldId[errorData.fieldId.length]="firstname";
  errorData.msg[errorData.msg.length]="Required field.";
 }
 
 if($.trim($('#lastname').val()) == "") {
  errorData.fieldId[errorData.fieldId.length]="lastname";
  errorData.msg[errorData.msg.length]="Required field.";
 }
 
 if($.trim($('#title').val()) == "") {
  errorData.fieldId[errorData.fieldId.length]="title";
  errorData.msg[errorData.msg.length]="Required field.";
 }
 
 if($.trim($('#organization').val()) == "") {
  errorData.fieldId[errorData.fieldId.length]="organization";
  errorData.msg[errorData.msg.length]="Required field.";
 } 
 
 if(!isValidEmail($('#emailaddress').val())) {
  errorData.fieldId[errorData.fieldId.length]="emailaddress";
  errorData.msg[errorData.msg.length]="Required field. must be a valid email address.";	 
 }
 
 if(errorData.fieldId.length > 0 || errorData.msg.length > 0) {
  displayFormErrors(errorData);	 
  return false;	
 }
 else {   
  addOverlay();
  displayStatusWindow('Please wait while your information is being submitted.');	 
  return true;	 
 }
}

function displayFormErrors(errorData) { 
 errorTotal = errorData.fieldId.length;
 $('.error').css('display','block');
 for(var x = 0; x < errorTotal; x++) {
  $("label[for='"+errorData.fieldId[x]+"']").before("<div class='errorlabel'>"+errorData.msg[x]+"</div>");	 
 }
}

function clearFormErrors() {
 $('.error').css('display','none');	
 $(".errorlabel").remove();
}

function isValidEmail(str) {
 if(str.indexOf('@') == -1 || str.indexOf('.') == -1) {
  return false;
 }
 else {
  var tmp1 = str.split("@");
  var tmp2 = tmp1[1].split(".");   
  if(tmp1[0].length < 1 || tmp2[0].length < 2 || tmp2[1].length < 2) {
   return false;
  }   
 }
 return true;
}

function isCheckboxGroupChecked(fieldName) {
 var isChecked = false;
 var total = document.getElementsByName(fieldName).length;
 for(var x = 0; x < total; x++) {
  if(document.getElementsByName(fieldName).item(x).checked) {
   return true;
   break;
  }   
 }
 return false; 
}

//Login Box - 3/9/10
	function loginshow() {
		$("a#login").addClass("selected");
		$("#loginbox").css("visibility","visible");
		if(loginTimer) {
		 clearTimeout(loginTimer);
		}
	}

	function loginnoshow() {	
	
		$("a#login").removeClass("selected");
		$("#loginbox").css("visibility","hidden");
		$("#loginArea").addClass("hide");
		$("#selectLogin input[type='radio']").attr("checked","");
		if(loginTimer) {		
		 clearTimeout(loginTimer); 
		}
	}
	
// this function gets the cookie, if it exists
function Get_Cookie( name ) {	
 var start = document.cookie.indexOf( name + "=" );
 var len = start + name.length + 1;
 if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
  return null;
 }
 if ( start == -1 ) return null;
 var end = document.cookie.indexOf( ";", len );
 if ( end == -1 ) end = document.cookie.length;
 return unescape( document.cookie.substring( len, end ) );
}

/*
 only the first 2 parameters are required, the cookie name, the cookie
 value. Cookie time is in milliseconds, so the below expires will make the 
 number you pass in the Set_Cookie function call the number of days the cookie
 lasts, if you want it to be hours or minutes, just get rid of 24 and 60.

 Generally you don't need to worry about domain, path or secure for most applications
 so unless you need that, leave those parameters blank in the function call.
*/
function Set_Cookie( name, value, expires, path, domain, secure ) {
 // set time, it's in milliseconds
 var today = new Date();
 today.setTime( today.getTime() );
 // if the expires variable is set, make the correct expires time, the
 // current script below will set it for x number of days, to make it
 // for hours, delete * 24, for minutes, delete * 60 * 24
 if ( expires ) {
  expires = expires * 1000 * 60 * 60 * 24;
 }
 //alert( 'today ' + today.toGMTString() );// this is for testing purpose only
 var expires_date = new Date( today.getTime() + (expires) );
 //alert('expires ' + expires_date.toGMTString());// this is for testing purposes only
 document.cookie = name + "=" +escape( value ) +
  ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
  ( ( path ) ? ";path=" + path : "" ) + 
  ( ( domain ) ? ";domain=" + domain : "" ) +
  ( ( secure ) ? ";secure" : "" );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
 if ( Get_Cookie( name ) ) document.cookie = name + "=" +
  ( ( path ) ? ";path=" + path : "") +
  ( ( domain ) ? ";domain=" + domain : "" ) +
  ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function addOverlay() { 
 setClientScreenDimensions();
 var oDiv = document.createElement("div");
 oDiv.setAttribute('id','disabledOverlay');  
 oDiv.style.height=getClientHeightWithScroll()+'px'; 
 document.getElementsByTagName("body").item(0).appendChild(oDiv);  
}

function removeOverlay() {
 removeStatusWindow();	
 if(document.getElementById('disabledOverlay')) {
  document.getElementsByTagName("body").item(0).removeChild(document.getElementById('disabledOverlay'));
 }	
}	

function displayStatusWindow(msg) {  
 removeStatusWindow();	 
 var statusWindow = getStatusWindow(msg);  
 document.getElementsByTagName('body').item(0).appendChild(statusWindow); 
}

function removeStatusWindow() {
 if(document.getElementById('statusWindow')) {
  document.getElementsByTagName('body').item(0).removeChild(document.getElementById('statusWindow'),true);	  
 }
}

function updateStatusMsg(msg) {
 if(document.getElementById('statusWindow')) {  
  document.getElementById('statusMsg').innerHTML = msg;
 }	
}

function getStatusWindow(msg) { 
 var oDivContainer = document.createElement("div");
 var oDivMessage = document.createElement("div"); 
 oDivContainer.setAttribute("id","statusWindow");
 oDivContainer.style.top = getVerticalCenterScreen()+'px';
 oDivContainer.style.left = getHorizontalCenterScreen(350)+'px';
 oDivMessage.setAttribute("id","statusMsg");
 oDivMessage.innerHTML = msg; 
 oDivContainer.appendChild(oDivMessage); 
 return oDivContainer;
}

function setClientScreenDimensions() {
 var de = document.documentElement;     
 clientScreenDimensions.height = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight; 
 if(window.pageYOffset) { clientScreenDimensions.vscroll = window.pageYOffset; } else if(document.documentElement && document.documentElement.scrollTop){ clientScreenDimensions.vscroll = document.documentElement.scrollTop; } else if(document.body){ clientScreenDimensions.vscroll = document.body.scrollTop; } 
 clientScreenDimensions.width = window.innerWidth-20 || self.innerWidth-20 || (de&&de.clientWidth) || document.body.clientWidth; 
 clientScreenDimensions.heightWithScroll = parseInt(clientScreenDimensions.height)+parseInt(clientScreenDimensions.vscroll);
}

function getClientHeight() {
 return clientScreenDimensions.height;
}

function getClientHeightWithScroll() {
 return clientScreenDimensions.heightWithScroll;
}

function getClientWidth() {
 return clientScreenDimensions.width;
}

function getVerticalCenterScreen() { 
 var y = clientScreenDimensions.heightWithScroll/2;  
 return Math.floor(y);
}
 
function getHorizontalCenterScreen(widthOffset) {
 var x = widthOffset/2;
 var y = clientScreenDimensions.width/2;  
 return Math.floor(y-x);	 
 
} 

function auto404() {
 window.location="/";	
}

function showFlyOut() {
	if(featuredTimer) {		
		 clearTimeout(featuredTimer);	
		}
	flyOutState();													 
		var e = $(this);									
		flyOverState(e);
}

function hideFlyOut() {		
	var isMenuOpen = false;	
	$('div.sublevel').each(function(index) {
     if($(this).attr('className') == 'sublevel') {
	   isMenuOpen=true; 
	 }
    
    });
	if(!isMenuOpen) {
	 if(featuredTimer) {
		  
		 clearTimeout(featuredTimer);	
		 featuredTimer=null;
		 featuredTimer=setInterval("rotateFeaturedContent()",rotateInterval);
		}	
	}
}


function rotateFeaturedContent() { 
 currentTab = currentTab*1+1; 
 if(currentTab == 6) {
	currentTab = 1; 
 } 
 $('#featurenav a').removeClass('selected');
 $("div.featureblock").css('display','none');
 $("a[href=#"+featuredTabs[currentTab]+"]").addClass("selected");
 $("div.featureblock#" + featuredTabs[currentTab]).fadeIn(1000);	
}