browserName = navigator.appName;          
browserVer = parseInt(navigator.appVersion);

hasImageSupport  = false;
hasInvalidFields = false;

var icon_print_on = new Image();
icon_print_on.src = relativePath + "images/icon_print_on.gif";

var icon_abc_on = new Image();
icon_abc_on.src = relativePath + "images/icon_abc_on.gif";

var icon_print_off = new Image();
icon_print_off.src = relativePath + "images/icon_print_off.gif";

var icon_abc_off = new Image();
icon_abc_off.src = relativePath + "images/icon_abc_off.gif";

var SAT_CODE = "";

buttonLoc = relativePath + "images/"+lang+"/btn_";
buttonName = new Array ('resources','skin_care','treating_your','understanding','tellafriend','selfassementtool');


for (var cnt=0; cnt < buttonName.length; cnt++) {
	eval ('var '+buttonName[cnt]+'_on = new Image();');
	eval (buttonName[cnt] + '_on.src = "'+buttonLoc + buttonName[cnt] + '_on.gif"');
	eval ('var '+buttonName[cnt]+'_off = new Image();');
	eval (buttonName[cnt] + '_off.src = "'+buttonLoc + buttonName[cnt] + '_off.gif"');
}	

if (browserName == "Netscape" && browserVer >= 3)
   hasImageSupport = true;
else if (browserVer > 3)
   hasImageSupport = true;
   
function buttonAction (imgName, isItOn) {   
  if (hasImageSupport) {
      if (isItOn) {
       	document[imgName].src = eval(imgName + "_on.src");
      } else {
         document[imgName].src = eval (imgName + "_off.src");
      }
   }
}

function nextSatMod ()
{
	var tmp = sat_active.split("_");
	
	if (tmp[1] < 4)
		setSatActive ("sat_"+(tmp[1]-0+1))
	else
	{
		//pageTracker._trackPageview(SAT_CODE+"Results");
		document.myform.submit();
	}
}

function nextSat ()
{
	var tmp = sat_active.split("_");
	
	if (tmp[1] < 4)
		setSatActive ("sat_"+(tmp[1]-0+1))
	else
	{
		pageTracker._trackPageview("/Self-Assessment/"+lang+"/Results");
		document.myform.submit();
	}
}

var letter = new Array ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");

function HideAllGlossary ()
{
	for (var i=0; i < letter.length; i++)
	{
		if (document.getElementById('link_'+letter[i]))	
			document.getElementById('link_'+letter[i]).className = "blue_link";
			
		if (document.getElementById('all_'+letter[i]))
			document.getElementById('all_'+letter[i]).className = "invisible";
	}
	
	document.getElementById("link_seeall").className = "blue_link"

}
function ShowGlossary (whichLetter)
{
	HideAllGlossary ();
	
	document.getElementById('link_'+whichLetter).className = "red_link";
	if (document.getElementById('all_'+whichLetter))
		document.getElementById('all_'+whichLetter).className = "visible";
	
}

function allShowGlossary ()
{

	for (var i=0; i < letter.length; i++)
	{
		if (document.getElementById('link_'+letter[i]))	
			document.getElementById('link_'+letter[i]).className = "blue_link";
			
		if (document.getElementById('all_'+letter[i]))
			document.getElementById('all_'+letter[i]).className = "visible";
	}
	
	document.getElementById("link_seeall").className = "red_link"
}

function setSatActiveMod (id)
{
	pageTracker._trackPageview(SAT_CODE+id.replace("sat_","step"));
	// turn off the previous tab
	document.getElementById(sat_active+'_header').className= "invisible";
	document.getElementById(sat_active+'_question').className= "invisible";	
	document[sat_active].src = eval (sat_active + "_off.src");
	
	// turn on the new tab
	document.getElementById(id+'_header').className= "visible";
	document.getElementById(id+'_question').className= "visible";	

	document[id].src = eval(id+"_active.src");	
	if (id == "sat_4")
	{
		document["sat_part01"].src = sat_part01_on.src	
		document["continue"].src = btn_getresult.src	
	}
	else
	{
		document["sat_part01"].src = sat_part01_off.src		 	
		document["continue"].src = btn_continue.src			
	}

	sat_active = id;
}

