
/*****************************************************
 Opens a PopUp Window
 parameters: 
    mylink: page url
    width: optional popup width
    height: optional popup height
    windowname: optional popup window name
    
*****************************************************/
function IsMail(mail)
{
    if ( mail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1 ) {
		return true;
	} else {
		return false;
	}
}
/*****************************************************/


/*****************************************************
 Opens a PopUp Window
 parameters: 
    mylink: page url
    width: optional popup width
    height: optional popup height
    windowname: optional popup window name
    
*****************************************************/
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=yes');
    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 popupNormalWindow(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, menubar=yes, resizable=yes, status=yes, toolbar=yes, directories=yes');
    return false;
}

/*****************************************************/
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)';}
}
/*******************************************************/						
function hide(){
	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("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)';
	
	var sPath2 = window.location.pathname;

	var sPage2 = sPath2.substring(sPath2.lastIndexOf('/') + 1);

	if(sPage2.indexOf('SpecialOffer') >= 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("menu-whats-your-skin-age").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('SpecialOffer') >= 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);

	if(sPage5 == 'Quiz_login.aspx' || sPage5 == 'Quiz_tool.aspx')
	{
		document.getElementById("menu-whats-your-skin-age").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);
	
	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.indexOf('SpecialOffer') >= 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_login.aspx' || sPage == 'Quiz_tool.aspx')
	{
		document.getElementById("menu-whats-your-skin-age").style.backgroundImage = 'url(images/bt-menu-whats-your-skin_on.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)
}

function ShowDiv(divObject){
    var div = document.getElementById(divObject.id);
    alert(div.style["display"].value);
    /*
    if(div.style["display"].value == "none")
        div.style["display"].value = "block";
    else
        div.style["display"].value = "none";
    */
}


/*****************************************************/
/* Client-side access to querystring name=value pairs
	Version 1.3
	28 May 2008
	
	License (Simplified BSD):
	http://adamv.com/dev/javascript/qslicense.txt
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};
	
	if (qs == null) qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i = 0; i < args.length; i++) {
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);
		
		var value = (pair.length==2)
			? decodeURIComponent(pair[1])
			: name;
		
		this.params[name] = value;
	}
}

Querystring.prototype.get = function(key, default_) {
	var value = this.params[key];
	return (value != null) ? value : default_;
}

Querystring.prototype.contains = function(key) {
	var value = this.params[key];
	return (value != null);
}
