
function getAuthHost()
{   var destURL = escape( document.location );
    var domain = location.host.toString();
    domain = domain.substring( 0, domain.indexOf( "." ) );
    if( domain.indexOf( "gurl.www--sandbox" ) != -1 )
    {   var host = "http://gurl.www--sandbox.wcp.alloy.inc";
    }
    else if( domain.indexOf( "staging" ) != -1 )
    {   var host = "https://staging.gurl.com";
    }
    else
    {   var host = "https://www.gurl.com";
    }
    return host;
}

function getCookieVal( offset )
{   var endstr = document.cookie.indexOf( ";", offset );
    if( endstr == -1 )
    {   endstr = document.cookie.length;
    }
    return unescape( document.cookie.substring( offset, endstr ) );
}

function getCookie( name )
{   var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while( i < clen )
    {   var j = i + alen;
        if( document.cookie.substring( i, j ) == arg )
        {   return getCookieVal( j );
        }
        i = document.cookie.indexOf( " ", i ) + 1;
        if( i == 0 )
        {   break;
        }
    }
    return null;
}

function displayBoardsLink()
{   var v = getCookie( "iv_id" );
    var vv = getCookie( "iv_auth" );
    if( vv != null && vv != 'NA' )
    {   document.write( "<a href=javascript:void(window.open('http://messageboards.gurl.com/dir-app/bbcard/profile.asp?webtag=gl-rooms&cName=" + v + "','myroom','scrollbars=yes,resizable=yes,height=480,width=640')) class='bNav'>my room</a>" );
    }
    else
    {   document.write( '<a href="http://messageboards.gurl.com/gl-rooms/start" class="bNav">my room</a>' );
    }
}

function displayAccountSettingLink()
{   var destURL = escape( document.location );
    document.write( "<a href='http://www.gurl.com/profile/account' class='bNav'>account settings</a><img src='/i/t.gif' width='1' height='5' border='0' alt='' /><br />" );
}

function displayLogTextFooter()
{   var v = getCookie( "iv_auth" );
    if( v != null && v != 'NA' )
    {   document.write( "<a href='http://www.gurl.com/j_acegi_logout' class='bNav'>log out</a>" );
    }
    else
    {   document.write( "<a href='http://www.gurl.com/login' class='bNav'>log in</a>" );
    }
}

function displayLogTextHeader()
{   var v = getCookie( "iv_auth" );
    if( v != null && v != 'NA' )
    {   document.write( "<a href='http://www.gurl.com/j_acegi_logout' class='shop'>log out</a>" );
    }
    else
    {   document.write( "<a href='http://www.gurl.com/login' class='shop'>log in</a>" );
    }
}

// redirect pages from a dropdown form named newLocation
function jumpPage( newLoc )
{   newPage = newLoc.options[newLoc.selectedIndex].value;
    if( newPage != '' )
    {   document.location = newPage;
    }
}

function getQueryParamValue( param )
{   var q = document.location.search;
    var detectIndex = q.indexOf( param );
    var endIndex = (q.indexOf( "&", detectIndex ) != -1 ) ? q.indexOf( "&", detectIndex ) : q.length;
    if( q.length > 1 && detectIndex != -1 )
    {   var thisNum = unescape( q.substring( q.indexOf( "=", detectIndex ) + 1, endIndex ) );
        return thisNum;
    }
    else
    {   return "";
    }
}





<!-- hide
// Begin Version Detection
isDOM  = (document.getElementById);
isNS4  = (document.layers);
isIE   = (document.all);
isIE4  = (isIE && !isDOM);
isMac  = (navigator.appVersion.indexOf("Mac") != -1);
isIE4M = (isIE4 && isMac);
isIE5M = isDOM && isIE && isMac;
isIE5W = isDOM && isIE && !isMac;
isNS6 =  isDOM && (navigator.vendor == ("Netscape6") || navigator.product == ("Gecko"));
// End Version Detection
iv_verticalID = "";

// Scriptlets
/*
if (typeof iv_scriptletIncluded_cta == "undefined") { document.write("<scr"+"ipt language=\"javascript\" type=\"text/javascript\" src=\"http://www.ivillage.com/shared/js/scriptlets/0,,cta,00.js\"></scr" + "ipt>"); var iv_scriptletIncluded_cta = 1; }
if (typeof iv_scriptletIncluded_utilities == "undefined") { document.write("<scr"+"ipt language=\"javascript\" type=\"text/javascript\" src=\"http://www.ivillage.com/shared/js/scriptlets/0,,utilities,00.js\"></scr" + "ipt>"); var iv_scriptletIncluded_utilities = 1; }
if (typeof iv_scriptletIncluded_json == "undefined") { document.write("<scr"+"ipt language=\"javascript\" type=\"text/javascript\" src=\"http://www.ivillage.com/shared/js/scriptlets/0,,json,00.js\"></scr" + "ipt>"); var iv_scriptletIncluded_json = 1; }
*/

