/*****************************************************
 Opens a PopUp Window
 parameters: 
    mylink: page url
    width: optional popup width
    height: optional popup height
    windowname: optional popup window name

*****************************************************/
function closeAndOpenFatherPage (url)
		{
			window.opener.location.href = url;
			window.close();
		}
/*****************************************************/	
function popup(mylink, width, height, windowname)
{
    if (! window.focus)return true;
    if(windowname == "") windowname = 'popupwindow';
    if(width == "") width = '100';
    if(height == "") height = '100';
    var href;
    if (typeof(mylink) == 'string')
        href=mylink;
    else
        href=mylink.href;
    window.open(href, windowname, 'width='+ width +',height='+ height +',scrollbars=no');
    return false;
}
/*****************************************************/
function popupscroll(mylink, width, height, windowname)
{
    if (! window.focus)return true;
    if(windowname == "") windowname = 'popupwindow';
    if(width == "") width = '100';
    if(height == "") height = '100';
    var href;
    if (typeof(mylink) == 'string')
        href=mylink;
    else
        href=mylink.href;
    window.open(href, windowname, 'width='+ width +',height='+ height +',scrollbars=yes');
    return false;
}
/*****************************************************/
function openwindowfulll(url) {
	window.open(url, '_blank','scrollbars=yes,resizable=yes,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,copyhistory=yes', 'top=0, left=0, width='+screen.width+', height='+screen.height);
	window.close();
}
/*****************************************************/
function requiredField( src, args ) 
{
    alert(src.controltovalidate);
    if(args.Value == "" || args.Value.lenght == 0)
    {
        args.IsValid = false;
    }
    else
    {
       args.IsValid = true;
    }
}
/*******************************************************/
function showsubm(varx){
	hide();
	document.getElementById("submenu").style.display = "block";
	document.getElementById("submenubg").style.display = "block";
	document.getElementById(varx).style.display = "block";
	if(varx == "submenu-heres-the-proof"){document.getElementById("menu-heres-the-proof").style.backgroundImage = 'url(images/bt-menu-heres-the-proof_on.jpg)';}
	if(varx == "submenu-how-it-works"){document.getElementById("menu-how-it-works").style.backgroundImage = 'url(images/bt-menu-how-it-works_on.jpg)';}
	if(varx == "submenu-retinol-sa"){document.getElementById("menu-retinol-sa").style.backgroundImage = 'url(images/bt-menu-retinol-sa_on.jpg)';}
}
/*******************************************************/						
function hide(){
	document.getElementById("submenu-heres-the-proof").style.display = "none";
	document.getElementById("submenu-how-it-works").style.display = "none";
	document.getElementById("submenu-retinol-sa").style.display = "none";
	document.getElementById("submenu").style.display = "none";
	document.getElementById("submenubg").style.display = "none";
	document.getElementById("menu-how-it-works").style.backgroundImage = 'url(images/bt-menu-how-it-works.jpg)';
	document.getElementById("menu-heres-the-proof").style.backgroundImage = 'url(images/bt-menu-heres-the-proof.jpg)';
	document.getElementById("menu-retinol-sa").style.backgroundImage = 'url(images/bt-menu-retinol-sa.jpg)';
	
	var sPath2 = window.location.pathname;

	var sPage2 = sPath2.substring(sPath2.lastIndexOf('/') + 1);
    var elems,i,iten;
	elems = document.getElementsByTagName('a');
	  
	   for(i=0;i<elems.length;i++)
	    {
	        if(elems[i].id.indexOf('menuwhatsyourskinage') != -1)
	        {
	            iten = document.getElementById(elems[i].id);
	            break;
	        }
	    }
	    
	    //alert(iten.id);
    
	if(sPage2.indexOf('Quiz_login') >= 0)
	{
		document.getElementById("menu-special-offer").style.backgroundImage = 'url(images/bt-menu-special-offer.jpg)';
	}
	if(sPage2 == 'TrueStories_list.aspx')
	{
		document.getElementById("menu-true-stories").style.backgroundImage = 'url(images/bt-menu-true-stories.jpg)';
	}
	if(sPage2 != 'Quiz_login.aspx' || sPage2 != 'Quiz_tool.aspx')
	{
	   document.getElementById(iten.id).style.backgroundImage = 'url(images/bt-menu-whats-your-skin.jpg)';
	}
}
/*******************************************************/	
function showso(){
	var sPath3 = window.location.pathname;

	var sPage3 = sPath3.substring(sPath3.lastIndexOf('/') + 1);

	if(sPage3.indexOf('Quiz_login') >= 0)
	{
		document.getElementById("menu-special-offer").style.backgroundImage = 'url(images/bt-menu-special-offer_on.jpg)';
	}
	
}
/*******************************************************/
function showts(){
	var sPath4 = window.location.pathname;

	var sPage4 = sPath4.substring(sPath4.lastIndexOf('/') + 1);

	if(sPage4 == 'TrueStories_list.aspx')
	{
		document.getElementById("menu-true-stories").style.backgroundImage = 'url(images/bt-menu-true-stories_on.jpg)';
	}
	
}
/*******************************************************/	
function showtl(){
	var sPath5 = window.location.pathname;

	var sPage5 = sPath5.substring(sPath5.lastIndexOf('/') + 1);
    var elems,i,iten;
    elems = document.getElementsByTagName('a');
     
     for(i=0;i<elems.length;i++)
	    {
	        if(elems[i].id.indexOf('menuwhatsyourskinage') != -1)
	        {
	            iten =  document.getElementById(elems[i].id);
	            break;
	        }
	    }
	
	if(sPage5 != 'Quiz_tool.aspx')
	{
	    //alert('Got it!');
		document.getElementById(iten.id).style.backgroundImage = 'url(images/bt-menu-whats-your-skin_on.jpg)'
	}		
	
}
/*******************************************************/	
function hide2(){
	/*document.getElementById("submenu-heres-the-proof").style.display = "none";
	document.getElementById("submenu-how-it-works").style.display = "none";
	document.getElementById("submenu").style.display = "none";
	document.getElementById("menu-how-it-works").style.backgroundImage = 'url(images/bt-menu-how-it-works.jpg)';
	document.getElementById("menu-heres-the-proof").style.backgroundImage = 'url(images/bt-menu-heres-the-proof.jpg)';*/
	hide();
	var sPath = window.location.pathname;
	 
	 
	   
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	
	var elems,i,iten;
	elems = document.getElementsByTagName('a');
	  
	  for(i=0;i<elems.length;i++)
	    {
	        if(elems[i].id.indexOf('menuwhatsyourskinage') != -1)
	        {
	           iten =  document.getElementById(elems[i].id);
	            break;
	        }
	    }
	if(sPage == 'product-faq.aspx' || sPage == 'product-info-details.aspx' || sPage == 'product-video.aspx' || sPage == 'product-video-commercial.aspx')
	{
		showsubm("submenu-how-it-works")
	}
	if(sPage == 'pore-size.aspx' || sPage == 'firmness.aspx' || sPage == 'age-spots.aspx' || sPage == 'wrinkles-fine-lines.aspx' || sPage == 'heres-the-proof.aspx')
	{
		showsubm("submenu-heres-the-proof")
	}
	if(sPage == 'rsa.aspx' || sPage == 'rsa_forehead.aspx' || sPage == 'rsa_eye.aspx' || sPage == 'rsa_cheek.aspx' || sPage == 'rsa_deep.aspx')
	{
		showsubm("submenu-retinol-sa")
	}
	if(sPage.indexOf('Quiz_login') >= 0)
	{
		document.getElementById("bt-buy-now").style.display = "none";
		document.getElementById("spacing").style.display = "none";
		document.getElementById("menu-special-offer").style.backgroundImage = 'url(images/bt-menu-special-offer_on.jpg)';
	}
	if(sPage == 'TrueStories_list.aspx')
	{
		document.getElementById("menu-true-stories").style.backgroundImage = 'url(images/bt-menu-true-stories_on.jpg)';
	}
	
	if(sPage == 'Quiz_tool.aspx')
	{
		document.getElementById(iten.id).style.backgroundImage = 'url(images/bt-menu-whats-your-skin_on.jpg)'
	}
	
	if(sPage != 'Quiz_tool.aspx')
	{
		document.getElementById(iten.id).style.backgroundImage = 'url(images/bt-menu-whats-your-skin.jpg)'
	}		
      

}
/***************************************/
function loadGoogleAnalytics()
{
    //loading google analytics
	var sPath = window.location.href;

	//loadjscssfile("myscript.js", "js")
	if(sPath.indexOf('https://') == 0)
	{
		gURL =  "https://ssl.google-analytics.com/urchin.js";
       
	}
	else
	{
		gURL = "http://www.google-analytics.com/urchin.js";
	}
	loadjscssfile(gURL, "js")
}
/********************************************/
function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}

