/* BEGIN: SUCKERFISH :hover for IE6 (used on drop-downs)
 * 
 * The suckerfish hover method mimics the :hover pseudo-class
 * for IE6 on any element by dynamically adding the sfHover class.
 * More info: http://www.htmldog.com/articles/suckerfish/hover/
 * 
 * This is globally applied for navigation, footer, and rss hovers.
 * Application is per element.  Add more here as necessary.
 * And don't forget, this is for IE6 only.
 */
/*sfHover = function() {
	
		var sfEls = document.getElementById("country_container");
		
	    var sfSelector = document.getElementById("country_selector");
	    
		sfEls.onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls.onmouseout=function() {
		    //sfSelector.style.display = "none";
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

*/
sfHover = function() {
	var sfEls = document.getElementById("country_container").getElementsByTagName("li");
	
	
	if (document.getElementById("navigation_container"))
	{
	    var sfEls3 = document.getElementById("navigation_container").getElementsByTagName("li");
	    
	    for (var i=0; i<sfEls3.length; i++) {
		    sfEls3[i].onmouseover=function() {
			    this.className+=" sfhover";
		    }
		    sfEls3[i].onmouseout=function() {
			    this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		    }
	    }
	}
	
	if (document.getElementById("ph_navigation_container"))
	{
	    var sfEls4 = document.getElementById("ph_navigation_container").getElementsByTagName("li");
	    
	    for (var i=0; i<sfEls4.length; i++) {
		    sfEls4[i].onmouseover=function() {
			    this.className+=" sfhover";
		    }
		    sfEls4[i].onmouseout=function() {
			    this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		    }
	    }
	}
	
	if (document.getElementById("leftnav_container"))
	{
	    var sfEls5 = document.getElementById("leftnav_container").getElementsByTagName("li");
	    
	    for (var i=0; i<sfEls5.length; i++) {
		    sfEls5[i].onmouseover=function() {
			    this.className+=" sfhover";
		    }
		    sfEls5[i].onmouseout=function() {
			    this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		    }
	    }
	}
	
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
			//sfSelector.style.margin="auto";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}


	
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


/* END: SUCKERFISH :hover */

//product page enlarge image function

 function showLargeImg() {

	        $("#products-large-image-pop").fadeIn();
	        $("#products-large-image-pop img.large-image").hide();
	        if (typeof(itemIndex)=="undefined")
	            itemIndex = "0";
}

 function showLargeImg1() {

	        $("#board-large-image-pop1").fadeIn();
	        $("#board-large-image-pop1 img.large-image").hide();
	        if (typeof(itemIndex)=="undefined")
	            itemIndex = "0";
}

 function showLargeImg2() {

	        $("#board-large-image-pop2").fadeIn();
	        $("#board-large-image-pop2 img.large-image").hide();
	        if (typeof(itemIndex)=="undefined")
	            itemIndex = "0";
}

 function showLargeImg3() {

	        $("#board-large-image-pop3").fadeIn();
	        $("#board-large-image-pop3 img.large-image").hide();
	        if (typeof(itemIndex)=="undefined")
	            itemIndex = "0";
}

 function showLargeImg4() {

	        $("#board-large-image-pop4").fadeIn();
	        $("#board-large-image-pop4 img.large-image").hide();
	        if (typeof(itemIndex)=="undefined")
	            itemIndex = "0";
}

 function showLargeImg5() {

	        $("#board-large-image-pop5").fadeIn();
	        $("#board-large-image-pop5 img.large-image").hide();
	        if (typeof(itemIndex)=="undefined")
	            itemIndex = "0";
}

 function showLargeImg6() {

	        $("#board-large-image-pop6").fadeIn();
	        $("#board-large-image-pop6 img.large-image").hide();
	        if (typeof(itemIndex)=="undefined")
	            itemIndex = "0";
}

/* TO MAKE A SPECIFIC TAB ON PRODUCTS PAGE ACTIVE */

function activeTab(param)
{ 
    //When any link is clicked
    //test to stop any playing videos
    try {
        if (flashMovie)
	        flashMovie.videoURL("");
    }
        catch(err)
    {
        //do nothing	
    }
    $('#tabs ul li').removeClass('active'); // Remove active class from all links
    var currentListItem = "#tabs ul li:eq(" + (parseInt(param) - 1) + ")";
    $(currentListItem).addClass('active'); //Set clicked link class to active
    var currentTab = "#tab-" + param; // Set variable currentTab to value of href attribute of clicked link
    $('#tabs > div').hide(); // Hide all divs
    //$('#tabs div div').show(); //Override for divs within parent div
    $(currentTab).show(); // Show div with id equal to variable currentTab
    return false;
}

function checkActiveTabs()
{
    //get querystring.  if dtab exists, then process activetab to show.
    
    tabValue = "";
    
    if (queryString("dTab"))
        activeTab(queryString("dTab"));
        
}


function queryString(theString) {
	qString = window.location.search.substring(1);
	qStringArray = qString.split("&");
	for (i=0;i<qStringArray.length;i++) {
		getString = qStringArray[i].split("=");
		if (getString[0] == theString) {
			return getString[1];
		}
	}
}


/* GLOBAL STICKY NAV */

$(document).ready(function() {
	
	var rootPath = location.pathname.split("/");
	
    if (rootPath[1] == "crest-products")
        document.getElementById("nav1").className = "liNavActive";
    if (rootPath[1] == "teeth-whitening")
        document.getElementById("nav2").className = "liNavActive";
    if (rootPath[1] == "crest-whitening-results")
        document.getElementById("nav3").className = "liNavActive";
    if (rootPath[1] == "crest-coupons")
        document.getElementById("nav4").className = "liNavActive";

});

/* Chat Room functions through TellNGo and RightNow Technologies */

// The following function saves the registration info into a cookie

function updateInfo() {
    var today = new Date();
    var expire = new Date();
    var nDays = 365;
    if (nDays == null || nDays == 0) nDays = 1;
    expire.setTime(today.getTime() + 3600000 * 24 * nDays);
    document.cookie = "p_firstname=" + escape(document.forms["CWSchat1"].p_firstname.value)
                 + ";expires=" + expire.toGMTString();
    document.cookie = "p_email=" + escape(document.forms["CWSchat1"].p_email.value)
                 + ";expires=" + expire.toGMTString();
}

// The following function is a generic function for getting a cookie value by name
// one value at a time and is used in the setFields() function.
function getCookie(name) {
    var dc = document.cookie;
    var cname = name + "=";
    var clen = dc.length;
    var cbegin = 0;

    while (cbegin < clen) {
        var vbegin = cbegin + cname.length;

        if (dc.substring(cbegin, vbegin) == cname) {
            var vend = dc.indexOf(";", vbegin);
            if (vend == -1) vend = clen;

            return unescape(dc.substring(vbegin, vend));
        }

        cbegin = dc.indexOf(" ", cbegin) + 1;

        if (cbegin == 0) break;
    }
    return null;
}


function delete_cookie(cookie_name) {
    var cookie_date = new Date();  // current date & time
    cookie_date.setTime(cookie_date.getTime() - 1);
    document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}


// The following function is called from the page load event.
function setFields() {

    var p_firstname = getCookie('p_firstname');
    var p_lastname = getCookie('p_lastname');
    var p_email = getCookie('p_email');

    // The following logic hides the appropriate section
    if (p_firstname != null && p_email != null) {
        document.getElementById("newusers").style.display = "none";
    } else {
        document.getElementById("registered").style.display = "none";
    }

    // The following logic prevents Null from being displayed in the fields
    if (p_firstname != null) {
        document.forms["CWSchat1"].p_firstname.value = p_firstname;
    }
    if (p_lastname != null) {
        document.forms["CWSchat1"].p_lastname.value = p_lastname;
    }
    if (p_email != null) {
        document.forms["CWSchat1"].p_email.value = p_email;
    }
}

//show and hide divs
function ShowHideDIV(divID, showHide) { document.getElementById(divID).style.display = showHide; }

//COPPA check
function checkForm(f) {
    var is_valid = true;
    if (is_valid && document.forms['CWSchat1'].state) {

        // check birthdate
        var df = document.forms['CWSchat1'];
        var curdate = new Date();
        var state = df.state.value;

        var under13 = new Date(curdate.getFullYear() - 13, curdate.getMonth() + 1, curdate.getDate());
        var under18 = new Date(curdate.getFullYear() - 18, curdate.getMonth() + 1, curdate.getDate());
        var dob_d = df.dobdd.value;
        var dob_m = df.dobmo.value;
        var dob_y = df.dobyr.value;
        var dob = new Date(dob_y, dob_m, dob_d);
        dob = dob.valueOf();

        if (state == "ME" && dob >= under18) {
            parent.location.href = "/duringhours.aspx?errorCode=sorry";
            return false;
        }

        if (dob >= under13) {
            parent.location.href = "/duringhours.aspx?errorCode=sorry";
            return false;
        }

    }

    return is_valid;
}

function newWindow(mypage,myname,w,h) {
	if(screen.width){
		var winl = (screen.width-w)/2;
		var wint = (screen.height-h)/2;
	}else{
		winl = 0;wint =0;
	}
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;
	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',';
	settings += 'toolbar=no,scrollbars=no,noresize,resizable=no'; //features;
	win = window.open(mypage,myname,settings);
	win.window.focus();
}