// Reads a query string from the URL. Pass in the key name and get back the value. */
function queryString(keyName) {
var keyValue = "";
keyName = keyName.toUpperCase() + "=";

if (window.location.href.indexOf("?") != -1) {
     var queryString = window.location.href.substring(window.location.href.indexOf("?")+1);
     var searchString = queryString.toUpperCase();
     if (searchString.indexOf(keyName) != -1) {
      var keyValueStart = parseInt(searchString.indexOf(keyName)) + keyName.length;
      var keyValueEnd = searchString.indexOf("&", keyValueStart);
      var keyValueEnd = (keyValueEnd != -1) ? keyValueEnd : searchString.length;
      keyValue = queryString.substring(keyValueStart,keyValueEnd);
     }

     var plusPos = keyValue.indexOf('+');
     while (plusPos != -1) {
         keyValue = keyValue.substring(0, plusPos) + " " + keyValue.substring(plusPos + 1, keyValue.length);
         plusPos = keyValue.indexOf('+');
     }
}
return unescape(keyValue);
}

// Verifies search input. To be deleted.
// @param Form to be checked.
// @return true/false depending on validation.
function processFindIt (box) {
    mt = box.qry.value;
    if (mt.length == 0) {
        alert ('Your search could not be completed because no search words were entered.');
        return false;
    }
}

/*
// To be deleted
// Submit handler. Verifies search input. Alters action depending on button pushed.
// Script will check for optional global shadow tags (shadowTagAJ & shadowTagG)
// @param inputForm Form object to be checked.
// @return boolean value if form is valid or not.
function handleSearchSubmit(inputForm) {
    // Check for shadow tags
    var shadowAJ = typeof(shadowTagAJ) == 'undefined' ? "" : shadowTagAJ;
    var shadowG = typeof(shadowTagG) == 'undefined' ? "" : shadowTagG;

    mt = inputForm.qry.value;
    if (mt.length == 0) {
        alert ('Your search could not be completed because no search words were entered.');
        inputForm.qry.focus();
        inputForm.qry.select();
        return false;
    }

    for (var i = 0; i < inputForm.alias.length; i++) {
        if (inputForm.alias[i].checked) {
            var selectedValue = inputForm.alias[i].value;
        }
    }

    if (selectedValue == "google") {
        inputForm.action = shadowG + "http://search.ivillage.com/google/";
    } else {
        inputForm.action = shadowAJ + "http://findit.ivillage.com/find/";
    }

    return true;
}


// Submit handler. Verifies search input. Alters action depending on button pushed.
// @param inputForm Form object to be checked.
// @return boolean value if form is valid or not.
function handleGoogleSubmit(inputForm) {
    mt = inputForm.q.value;
    if (mt.length == 0) {
        alert ('Your search could not be completed because no search words were entered.');
        inputForm.q.focus();
        inputForm.q.select();
        return false;
    }

    for (var i = 0; i < inputForm.restrict.length; i++) {
        if (inputForm.restrict[i].checked) {
            var selectedValue = inputForm.restrict[i].value;
        }
    }
    var skin = inputForm.sk.value;

    if (selectedValue == "") {
        if (skin == "ivi") {
            inputForm.action = "http://search.ivillage.com/search/web";
        } else if (skin == "gur") {
            inputForm.action = "http://search.ivillage.com/search/webgurl";
        } else if (skin == "wom") {
            inputForm.action = "http://search.ivillage.com/search/webwomen";
        } else if (skin == "ast") {
            inputForm.action = "http://search.ivillage.com/search/web";
        }
        return true;
    } else if (selectedValue == "Astrology") {
        inputForm.action = "http://search.ivillage.com/search/ivillage";
    } else if (selectedValue == "gURL") {
        inputForm.action = "http://search.ivillage.com/search/gurl";
    } else if (selectedValue == "Women") {
        inputForm.action = "http://search.ivillage.com/search/women";
    } else {
        inputForm.action = "http://search.ivillage.com/search/ivillage";
    }
    myInput = document.createElement("INPUT");
    myInput.name="filter";
    myInput.id="idFilter";
    myInput.value="p";
    myInput.type="hidden";
    inputForm.appendChild(myInput);
    return true;
}
*/

