/* Header functions*/
// Tog More for Search
// Tog More for Search
function togMore(sShow)
{
	if (sShow == "hide")
	{
		document.getElementById("srchMoreId").style.display = "none";
	}
	else
	{
		document.getElementById("srchMoreId").style.display = "block";
	}
	return false;
}

function togFootMore(sShow)
{
	if (sShow == "hide")
	{
		document.getElementById("srchFootMoreId").style.display = "none";
	}
	else
	{
		document.getElementById("srchFootMoreId").style.display = "block";
	}
	return false;
}

// Begin : Headers 2 code
function p_o(o){return getEl(o);}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function srchSub(ref){
  var frm=p_o("search");
  var queryval = frm.topquery.value.trim();
  queryval = queryval.replace( /\+/, " ");
  newurl = ref.href + queryval;
  window.location = newurl;
  return false;
}

function searchTarget(url, newWindow, newTarget) {
    // Set the target for the form
    document.bb_topform.action = url;
    if (newWindow) {
        document.bb_topform.target = '_blank';
    } else {
        document.bb_topform.target = '';
    }
    // Update the tabs classes to allow highlighting of the selected
    //var arrElements = ["search-tab-Stylelist","search-tab-Web","search-tab-Blog","search-tab-Video","search-tab-News","search-tab-Images","search-tab-Local"];
    //for (var i=0; i<arrElements.length; i++) {
    for (i=0; i<6; i++) {
        getEl("search-tab-" + i).className = '';
    }
    getEl("search-tab-" + newTarget).className = 'searchCatBg';

    return false;
}

function searchTarget2(url, newWindow, newTarget) {
    // Set the target for the form

    document.bb_bottomform.action = url;
    if (newWindow) {
        document.bb_bottomform.target = '_blank';
    } else {
        document.bb_bottomform.target = '';
    }
    // Update the tabs classes to allow highlighting of the selected
    //var arrElements = ["search-tab-Stylelist2","search-tab-Web2","search-tab-Blog2","search-tab-Video2","search-tab-News2","search-tab-Images2","search-tab-Local2"];
    //for (var i=0; i<arrElements.length; i++) {
    for (i=0; i<6; i++) {
        getEl("search-tab2-" + i).className = '';
    }
    getEl("search-tab2-" + newTarget).className = 'searchCatBg';


    return false;
}

function eventIsEnterKey(event) {
    if (event && event.which == 13 || window.event && window.event.keyCode == 13 || event && event.which == 3 || window.event && window.event.keyCode == 3) {
        return true;
    }
    return false;
}

function submitHeaderSearch(event) {
    if (event == "onclick" || eventIsEnterKey(event)) {
        return srchSub2();        
    } else {
        return true;
    }
}

function srchSub2() {
    var frm=p_o("search");
    var queryval = frm.topquery.value.trim();
    queryval = queryval.replace( /\+/, " ");
    var newurl = frm.action + URLEncode(queryval);
    if (frm.target == '_blank') {
        window.open(newurl, '_blank', '');
    } else {
        window.location = newurl;
    }
    return false;
}

function submitFooterSearch(event) {
    if (event == "onclick" || eventIsEnterKey(event)) {
        return srchSub4();        
    } else {
        return true;
    }
}

function srchSub4() {
    var frm=p_o("search2");
    var queryval = frm.Bottomquery.value.trim();
    queryval = queryval.replace( /\+/, " ");
    var newurl = frm.action + URLEncode(queryval);
    if (frm.target == '_blank') {
        window.open(newurl, '_blank', '');
    } else {
        window.location = newurl;
    }
    return false;
}


//Prevent IE flickr
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

function hideHeaderMore(e) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;

	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	if(targ.id != 'srchMoreAnc' && targ.id != 'srchMoreAnc2') {
 		document.getElementById("srchMoreId").style.display = 'none';
		document.getElementById("srchFootMoreId").style.display = 'none';
	}
}


// ====================================================================
//       URLEncode and URLDecode functions
//
// Copyright Albion Research Ltd. 2002
// http://www.albionresearch.com/
//
// You may copy these functions providing that 
// (a) you leave this copyright notice intact, and 
// (b) if you use these functions on a publicly accessible
//     web site you include a credit somewhere on the web site 
//     with a link back to http://www.albionresearch.com/
//
// If you find or fix any bugs, please let us know at albionresearch.com
//
// SpecialThanks to Neelesh Thakur for being the first to
// report a bug in URLDecode() - now fixed 2003-02-19.
// And thanks to everyone else who has provided comments and suggestions.
// ====================================================================