function setSatActive (id)
{
	pageTracker._trackPageview("/Self-Assessment/"+lang+"/"+id.replace("sat_","step"));
	// turn off the previous tab
	document.getElementById(sat_active+'_header').className= "invisible";
	document.getElementById(sat_active+'_question').className= "invisible";	
	document[sat_active].src = eval (sat_active + "_off.src");
	
	// turn on the new tab
	document.getElementById(id+'_header').className= "visible";
	document.getElementById(id+'_question').className= "visible";	

	document[id].src = eval(id+"_active.src");	
	if (id == "sat_4")
	{
		document["sat_part01"].src = sat_part01_on.src	
		document["continue"].src = btn_getresult.src	
	}
	else
	{
		document["sat_part01"].src = sat_part01_off.src		 	
		document["continue"].src = btn_continue.src			
	}

	sat_active = id;
}

function satButtonAction (imgName, isItOn) {   
	if (imgName != sat_active)
	{
		if (hasImageSupport) {
			if (isItOn) {
				document[imgName].src = eval(imgName + "_on.src");
				if (imgName == "sat_4")
					document["sat_part01"].src = sat_part01_on.src
				else if (sat_active != "sat_4")
					document["sat_part01"].src = sat_part01_off.src		 
			} else {
				document[imgName].src = eval (imgName + "_off.src");
				if (sat_active != "sat_4")
					document["sat_part01"].src = sat_part01_off.src		 
			}
		}
	}
}

function buttonArrowAction (target, isItOn)
{
  if (hasImageSupport) {
      if (isItOn) {
         document[target].src = arrow_on.src;
      } else {
         document[target].src = arrow_off.src;
      }
   }
}

function goPopup(url,width,height,scroll,menu)
{
	if (menu == "yes")
		window.open(url, 'newWin', 'width='+width+',height='+height+',scrollbars='+scroll+',menubar=yes,toolbar=yes');	
	else
		window.open(url, 'newWin', 'width='+width+',height='+height+',scrollbars='+scroll);
}

function viewImage (filename, width, height,scroll,title)
{
	var tmp = filename.split ("/");
	var str = 'toolbar=0,scrollbars='+scroll+',location=0,statusbar=0,menubar=1,resizable=1,width='+width+',height='+height

	var html ='<html>\n<head>\n<title>'+title+'</title></head>\n';
	html += '<body bgcolor="white" leftmargin=0 rightmargin=0 topmargin=0 bottommargin=0 marginwidth=0 marginheight=0>\n';
	html += '<a href="javascript:window.close();"><img src="'+filename+'" border=0 alt="Click to Close Window"></a></td></tr></table>';
	html += '\n</body>\n</html>';

	var win = window.open("","_blank", str);
	win.document.open("text/html", "replace");	
	win.document.write(html);
	win.document.close();
	win.window.focus();	
}

function validForm(formName, msg)
{
	var myForm   = eval ("document."+formName);
	var reqField = (myForm["req"].value).split(",");
	var valid    = true;	
	for (i=0; i < reqField.length; i++)
	{
		var tmp = reqField[i].split("|");
		
		if (tmp[0] == "text" && myForm[tmp[1]].value == "")
			valid = false;
		else if (tmp[0] == "email" && ((myForm[tmp[1]].value).indexOf("@") == -1 || (myForm[tmp[1]].value).indexOf(".") == -1))
			valid = false;
		else if (tmp[0] == "select" && myForm[tmp[1]].options[ myForm[tmp[1]].selectedIndex].value == "")
			valid = false;
		else if (tmp[0] == "option")
		{
			if (tmp[1] == "email" && myForm[tmp[2]].value != "")
			{
				if ((myForm[tmp[2]].value).indexOf("@") == -1 || (myForm[tmp[2]].value).indexOf(".") == -1)
				{
					msg  += " Please enter a valid email address.";
					valid = false;
				}
			}
		} 
	}
	if (!valid)
		alert (msg);
	return valid;
}

function ConfirmDeletion (formName,fieldname)
{
	var myForm = eval ('document.'+formName);

	var IDs    = myForm[fieldname];

	var id     = "";
	var portfolio_name = "";
	
	if ("undefined" != typeof(IDs))
	{
		if (IDs.length)
		{
			for(i=0;i<IDs.length;i++)
			{
				if (IDs[i].checked)
					id = IDs[i].value;
			}
		}
		else if (IDs.checked)
			id = IDs.value;
	}

	if (id)
	{
		var status               = confirm (myForm["error_msg"].value)
		if (status)
		{
			myForm["cmd"].value = "Delete";
			myForm.submit();		
		}
	}	
}