// interstitial for tool front ends
function popAdTFE (subForm) {
  if (subForm.useCookie != null) {
    if (GetCookie('ivQuiz') == null) {
      SetCookie('ivQuiz', 'yes', '', '', '.ivillage.com');
    } else {
      return true;
    }
  }
  ivAD=window.open('/interquizzal/frame/0,,'+subForm.hidden_ID.value+',00.html' ,'ivAd',"WIDTH=480,HEIGHT=515");
  quizForm = subForm;
  setInterval("ivAD.close();",15000);
  if (navigator.platform == 'MacPPC') {
    timerID = setInterval("if (ivAD.closed || !ivAD) {quizForm.submit(); clearInterval(timerID);}",1000);
  } else {
    setInterval("quizForm.submit();",15100);
  }
  return false;
}

// Select box redirector (opens in same window)
function newpage(box) {
  if (box.options[box.selectedIndex].value == '') { return; }
  document.location.href = box.options[box.selectedIndex].value;
}

function pleasedontGo(box) {
  if (box.selectedIndex == -1) { alert('Please select a value first.'); return; }
  val = box.options[box.selectedIndex].value; window.open (val,'_top'); }

// Select box redirector (opens in new window)
function windowRedirect (selectBox) {
  if (selectBox.selectedIndex == -1) {
    alert("Please select a value first.");
    return;
  }

  val = selectBox.options[selectBox.selectedIndex].value;
  window.open (val,'_top');
}

// 4th Column redirector (opens in new window)
function pleasedoGo(box) {
  if (box.selectedIndex == -1) {
    alert('Please select a value first.');
    return;
  }

  if (box.options[box.selectedIndex].value == '') { return; }
  val = box.options[box.selectedIndex].value;
  window.open (val,'sponsor');
}

// Generic window opener (need to pass html)
function newWin(width, height, bgcolor, lcolor, name, title, content) {
  popupWin = window.open("", name, "scrollbars,width=" + width + ",height=" + height);
  if (popupWin == null) {window.open("", name, "width=" + width + ",height=" + height);}
  // the funkiness below is to prevent nesting of the scr*pt tags
  var m = "<html>\n<head><title>" + title + "</title>\n<scrip" + "t language=javascript>function t() {}</scrip" + "t></head>\n<body bgcolor=#" + bgcolor + " link=#" + lcolor + " alink=#" + lcolor + " vlink=#" + lcolor + ">\n";
  m += content;
  m += "</body>\n</html>";
  popupWin.document.write(m);
  popupWin.document.close();
  popupWin.focus();
}

// CIMS form handler.
// Checks the email field, and sets cid and cid fields. All CIMS forms MUST have
// these fields.
function processCIMS (theForm,popUp) {
   // See if we have any spaces.
    var space = theForm.email.value.indexOf(" ");
    if (space != -1) {
    alert("Please check your email address");
    return false;
    }

    var pos1 = theForm.email.value.indexOf("@");
    if (pos1 < 1) {
    alert("Please check your email address");
    return false;
    }
    var email = theForm.email.value.substr(pos1 + 1);
    var pos2 = theForm.email.value.indexOf(".");
    if (pos2 < 1 || theForm.email.value.substr(pos2 + 1) == "" || (pos2 - pos1) == 1) {
    alert("Please check your email address");
    return false;
    }


  if (typeof(cimsCid) != 'undefined') {
    theForm.cid.value=cimsCid;
  }

  if (typeof(cimsUid) != 'undefined') {
    theForm.uid.value=cimsUid;
  }

  // Append the email address to the rurl.
  //theForm.rurl.value += "?email=" + theForm.email.value;

  // If popUp is specified, open CIMS in a new window.
  if (popUp == 'y') {
    cimsWindow = window.open('','cimsWindow',"WIDTH=770,HEIGHT=600,scrollbars=yes,toolbar=yes,resizable=yes,location=yes,menubar=yes,statusbar=yes");
    theForm.target = 'cimsWindow';
    return true;
  } else {
    return true;
  }
}



