function nav( itemnum )
{
	var oCmElement;
	
	//For Coremetric tagging
	if (typeof CM_ShopCatID != 'undefined')
	{
		oCmElement = document.getElementById("cm_scid");
		if (oCmElement)
		{
			oCmElement.value = CM_ShopCatID;
		}
	}
	
	tpl 	= "de";
	sc  	= document.fNav.sc.value;
	cc  	= document.fNav.cc.value;
	from	= document.fNav.from.value;
	navlist = document.fNav.navlist.value;
	
	if (oCmElement)
		cm_scid = document.fNav.cm_scid.value;
	
	// create the qic link (using the ? format since we may have illegal, *, chars)
	fNav_action = "http://www.qvc.de/deqic/qvcapp.aspx?app=detail&params=item^" + itemnum + 
		      ",tpl^" + tpl + 
		      ",sc^" + sc + 
		      ",cc^" + cc + 
		      ",from^" + from +
		      ",navlist^" + navlist;
		
	//Do we have a Session Id?  If so, add it to action attribute.
	//Session Id is required for cookieless checkout.
	if (typeof RequestSessionIdQic != 'undefined')				// Session Id variable present?
	{
		if (RequestSessionIdQic.length > 0)									// Session Id contains a value?
		{
			fNav_action += ",iqvcid^" + RequestSessionIdQic;
		}
	}
		
	if (oCmElement)
		fNav_action += ",cm_scid^" + cm_scid;
	
	window.location = fNav_action;
}

function buy( itemnum )
{
	document.fNav.elements[0].value=itemnum;
	document.fNav.elements[1].value="debuynow";
	document.fNav.elements[2].value="";
	document.fNav.elements[3].value="";
	document.fNav.submit();
}

function nav1( itemnum,cc,sc )
{
	document.fNav.elements[0].value=itemnum;
	document.fNav.elements[1].value="de";
	document.fNav.elements[2].value=sc;
	document.fNav.elements[3].value=cc;
	document.fNav.submit();
}

function plnav( itemnum, cont )
{
	prepYAH();
	document.fNav.item.value=itemnum;
	document.fNav.sc.value="";
	document.fNav.cc.value="";
	document.fNav.cont.value=cont;

	document.fNav.submit();
}

function detailnav(itemNum)
{

	document.fNav.item.value  = itemNum;
	document.fNav.submit();

}

