// global vars
var popupWin;
var scrnwidth=screen.width;
var scrnheight=screen.height;


// "only 1 open at a time" popup function.
//-----------------------------------------------------------------------------
// The fifth argument, windowname, is optional.  If specified, it is passed as
// the second argument to window.open().  This is required in order to leave
// the popup opener page (without closing the popup), come back to it, and NOT
// have a duplicate popup window.
//-----------------------------------------------------------------------------
function openPop (url, width, height, addloptions, windowname) {
	if (windowname == null) {
		windowname = "";
	}
	var xspot = Math.round((scrnwidth/2)-(width/2));
	var yspot = Math.round((scrnheight/2)-(height/2)-30);
	features = "height="+height+",width="+width+",top="+yspot+",screenY="+yspot+",left="+xspot+",screenX="+xspot;
	if (addloptions && addloptions!="") { features += ","+addloptions; }
	if (!popupWin || popupWin.closed) {
		popupWin = window.open(url, windowname, features);
	}
	else {
		window.popupWin.close();
		popupWin = window.open(url, windowname, features);
	}
}

function closepopups(){
	if (popupWin && popupWin.open){
		window.popupWin.close();
	}
}





var exceptions = new Array();
var i = 0;
exceptions[i++] = "postsaleservice";
exceptions[i++] = "consumerspot";
exceptions[i++] = "aftermind";
exceptions[i++] = "geapplianceparts";
exceptions[i++] = "genet2";
exceptions[i++] = "genet";
exceptions[i++] = "millstone";
exceptions[i++] = "products";
exceptions[i++] = "monogram";
exceptions[i++] = "ap1lnx";
exceptions[i++] = "answers";
exceptions[i++] = "prodcontent";

var Base_Href = window.location.protocol+"//espanol.geappliances.com";
var UnSecure_Base_Href = "http://espanol.geappliances.com";
if (window.location.host.indexOf('team') != -1)
{
	var Base_Href = window.location.protocol+"//espanol.geappliances.com";
	var UnSecure_Base_Href = "http://espanol.geappliances.com";
	for (count = 0; count < exceptions.length; count++)
	{
		if (window.location.host.indexOf(exceptions[count]) != -1)
		{
			var Base_Href = window.location.protocol+"//espanol.geappliances.com";
			var UnSecure_Base_Href = "http://espanol.geappliances.com";
		}//Close if
	}//Close for
}//Close if
var FooterImage, HeaderImage, TargetLocationDefinition, DaughterWindowClose;
if (!DaughterWindowClose){DaughterWindowClose = false;}

// LER 05/27/09
// function remains in a simplified form to catch any of the few places that MIGHT still be calling it...
function openurllist(customhref) { document.location.replace("http://espanol.geappliances.com/"); }


/* This function is here for legacy. */
/* Use one of the other functions if you need a popup. */
function openNewWindow(url, width, height) {
          windowName  = "new_window";
          params      = "toolbar=0,";
          params     += "location=0,";
          params     += "directories=0,";
          params     += "status=0,";
          params     += "menubar=0,";
          params     += "scrollbars=1,";
          params     += "resizable=0,";
          params += "width="+width+",";
          params += "height="+height;
          win = window.open(url, windowName, params);
          win.opener.name = "opener";
}



/*	Function to encode special characters, as well as anything that's not
	printable ASCII, as HTML entities for safe inclusion in generated HTML.
	
	Usage example:

		document.write('<a href="' + encodeEntities(url) + '">moo</a>\n');
*/
function encodeEntities (s) {
	s = s.replace(/&/g, "&amp;");
	s = s.replace(/</g, "&lt;");
	s = s.replace(/>/g, "&gt;");
	s = s.replace(/\x22/g, "&quot;"); /* double quotation mark */
	s = s.replace(/\x27/g, "&#39;"); /* ASCII apostrophe - &apos; is not universal yet */
	s = s.replace(/[^\x20-\x7e]/g,
		function (ch) {
			return "&#" + ch.charCodeAt(0) + ";";
		}
	); /* escape anything other than ASCII printable */
	return s;
}

