var activeNum = 0;
var numberOfDiv = 0;
var restoreNameDiv = '';

function getHTTPObject() { 			
		if (typeof XMLHttpRequest != 'undefined') {				
			return new XMLHttpRequest(); 
		} 
		try { 		
			return new ActiveXObject("Msxml2.XMLHTTP"); 
		} catch (e) { 
			try { 			
				return new ActiveXObject("Microsoft.XMLHTTP"); 
			} catch (e) {} 
		} 
		return false; 
}

function showContent(activeDiv,divId,divName){
	switch (divName) {
		case 'feverfew':
			numberOfDiv = 7;
			break
		case 'soy':
			numberOfDiv = 9;
			break
		case 'oats':
			numberOfDiv = 9;
			break
		case 'shiitake':
			numberOfDiv = 7;
			break
		case 'lavender':
			numberOfDiv = 5;
			break
		case 'wheat-complex':
			numberOfDiv = 4;
			break

	}
	for (var i = 0; i<numberOfDiv; i++){
		if (document.getElementById(''+divName+'_content_'+i+'') != null) {
			document.getElementById(''+divName+'_content_'+i+'').style.display = 'none';
		}
	}
	activeNum = activeDiv;
	restoreNameDiv = divName;
	document.getElementById(''+divName+'_content_'+divId+'').style.display = 'block';
}
function restoreDiv(){
	for (var i = 0; i<numberOfDiv; i++){
		if (document.getElementById(''+restoreNameDiv+'_content_'+i+'') != null) {
			document.getElementById(''+restoreNameDiv+'_content_'+i+'').style.display = 'none';
		}
	}
	document.getElementById(''+restoreNameDiv+'_content_'+activeNum+'').style.display = 'block';
}

//==============================================================================

function setStyle(){
	
	var args = setStyle.arguments;

	for (var i = 0; i<=3; i++){
			var elem = document.getElementById('link_tab_'+i+'');
			if (elem != null){
				elem.className = '';
				}
		}
	document.getElementById('link_tab_'+args[0]+'').className = 'active';
}

//==============================================================================

function openPopup (width, height, url, name) {

	var windowWidth = window.screen.width;
	var windowHeight = window.screen.height;
	
	var popupWidth = width;
	var popupHeight = height;
	
	var popupTop = (windowHeight - popupHeight) / 2;
	var popupLeft = (windowWidth - popupWidth) / 2;
	
	var features = "width=" +  popupWidth + ",height=" + popupHeight + ",top=" + popupTop + ",left=" + popupLeft;
	
	
	window.open(url, name, features);			
}

function openContactUsPop(width, height, url, name) {

	var windowWidth = window.screen.width;
	var windowHeight = window.screen.height;
	
	var popupWidth = width+30;
	var popupHeight = height+60;
	
	var popupTop = (windowHeight - popupHeight) / 2;
	var popupLeft = (windowWidth - popupWidth) / 2;
	
	var features = "width=" +  popupWidth + ",height=" + popupHeight + ",top=" + popupTop + ",left=" + popupLeft;
	
	Citbox.show(url,name,'width='+popupWidth+', height='+popupHeight);	
}

//==============================================================================

function toggleProdMenu (divName) {
	
	if(document.getElementById(divName).style.display == 'block'){
		if(navigator.userAgent.indexOf('MSIE') != -1){
			if(document.getElementById("flash")){
				document.getElementById('flash_content').style.zIndex  = 1;
			}
		}
			document.getElementById(divName).style.display = 'none';
		} 
		else {
		if(navigator.userAgent.indexOf('MSIE') != -1){
			if(document.getElementById("flash")){
				document.getElementById('flash_content').style.zIndex  = -1;
			}
		}
			document.getElementById(divName).style.display = 'block';
			}
}

//==============================================================================