function prepYAH() {

  if (!(document.fNav.yahlevel)) {
    return;
  }
  if (document.fNav.yahparent.value == "search") {
    return;  // This function not needed for search-based YAH bar
  }
  else {
    document.fNav.yahlevel.value = 0;
  }
// Drilldown-based YAH bar
  if ( (document.yahinfo) && (document.yahinfo.ccode1) ) {
    var yahlevel = 1;
    var yahsub = "";
    var yahparent = "";
    var yahendclass = "";
    var yahsortkey = "";
    var yahstind = "";
    var yahclass = document.yahinfo.ccode1.value+'~';
    var yahnames = document.yahinfo.cname1.value+'~';

    if (document.yahinfo.ccode2) {
      yahlevel = 2;
      yahclass += document.yahinfo.ccode2.value+'~';
      yahnames += document.yahinfo.cname2.value+'~';
      if (document.yahinfo.cparent2) {
        yahparent = document.yahinfo.cparent2.value;
      }

      if (document.yahinfo.ccode3) {
        yahlevel = 3;
        if (document.yahinfo.yah3) {
          yahsub = document.yahinfo.yah3.value+',';
        }
        else {
          yahsub = yahclass+',';
        }
        yahclass += document.yahinfo.ccode3.value+'~';
        yahnames += document.yahinfo.cname3.value+'~';

        if (document.yahinfo.ccode4) {
          yahlevel = 4;
          if (document.yahinfo.yah4) {
            yahsub += document.yahinfo.yah4.value+',';
          }
          else {
            yahsub += yahclass+',';
          }
          yahclass += document.yahinfo.ccode4.value+'~';
          yahnames += document.yahinfo.cname4.value+'~';

          if (document.yahinfo.ccode5) {
            yahlevel = 5;
            if (document.yahinfo.yah5) {
              yahsub += document.yahinfo.yah5.value+',';
            }
            else {
              yahsub += yahclass+',';
            }
            yahclass += document.yahinfo.ccode5.value+'~';
            yahnames += document.yahinfo.cname5.value+'~';
          } //level 5
        } //level 4
      } //level 3
    } //level 2

  // Grab current class code and label
    if (document.yahinfo.lname) {
		yahnames += document.yahinfo.lname.value+'~';
		yahclass += document.yahinfo.endclass.value+'~';
		yahlevel++;
    }
	else {
	// Grab current sort type
	  if (document.yahinfo.sorttype) {
	    var currClass = getVarFromURL("class");
	    if (currClass != "error") {
	      yahnames += document.yahinfo.sorttype.value+'~';
	      yahclass += currClass+'~';
	      yahstind = "1";
	      yahlevel++;
	    }
	  }
	}

  // Grab current sub YAH
	if (yahlevel >= 3) {
	  var addYahSub = getVarFromURL("yah");
	  if (addYahSub != "error") {
	    yahsub += addYahSub+',';
	  }
	}
	else {
	  yahsub = "0";
	}

  // Grab current sortkey
//    if (document.frmPagingHead.sortkey) {
//     yahsortkey = getSortKey(document.frmPagingHead.sortkey);
//   }

  // Copy YAH info to fNav to use in the Product Detail page
    document.fNav.yahlevel.value = yahlevel;
    document.fNav.yahclass.value = yahclass;
    document.fNav.yahnames.value = yahnames;
    document.fNav.yahparent.value = yahparent;
    document.fNav.yahendclass.value = yahendclass;
    document.fNav.yahsub.value = yahsub;
    document.fNav.yahsort.value = yahsortkey;
    document.fNav.yahsorttypeind.value = yahstind;
  } //level 1 - of Drilldown-based YAH

//  else {
    // 24 Hour Product Review based YAH bar
//    if (document.prodreview) {
//      if (document.prodreview.showname) {
//        document.fNav.yahlevel.value = 24;
//        document.fNav.yahnames.value = document.prodreview.showname.value;
//      }
//      if (document.prodreview.datetime) {
//        document.fNav.yahsub.value = document.prodreview.datetime.value;
//      }
//      if (document.prodreview.tz) {
//        document.fNav.yahclass.value = document.prodreview.tz.value;
//      }
//    }
//  } // 24-Hour

} // prepYAH

function getVarFromStandardURL(varName_in) {
	// Retrieves the first instance of the requested var from the current page URL
	
	// http://www.qvc.com/navigationapp/QVCNavigate.aspx?type=rightnav&class=F377&level=3&yah=C500~F396&tmp=ddsn&cont=F377&cm_re=PAGE-_-DEPARTMENTS-_-RINGS

	var currURL = new String(document.URL);
	var varName = new String(varName_in);
	var startIdx = currURL.indexOf(varName+"=");
	if (startIdx == -1) { return "error"; }  // Var Name was not found in the URL
	startIdx += varName.length + 1;  // Advance index to beginning of value
	var varValue = "";
	var currChar = currURL.charAt(startIdx++);
	while ( (currChar != '&') && (currChar != '') ) {
		varValue += currChar;
		currChar = currURL.charAt(startIdx++);
	}
	return unescape(varValue);
}

function getVarFromQICURL(varName_in) {
	// Retrieves the first instance of the requested var from the current page URL
	
	// http://www.qvc.com/qic/qvcapp.aspx/app.nav/params.class.G930.level.3/walk.yah.0011-2403?tmp=ddsn&cont=G930&cm_re=PAGE-_-DEPARTMENTS-_-CARPETFLOORCLEANERS

	var currURL = new String(document.URL);
	var varName = new String(varName_in);
	var startIdx = currURL.indexOf("."+varName+".");
	if (startIdx == -1) { return "error"; }  // Var Name was not found in the URL
	startIdx += varName.length + 2;  // Advance index to beginning of value
	var varValue = "";
	var currChar = currURL.charAt(startIdx++);
	while ( (currChar != '.') && (currChar != '') && (currChar != '?') && (currChar != '/') && (currChar != '&') ) {
		varValue += currChar;
		currChar = currURL.charAt(startIdx++);
	}
	return unescape(varValue);
}

function getVarFromURL(varName_in) {
	// Retrieves the first instance of the requested var from the current page URL
	var currURL = new String(document.URL);
	
	if( currURL.indexOf( "/qvcapp.aspx/" ) != -1 )
	{
		return getVarFromQICURL( varName_in );
	}
	else
	{
		return getVarFromStandardURL( varName_in );
	}
	return "error";
}