/*	based on openLarger() from http://www.gelighting.com/na/scripts/global.js

	One usage example is needed for onclick events, other on events, and
	href="javascript:..." attributes.  Another is needed for <script> elements
	and .js files.

	Usage example --- onclick event (also applies for href="javascript:..."):

		<a target="_blank" href="images/foo.jpg"
			onclick="openNakedImagePopup('images/foo.jpg', 640, 480, 'GE Profile(TM) Washers and Dryers'); return false;">
				view larger photo
		</a>

		Got &, <, >, ', ", or other special characters?

		<a target="_blank" href="images/foo.jpg?foo=1&amp;bar=2"
			onclick="openNakedImagePopup('images/foo.jpg?foo=1&amp;bar=2', 640, 480, 'GE Profile&trade; Washers &amp; Dryers'); return false;">
				view larger photo
		</a>
		
		REMEMBER:
		While this function runs encodeEntities on the imageURL and altText,
		you still need to escape <, >, &, ', and " characters in onclick events
		or any other HTML attribute value (the browser unescapes them, then
		openNakedImagePopup re-escapes them).
		While most browsers are lenient, XHTML validation tools will issue
		warnings or error messages if you do not do this.

	Usage example --- <script> element (also applies for .js files):

		<script type="text/javascript">
			function openPopup () {
				openNakedImagePopup('images/foo.jpg', 640, 480, 'GE Profile(TM) Washers and Dryers');
				// Got special characters?
				openNakedImagePopup('images/foo.jpg?foo=1&bar=2', 640, 480, 'GE Profile\u2122 Washers & Dryers'); // [1] one way
				openNakedImagePopup('images/foo.jpg?foo=1&bar=2', 640, 480, 'GE Profile&trade; Washers &amp; Dryers', true); // [2] another way
				// notice lack of entity escaping here --^ in the URLs.
				// you don't need to entity-escape the URLs in <script>
				// elements or .js files.
			}
		</script>
		<a target="_blank" href="images/foo.jpg" onclick="openPopup(); return false;">
			view larger photo
		</a>

		Got &, <, >, ', ", or other special characters?

		REMEMBER:
		Since browsers do NOT unescape entities in <script> elements like they
		do in HTML attribute values, you do NOT need to do HTML entity escaping
		here.  \ escaping still applies.  See [1] above.
	
		If you don't like looking up Unicode hex values, you can use HTML
		entity escaping instead.  However, within <script> elements and .js
		files, you MUST pass an optional fifth argument of true.  In other
		contexts, such as onclick attributes and javascript: hrefs, you
		MUST NOT pass the optional fifth argument.  (The browser unescapes
		entities in onclick/href attributes, but not in script elements or
		.js files; the optional fifth argument tells openNakedImagePopup
		to *not* perform entity-escaping on the alt text.)
	
*/
var nakedImagePopupWindow;
function openNakedImagePopup(imageURL, width, height, altText, isEscaped) {
	var screenX = Math.round((screen.width - width) / 2);
	var screenY = Math.round((screen.height - height - 60) / 2); /* assume 60px for titlebar, toolbars, other vertical real-estate */
	var features = ( /* parenthesis for multiline expression */
		"width=" + width
		+ ",height=" + height
		+ ",screenX=" + screenX + ",screenY=" + screenY /* Netscape */
		+ ",left=" + screenX + ",top=" + screenY /* IE */
	);
	if (nakedImagePopupWindow && !(nakedImagePopupWindow.closed)) {
		nakedImagePopupWindow.close();
	}
	nakedImagePopupWindow = window.open(null, null, features);
	if (altText != null && !isEscaped) {
		altText = encodeEntities(altText);
	}
	var html = ( /* parenthesis for multiline expression */
		'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n'
		+ '<html>\n'
		+ '<head>\n'
		+ '<title>'
		+ ((altText != null) ? altText : 'Photo')
		+ '</title>\n'
		+ '<style type="text/css">\n'
		+ 'html, body { margin: 0; padding: 0; background-color: white; color: black; }\n'
		+ '</style>\n'
		+ '</head>\n'
		+ '<body>\n'
		+ '<img src="' + encodeEntities(imageURL) + '"\n'
		+ ' width="' + width + '"'
		+ ' height="' + height + '"'
		+ ((altText != null) ? (' alt="' + altText + '"') : "")
		+ ' border="0"'
		+ ' />\n'
		+ '</body>\n'
		+ '</html>\n'
	);
	nakedImagePopupWindow.document.open();
	nakedImagePopupWindow.document.write(html);
	nakedImagePopupWindow.document.close();
}