function openPic(id, w, h){
	var winleft = (screen.width - w) / 2;
	var winUp = (screen.height - h) / 2;
	window.open(id,'foto','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+w+',height='+h+',left='+winleft+',top='+winUp+'')
}

//==============================================================================

function showDisclaimer (disclaimer, linkId) {
	topPosition = (document.all)?document.documentElement.scrollTop:window.pageYOffset; 
	document.getElementById(disclaimer).style.display = 'block';
	document.getElementById(disclaimer).style.top = topPosition + 350 + "px";

	document.getElementById("link").href = linkId;
}

function closeDisclaimer(disclaimer){
	document.getElementById(disclaimer).style.display = 'none';
}

//===============================================================

function showDisclaimerHairWithLife (disclaimer, linkId) {
	topPosition = (document.all)?document.documentElement.scrollTop:window.pageYOffset; 
	document.getElementById(disclaimer).style.display = 'block';
	document.getElementById(disclaimer).style.top = topPosition + 350 + "px";

	document.getElementById("linkHairWithLife").href = linkId;
}

//==============================================================================


function showDisclaimer2 (disclaimer2, linkId2) {
	topPosition = (document.all)?document.documentElement.scrollTop:window.pageYOffset; 
	document.getElementById(disclaimer2).style.display = 'block';
	document.getElementById(disclaimer2).style.top = topPosition + 350 + "px";

	document.getElementById("link2").href = linkId2;
}
function closeDisclaimer2(disclaimer2){
	document.getElementById(disclaimer2).style.display = 'none';
}

//==============================================================================

function showDisclaimer3(disclaimer3, linkId3) {
	topPosition = (document.all)?document.documentElement.scrollTop:window.pageYOffset; 
	document.getElementById(disclaimer3).style.display = 'block';
	document.getElementById(disclaimer3).style.top = topPosition + 350 + "px";

	document.getElementById("link3").href = linkId3;
}
function closeDisclaimer3(disclaimer3){
	document.getElementById(disclaimer3).style.display = 'none';
}

function showDisclaimer4(disclaimer4, linkId4) {
	topPosition = (document.all)?document.documentElement.scrollTop:window.pageYOffset;
	document.getElementById(disclaimer4).style.display = 'block';
	document.getElementById(disclaimer4).style.top = topPosition + 350 + "px";

	document.getElementById("link4").href = linkId4;
}
function closeDisclaimer4(disclaimer4){
	document.getElementById(disclaimer4).style.display = 'none';
}
//===============================================================================
// Click Overlay Teraacycle

function toggle(obj) {
		var el = document.getElementById(obj);
		if ( el.style.display != "block" ) {
			el.style.display = 'block';
             }
		else {
			el.style.display = '';
           }
}
//===============================================================================
//refresh the form pages to load the fileds information
function refreshFormPages() {
	var url = window.location.href;
	var arrayPages = [];
	arrayPages[0] = "product_coupon.jsp";
	arrayPages[1] = "free-sample-stress.jsp";
	arrayPages[2] = "ageless-coupon.jsp";
	arrayPages[3] = "register-official.jsp";
	arrayPages[4] = "baby-coupon.jsp";
	arrayPages[5] = "babyoffer";
	arrayPages[6] = "jubilance";
	arrayPages[7] = "baby-coupon2.jsp";
	arrayPages[8] = "save";
	arrayPages[9] = "save.jsp";
	for (i = 0; i < arrayPages.length; i++) {
		if (url.indexOf(arrayPages[i]) > -1) {
			var varNoCache = new Date().getTime();
			var varSpecialChar = "?";
			if ((url.indexOf("?") > -1) || (url.indexOf(";") > -1)) {
				varSpecialChar = "&";
			}
			//if page is register-official.jsp, it forces the redirect to index.jsp
			//because the user loged in
			if (i != 3) {
				window.location.href = url.replace('#','') + varSpecialChar + "rld=" + varNoCache;
			} else {
				window.location.href = "index.jsp";
			}
		}
	}
}