function URLEncode(textToEncode)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +
// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";
// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = textToEncode;
	var encoded = '';
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				//x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			 
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for
	return encoded;
};

document.onclick = hideHeaderMore;
/*end header functions*/

/* clear input box */
function enterTxt(id) {
    var txt = document.getElementById(id);   
    if (txt.defaultValue == txt.value) {
        txt.value = '';
    }
}
/* shared module popup */
function shareWin(url) {
    w = window.open(url,'stylelistShared','resizable=yes,height=534,width=770');
    if (window.focus) {
        w.focus()
    }
    return false;
}
/* common */
var ratingFlg = true; // If user login info available, change this to true else false
var usrRate = 0;
var isAvgFlag;
function fn_miniSignIn(obj, parentUrl, hostname) {
    
    alert("fn_miniSignIn");
    var parDiv = document.createElement("div");
    parDiv.style.position="absolute";
    parDiv.style.zIndex="100";
    parDiv.style.display="inline";
    parDiv.style.margin="22 -17";
    var innerHtml = ajaxCall("miniSignIn.jsp?parentUrl="+encodeURL(parentUrl)+"&hostname="+hostname);
    parDiv.innerHTML= "<div id='snsMiniUI' style='left: 0px; top: -49px; position: relative; z-index: 5000; display: block;'>"+innerHtml+"</div>";
    obj.appendChild(parDiv);
}

function ajaxCall(url) {
    var page_request = false;
    
    if (window.ActiveXObject){ // if IE
        try {
            page_request = new ActiveXObject("Msxml2.XMLHTTP")
        }
        catch (e){
            try{
                page_request = new ActiveXObject("Microsoft.XMLHTTP")
            }
            catch (e){}
        }
    }
    else if (window.XMLHttpRequest) // if Mozilla, Safari etc
        page_request = new XMLHttpRequest()
    else
        return false
    page_request.open('GET', url, false) //get page synchronously
    page_request.send(null);
    return page_request.responseText;
    
}

var channelURN = '';
var galId = '';
var user = '';

function getEl( id ){ return document.getElementById( id ); }

function selCatAsset(navName) {
 var sblog = 'http://www.stylelist.com/blog';
 if (sblog != location.href) {
  if (document.getElementById(navName) !=null) {
   var ulObjARR = document.getElementById(navName).getElementsByTagName('a');
   for (i=0;i<ulObjARR.length;i++) {
    if (ulObjARR[i].href.match(window.location)) {
     ulObjARR[i].className = 'selected';
     i = ulObjARR.length;
    }
   }
  } 
 }
}
window.onload = function() {
 selCatAsset('categories');
}

/* SNS Login Verification */
function loginCheck() {
    var sitedomain1 = 'sitedomain='+sitedomain;
	var url="siteState="+encodeURIComponent("OrigUrl="+encodeURIComponent(window.location));
	if(_sns_isLoggedIn) {
		getEl("userspan").innerHTML="Logged In: "+_sns_current_user;
		getEl("loginlink").href="https://my.screenname.aol.com/_cqr/logout/mcLogout.psp?"+sitedomain1+"&"+url;
		getEl("loginlink").title="Sign Out";  
		getEl("loginlink").innerHTML="Sign Out";
	} else {
		getEl("loginlink").href="https://my.screenname.aol.com/_cqr/login/login.psp?"+sitedomain1+"&"+url;
		getEl("loginlink").title="Sign In";        	
		getEl("loginlink").innerHTML="Sign In";
	 }
}

/* channel header rollovers */
function removeAll() {
	for (var i=0; i<cat_slugs.length; i++) {
		document.getElementById("chNav_" + cat_slugs[i]).className = "";
	}
}

function changeNav(idToChange) {
	removeAll();
	document.getElementById("chNav_" + idToChange).className = "selected";
}

function returnNav() {
	removeAll();
	
	if (selected_cat == '') {
		if (post_cat == '') {
			var urlStr = new String(document.location);
			urlStr = urlStr.substring(7);
			if (urlStr[urlStr.length - 1] == '/') {
				urlStr = urlStr.substring(0, urlStr.length - 1);
			}
			var urltokens = urlStr.split('/');

			if (urltokens.length == 3) {
				selected_cat = urltokens[2];
			} else {
				selected_cat = "portada";
			}
		} else {
			var catList = post_cat.substring(post_cat.indexOf(">") + 1, post_cat.indexOf("<", 1)).split(',');
			selected_cat = catList[0];
		}
	}
	
	document.getElementById("chNav_" + selected_cat).className = "selected";
}