function openNakedImagePopupLong(imageURL, width, height,imgwidth,imgheight, altText, isEscaped) {
	var screenX = Math.round((screen.width - width) / 2);
	var screenY = Math.round((screen.height - height - 60) / 2); /* assume 60px for titlebar, toolbars, other vertical real-estate */
	var features = ( /* parenthesis for multiline expression */
		"scrollbars = yes, resizable=yes,"
		+ "width=" + width
		+ ",height=" + height
		+ ",screenX=" + screenX + ",screenY=" + screenY /* Netscape */
		+ ",left=" + screenX + ",top=" + screenY /* IE */
	);
	if (nakedImagePopupWindow && !(nakedImagePopupWindow.closed)) {
		nakedImagePopupWindow.close();
	}
	nakedImagePopupWindow = window.open(null, null, features);
	if (altText != null && !isEscaped) {
		altText = encodeEntities(altText);
	}
	var html = ( /* parenthesis for multiline expression */
		'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n'
		+ '<html>\n'
		+ '<head>\n'
		+ '<title>'
		+ ((altText != null) ? altText : 'Photo')
		+ '</title>\n'
		+ '<style type="text/css">\n'
		+ 'html, body { margin: 0; padding: 0; background-color: white; color: black; }\n'
		+ '</style>\n'
		+ '</head>\n'
		+ '<body>\n'
		+ '<img src="' + encodeEntities(imageURL) + '"\n'
		+ ' width="' + imgwidth + '"'
		+ ' height="' + imgheight + '"'
		+ ((altText != null) ? (' alt="' + altText + '"') : "")
		+ ' border="0"'
		+ ' />\n'
		+ '</body>\n'
		+ '</html>\n'
	);
	nakedImagePopupWindow.document.open();
	nakedImagePopupWindow.document.write(html);
	nakedImagePopupWindow.document.close();
}


// Function to open video gallery 
// Uses the 'openPop' function
function openVideoGalleryPopup(url) {
	openPop(url, 780, 730, 'scrollbars,resizable');
}

// Function to get a value from URL
function getValueFromURL(paramName)
{
  var regexS = "[\\?&'&amp;']"+ paramName +"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

// Function to open Email-A-Friend -- ClickQuared version 
// Uses the 'openPop' function
function openEmailafriendPopup(url) {
	encurl= encodeURIComponent(url);
	openPop("http://espanol.geappliances.com/sdforms/dgeconsumerandindustrial/asbs/servlet/SS?F=3123803&C=21036959&product="+encurl, 600, 630, 'scrollbars,resizable');
}




/**************** CHAT SURVEY COOKIE SUPPORT ****************/
var rightNow = new Date().getTime();
var chatCookieName = "chatSurveyCookie"; // Cookie name here

var domainParts = document.domain.split(".");
var domain = domainParts[domainParts.length -2] + "." + domainParts[domainParts.length -1];

//var chatCookieExpires = new Date(rightNow + (365 * 86400000));  //expires in one year
var chatCookieExpires = new Date(rightNow + (365 * 21600000));  //expires in one quarter
//var chatCookieExpires = new Date(rightNow + (60000));  //expires in one minute

var timeUntilSurveyPops = rightNow + 300000; // five minutes


 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));
}

/*	This function should be run somewhere on page after init.
	'surveyDelivery' can have one of two possible values.
		1) "popup" - will display a survey popup
		2) anything else - the ID of the link container
*/
function offerChatSurvey(surveyDelivery,event) {
	
	if ( rightNow > Get_Cookie(chatCookieName) && Get_Cookie(chatCookieName) > 0 ) {
	
		if( surveyDelivery == "popup" ) {
			if(navigator.userAgent.toLowerCase().indexOf("msie 6") != -1) { // skip tooltip for ie6
				openPop("http://espanol.geappliances.com/dgesurveys/survey/133007/2d35/",780,500,'scrollbars,resizable');
			} else {
				showTooltip('chatSurveyTooltip',375,event,this);
			}
			disableChatSurveyCountdown();
		} else {
			document.writeln('<style type="text/css">#'+surveyDelivery+' { display:block !important; }</style>');
		}
		
	}	
}

// sets cookie to 0, eliminating countdown
function disableChatSurveyCountdown() {
	document.cookie = chatCookieName + "=0;path=/;domain=" + domain;
}

// Runs for all pages on load
function firstSetChatSurveyCookie() {
	document.cookie = chatCookieName + "=" + timeUntilSurveyPops + ";path=/;domain=" + domain;
}
if (!Get_Cookie(chatCookieName)) {
	firstSetChatSurveyCookie();
}
/**************** end CHAT SURVEY COOKIE SUPPORT ****************/


// stop hiding -->