function isValidEmail( email ) {
    // See if we have any spaces.
    var space = email.indexOf(" ");
    if (space != -1) { return false; }

    var pos1 = email.indexOf("@",1);
    if (pos1 < 1) { return false; }
    var email = email.substr(pos1 + 1);
    var pos2 = email.indexOf(".",1);
    if (pos2 < 1 || email.substr(pos2 + 1) == "") { return false; }
    return true;
}
// @param thisForm Form object to be tested
// @param popUp checks for popUp window
// @return true/false
function doNewsletterSubmit(theForm,popUp) {
    theForm.ip.value = document.location.href;
    theForm.action="https://subscriber.ivillage.com/sagews"    //Get Server Environment
    if (!isValidEmail(theForm.email.value)) {
      alert("Enter valid email address");
      return false;
    }

    if (theForm.r.value == "") { theForm.r.value = "http://www.ivillage.com/ivillage/thankyou/newsletters"; }
    if (popUp == 'y') {
        sageWindow = window.open('','sageWindow',"WIDTH=500,HEIGHT=500,scrollbars=yes,toolbar=yes,resizable=yes,location=yes,menubar=yes,statusbar=yes");
        theForm.target = 'sageWindow';
        theForm.submit();
        return false;
    } else {
        theForm.submit();
        return false;
    }

}

// @param thisForm Form object to be tested
// @param popUp checks for popUp window
// @return true/false
function doFunnel4Submit( theForm, popUp ) {
    theForm.action = "https://subscriber.ivillage.com/funnels/4/";
    if( !isValidEmail( theForm.email.value ) ) {
        alert( "Enter valid email address" );
        return false;
    }
    if( popUp == 'y' ) {
        sageWindow = window.open( '', 'sageWindow', "WIDTH=720,HEIGHT=500,scrollbars=yes,toolbar=yes,resizable=yes,location=yes,menubar=yes,statusbar=yes" );
        theForm.target = 'sageWindow';
        theForm.submit();
        return false;
    }
    else {
        return true;
    }
}


// ===== Cookie Code =====
var ckToday = new Date();

function getCookieVal( offset ) {
    var endstr = document.cookie.indexOf( ";", offset );
    if( endstr == -1 ) {
        endstr = document.cookie.length;
    }
    return unescape( document.cookie.substring( offset, endstr ) );
}

function GetCookie( name ) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while( i < clen ) {
        var j = i + alen;
        if( document.cookie.substring( i, j ) == arg ) {
            return getCookieVal( j );
        }
        i = document.cookie.indexOf( " ", i ) + 1;
        if( i == 0 ) {
            break;
        }
    }
    return null;
}

function DeleteCookie( name, path, domain ) {
    if( GetCookie( name ) ) {
        document.cookie = name + "=" + "; path=" + ( ( path ) ? path : "/" ) + ( ( domain ) ? "; domain=" + domain : "" ) + "; expires=Thu, 01-Jan-1970 00:00:01 GMT";
    }
}

function SetCookie( name, value, expires, path, domain ) {
    // expires represents a value in days
    var ckToday = new Date();
    if( expires != null ) {
        var exp = new Date( ckToday.getTime() + expires * 24 * 60 * 60 * 1000 );
    }
    document.cookie = name + "=" + escape( value ) + ( ( expires ) ? "; expires=" + exp.toGMTString() : "" ) + "; path=" + ( ( path ) ? path : "/" ) + ( ( domain ) ? "; domain=" + domain : "" );
}

function setIntervalCookie( name, value, interval, mode ) {
    var now = new Date();
    var aDay = 86400000;
    var aHour = 3600000;
    var aMinute = 60000;
    var aSec = 1000;
    if( mode == 'days' ) {
        //this gets the precise seconds to set the cookie, calculating the days (not 24hours)
        now.setTime( now.getTime() + ( ( interval - 1 ) * aDay ) + ( 24 - now.getHours() ) * aHour + aMinute );
    }
    else if( mode == 'hours' ) {
        now.setTime( now.getTime() + interval * aHour );
    }
    //now set the cookie
    document.cookie = name + "=" + escape( value ) + "; expires=" + now.toGMTString() + "; path=/";
}
// ===== End Cookie Code =====

if( !window.saveInnerWidth ) {
    window.onresize = resize;
    window.saveInnerWidth = window.innerWidth;
    window.saveInnerHeight = window.innerHeight;
}

function resize() {
    if( saveInnerWidth < window.innerWidth ||
        saveInnerWidth > window.innerWidth ||
        saveInnerHeight > window.innerHeight ||
        saveInnerHeight < window.innerHeight )
    {
        window.history.go( 0 );
    }
}

// Feedroom video popup
function iv_FRPop( url ) {
    popupWindow = window.open( url, "videoPopup", "width=800,height=500,location=yes,toolbar=yes,status=yes,resizable=yes,scrollbars=yes,menubar=yes,left=10,top=10" );
    popupWindow.focus();
}

function challengeUser() {
    // Validate user
    if( GetCookie( 'temp_auth' ) != "logged" && ( queryString( "pp_user" ) == "" && queryString( "pp_ticket" ) == "" ) ) {
        document.location = "https://subscriber.ivillage.com/funnels/7?vrt=pp&prd=pregcl&dd=" + escape( document.location );
    }
    else {
        SetCookie( 'temp_auth', 'logged' );
    }
}
// end hide -->


