function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1)
         end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

function loadoverlaypopup(){

	var popDetails = loadoverlaypopup.arguments;
	var divId, popWidth;

	if (get_cookie('feoquicksearchpopup')=='' || get_cookie('feoquicksearchpopup')=='1'){
		//var w = openpopup();
		//if(w != null)
		if (get_cookie('feoquicksearchpopup')=='')
		{
			divId = popDetails[0];
			popWidth = popDetails[1];
			document.cookie = "feoquicksearchpopup=1";
		}
		else
		{
			if(popDetails.length == 4)
			{
				divId = popDetails[2];
				popWidth = popDetails[3];
			}
			else
			{
				divId = popDetails[0];
				popWidth = popDetails[1];
			}
			document.cookie = "feoquicksearchpopup=2";
		}

		poplightpopup(divId, popWidth);
	}

}


function loadoverlayvid(){

	if(navigator.platform != 'iPad' && navigator.platform != 'iPhone' && navigator.platform != 'iPod')
	{
		var popDetails = loadoverlayvid.arguments;
		var divId, popWidth;

			//if (get_cookie('feosohovid')=='')
			{
				divId = popDetails[0];
				popWidth = popDetails[1];
				//document.cookie = "feosohovid=1";

				poplightpopup(divId, popWidth);
			}
	}

}


function loadoverlayhomepage(){

		var popDetails = loadoverlayhomepage.arguments;
		var divId, popWidth;

			//if (get_cookie('feohomepagepopup')=='')
			//{
				divId = popDetails[0];
				popWidth = popDetails[1];
				//document.cookie = "feohomepagepopup=1";

				poplightpopup(divId, popWidth);
			//}

}

	function poplightpopup(popID, popWidth){

		//Fade in the Popup and add close button
		$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="/FEOCorp.Display/images/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');
		
		//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
		var popMargTop = ($('#' + popID).height() + 40) / 2;
		var popMargLeft = ($('#' + popID).width() + 40) / 2;
		
		//Apply Margin to Popup
		$('#' + popID).css({ 
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
		
		//Fade in Background
		$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
		if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')
		{
			$("#fade").css({"width": "10000px", "height": "10000px"});
		}
		$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer 
		
	};

	//Close Popups and Fade Layer
	$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
	  	$('#fade , .popup_block').fadeOut(); //fade them both out
		$('#fade').remove();
		$('#introvid_content').empty();
		return false;
	});