function ConfirmArchive (formName,fieldname)
{
	var myForm = eval ('document.'+formName);

	var IDs    = myForm[fieldname];

	var id     = "";
	var portfolio_name = "";
	
	if ("undefined" != typeof(IDs))
	{
		if (IDs.length)
		{
			for(i=0;i<IDs.length;i++)
			{
				if (IDs[i].checked)
					id = IDs[i].value;
			}
		}
		else if (IDs.checked)
			id = IDs.value;
	}

	if (id)
	{
		var status               = confirm (myForm["error_msg_archive"].value)
		if (status)
		{
			myForm["cmd"].value = "Archive";
			myForm.submit();		
		}
	}	
}

function ConfirmRestore (formName,fieldname)
{
	var myForm = eval ('document.'+formName);

	var IDs    = myForm[fieldname];

	var id     = "";
	var portfolio_name = "";
	
	if ("undefined" != typeof(IDs))
	{
		if (IDs.length)
		{
			for(i=0;i<IDs.length;i++)
			{
				if (IDs[i].checked)
					id = IDs[i].value;
			}
		}
		else if (IDs.checked)
			id = IDs.value;
	}

	if (id)
	{
		var status               = confirm (myForm["error_msg_restore"].value)
		if (status)
		{
			myForm["cmd"].value = "Restore";
			myForm.submit();		
		}
	}	
}

function FIND(item) {
  if( window.mmIsOpera ) return(document.getElementById(item));
  if (document.all) return(document.all[item]);
  if (document.getElementById) return(document.getElementById(item));
  return(false);
}

function moveXbySlicePos (x, imgname) { 
  var img = FIND(imgname) || document.images[imgname] || document.links[imgname] || document.anchors[imgname];

  if (!document.layers) {
    var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
    var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
    var par = img;
    var lastOffset = 0;
    while(par){
      if( par.leftMargin && ! onWindows ) x += parseInt(par.leftMargin);
      if( (par.offsetLeft != lastOffset) && par.offsetLeft ) x += parseInt(par.offsetLeft);
      if( par.offsetLeft != 0 ) lastOffset = par.offsetLeft;
      par = macIE45 ? par.parentElement : par.offsetParent;
    }
  } else if (img.x) {
     x += img.x;
  }
  return x;
}

function getExplorerVersion()
{
	var ieVers = parseFloat(navigator.appVersion);
	if( navigator.appName != 'Microsoft Internet Explorer' ) return ieVers;

	var tempVers = navigator.appVersion;

	var i = tempVers.indexOf( 'MSIE ' );
	if( i >= 0 ) 
	{
		tempVers = tempVers.substring( i+5 );
		ieVers = parseFloat( tempVers ); 
	}
	return ieVers;
}


function moveYbySlicePos (y, imgname)
{
	var img = FIND(imgname) || document.images[imgname] || document.links[imgname] || document.anchors[imgname];
	if(!document.layers) 
	{
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
		var par = img;
		var lastOffset = 0;
		while(par)
		{
			if( par.topMargin && !onWindows ) y += parseInt(par.topMargin);
			if( (par.offsetTop != lastOffset) && par.offsetTop ) y += parseInt(par.offsetTop);
			if( par.offsetTop != 0 ) lastOffset = par.offsetTop;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}    
	} 
	else if (img.y >= 0) 
		y += img.y;
		
	return y;
}


function ShowIconDropDown ()
{
	var y = moveYbySlicePos (16, "drop_down")
	var x = moveXbySlicePos (0, "drop_down")

	document.getElementById('icon_holder').style.top = y +"px"
	document.getElementById('icon_holder').style.left = x +"px"	
	
	if (document.getElementById('icon_holder').style.display == "none")
		document.getElementById('icon_holder').style.display  = "block";		
	else
		document.getElementById('icon_holder').style.display  = "none";		
}

function SelectIcon (icon_id)
{
	if (icon_id-0)
	{
		if (document.spotlight_form['SECTION'].value && document.getElementById('icon_'+document.spotlight_form['SECTION'].value))
			document.getElementById('icon_'+document.spotlight_form['SECTION'].value).style.display  = "none";		
			
		document.spotlight_form['SECTION'].value = icon_id;
			document.getElementById('icon_'+icon_id).style.display  = "block";		
		document.getElementById('icon_holder').style.display  = "none";		
	}
}

function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}