cookieName = "gurlQuoteSave" ;

function save( oid ) {
    var cookieValue = oid ;
    var existingCookie = GetCookie( cookieName );
    if( existingCookie != null ) {
        cookieValue = oid + "-" + existingCookie;
    }
    SetCookie( cookieName, cookieValue );
    return true;
}

function submitSearch( theForm )
{   qry = theForm.qry.value;
    if( qry == "" )
    {   alert( "Please enter your search terms." );
        return false;
    }
    if( theForm.restrict[0].checked )
    {   theForm.action = "http://search.gurl.com/search/gurl?q=" + escape( theForm.qry.value ) + "&amp;restrict=gurl";
    }
    else
    {   theForm.action = "http://search.gurl.com/search/webgurl?q=" + escape( theForm.qry.value );
    }
    return true;
}

function toggleVisibility( id, isVis, obj )
{   IMG_PREFIX = "arrow";
    var moreNav = new Array();
    moreNav[0] = "";
    moreNav[1] = "con";
    moreNav[2] = "fin";
    moreNav[3] = "pla";
    moreNav[4] = "sho";
    moreNav[5] = "rea";
    moreNav[6] = "exp";
    var g_ImgExpanded = "/images/nav/top/nav_" + moreNav[obj] + "_more_on.gif";
    var g_ImgCollapsed = "/images/nav/top/nav_" + moreNav[obj] + "_more_off.gif";
    if( document.getElementById )
    {   if( isVis )
        {   eval( "document.getElementById(id).style.display = '' " );
            document.images[IMG_PREFIX + obj].src = g_ImgExpanded;
        }
        else
        {   eval( "document.getElementById(id).style.display = 'none' " );
            document.images[IMG_PREFIX + obj].src = g_ImgCollapsed;
        }
    }
}


function feedback2( box )
{   if ( !window.S2F_altURL )
    {   s2fURL = window.document.location.href;
    }
    else
    {   s2fURL = S2F_altURL;
    }
    // var s2fURL = 'http://' + location.host + s2fURL;
    var w = 470, h = 600, cw = w/2, ch = h/3;
    if( window.screen )
    {   cw = Math.floor( ( screen.availWidth - w ) / 2 );
        h = Math.floor( ( screen.availHeight - h ) / 3 );
    }
//    var mywin = window.open( '/feedback/0,,,00.html?s2fURL=' + escape( s2fURL ) + '&amp;mc=' + box.mc.value + '&amp;comments=' + box.comments.value + '&amp;s2fTitle=' + escape( window.document.title ), 's2f', 'width=470,height=600,top=' + ch + ',left=' + cw + ',scrollbars=yes' );
    var mywin = window.open( '/feedback.vm?s2fURL=' + escape( s2fURL ) + '&amp;mc=' + box.mc.value + '&amp;comments=' + box.comments.value + '&amp;s2fTitle=' + escape( window.document.title ), 's2f', 'width=470,height=600,top=' + ch + ',left=' + cw + ',scrollbars=yes' );
    return false ;
}



////////////////////////////////////////////////////////////////////////////////////////
// Paperdoll Game functions
////////////////////////////////////////////////////////////////////////////////////////
function subForm( theForm ) {
    var nextPagePath = theForm.nextPagePath.value;
    var oid = theForm.contentID.value + "-";
    oid = oid + getRadioValue( theForm.top );
    oid = oid + getRadioValue( theForm.mid );
    oid = oid + getRadioValue( theForm.bot );
    theForm.action = nextPagePath + "/0,," + oid + ",00.html";
    return true;
}

function getRadioValue( theRadio ) {
    for( i = 0; i < theRadio.length; i++ ) {
        if( theRadio[i].checked ) {
            return theRadio[i].value;
        }
    }
}



////////////////////////////////////////////////////////////////////////////////////////
// Search functions
////////////////////////////////////////////////////////////////////////////////////////
/*
function getSrchForm(id) {
	if (id==="our_web_picks") {
		$('all_the_web_form').hide();
		$('our_web_picks_form').show();
		$('our_web_picks').addClassName("active_link");
		$('all_the_web').removeClassName("active_link");
	} else if (id==="all_the_web" ) {
		$('our_web_picks_form').hide();
		$('all_the_web_form').show();
		$('all_the_web').addClassName("active_link");
		$('our_web_picks').removeClassName("active_link");		
	} else {
		alert("unknown id: " + id + " in masthead-noad.vm");
	}
}
*/
