var openTab = 0;
var tabImages;
var tabBodies;



//***************************************************//
//         Text sizing version .9                    //
//***************************************************//

var sizesArray = new Array("96%", "97%", "98%", "99%", "100%", "101%", "102%", "103%", "104%")
var sizePointer;
var ruleCounter;
// ruleCounter is used for Mozilla due to the necessity to write the new CSS rule in the last position so that it is applied.


if (getCookie("sizePref") != "") {
	sizePointer = Number(getCookie("sizePref"))
	// now apply the font
	if (document.styleSheets[0].cssRules) {
		ruleCounter = document.styleSheets[0].cssRules.length
	// Mozilla
	document.styleSheets[0].insertRule("* {font-size: " + sizesArray[sizePointer] + ";}", ruleCounter)
		//ruleCounter = ruleCounter + 1
	}
	else {
	//IE
	document.styleSheets[0].addRule("*", "{font-size: " + sizesArray[sizePointer] + ";}")
	}
}
else {
	sizePointer = 4;
}
var ie=false;
if (navigator.appName.indexOf("Microsoft") != -1){
	ie=true;
}
	


function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return "";
}

function largerFont () {
	
	if (document.styleSheets[0].cssRules) {
	// Mozilla
		if (document.styleSheets[0].cssRules[0]) {
			if (sizePointer != 8) {
				ruleCounter = document.styleSheets[0].cssRules.length;
				sizePointer = sizePointer + 1;
				document.styleSheets[0].insertRule("* {font-size: " + sizesArray[sizePointer] + ";}", ruleCounter)
				//document.write('<style>* {font-size: ' + sizesArray[sizePointer] + ';}</style>');
				document.cookie = 'sizePref='+ sizePointer + '; path=/; domain=.4parents.gov';
			}
		}	
	}
	
	else if (document.styleSheets[0].rules) {
	// IE
		if (sizePointer < 8) {
			sizePointer = sizePointer + 1;
			document.cookie = 'sizePref='+ sizePointer + '; path=/; domain=.hhs.gov';
			document.styleSheets[0].addRule("*", "{font-size: " + sizesArray[sizePointer] + ";}")
			}
		}		
	}

function smallerFont () {	
	if (document.styleSheets[0].cssRules) {
		
	// Mozilla
		if (document.styleSheets[0].cssRules[0]) {	
			if (sizePointer != 0) {
				sizePointer = sizePointer - 1;
				ruleCounter = document.styleSheets[0].cssRules.length;
				document.styleSheets[0].insertRule("* {font-size: " + sizesArray[sizePointer] + ";}", ruleCounter)
				document.cookie = 'sizePref='+ sizePointer + '; path=/; domain=.hhs.gov';
			}
		}	
	}
	
	else if (document.styleSheets[0].rules) {
	// IE		
		if (sizePointer > 0) {
			sizePointer = sizePointer - 1;
			document.cookie = 'sizePref='+ sizePointer + '; path=/; domain=.hhs.gov';
			document.styleSheets[0].addRule("*", "{font-size: " + sizesArray[sizePointer] + ";}")
		}
	}
	
}


function sendReferral(lnk, imgpath){
	
document.write('<form name="sendweblink" action="http://transparency.cit.nih.gov/sendweblink.cfm" method="post">');
document.write('<input type="hidden" name="title" value="' + document.title + '" />');
document.write('<input type="hidden" name="lnkurl" value="' + location.href + '" />');
document.write('<p class="mailfriend"><a href="javascript:sendweblink.submit();" onclick="javascript:sendweblink.submit();">' + lnk + '</a> <a href="javascript:sendweblink.submit();" onclick="javascript:sendweblink.submit();"><img alt="Email to a friend" src="' + imgpath + '/email.gif" /></a></p>');
document.write('</form>');

}

function sendReferralSp(lnk, imgpath){
	
document.write('<form name="sendweblink" action="http://transparency.cit.nih.gov/sendweblinksp.cfm" method="post">');
document.write('<input type="hidden" name="title" value="' + document.title + '" />');
document.write('<input type="hidden" name="lnkurl" value="' + location.href + '" />');
document.write('<p class="mailfriend"><a href="javascript:sendweblink.submit();" onclick="javascript:sendweblink.submit();">' + lnk + '</a> <a href="javascript:sendweblink.submit();" onclick="javascript:sendweblink.submit();"><img alt="Correo Electrónico a un Amigo" src="' + imgpath + '/email.gif" /></a></p>');
document.write('</form>');

}


// following function is used for Send Link to a Friend
function ValidateData()
{
	
	// Data Validation for e-mail address
	if (document.emailform.toemail.value == "")
	{
		alert("Please make sure that you have entered recipient's e-mail address.");
		return false;
	}
	else
	{
		if (document.emailform.toemail.value == " ")
		{
			alert("Recipient's e-mail address cannot contain any white spaces.");	
			return false;
		} 
	
		var strng = document.emailform.toemail.value;
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(strng))) 
		{ 
   			alert("Please enter a valid e-mail address for the recipient.\n");
				return false;
		}
	
		var illegalChars= /[\(\)\<\>\;\:\\\/\"\[\]]/
		if (strng.match(illegalChars)) 
		{
			alert("The recipient's email address contains illegal characters.\n");
			return false;
		
		}
	}

	// Data Validation for from e-mail address
	if (document.emailform.fromemail.value == "")
	{
		alert("Please make sure that you have entered your e-mail address.");
		return false;
	}
	else
	{
		if (document.emailform.toemail.value == " ")
		{
			alert("Your e-mail address cannot contain any white spaces.");	
			return false;
		} 
	
		var strng = document.emailform.fromemail.value;
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(strng))) 
		{ 
   			alert("Please make sure that your e-mail address is valid.\n");
				return false;
		}
	
		var illegalChars= /[\(\)\<\>\;\:\\\/\"\[\]]/
		if (strng.match(illegalChars)) 
		{
			alert("Your e-mail address contains illegal characters.\n");
			return false;
		}
	}
	return true;
}

function Disclaimer(){

         alert("You are about to leave the 4Parents.gov website. 4Parents.gov provides links to other Internet sites as a service to its users, and is not responsible for the availability or content of these external sites. 4Parents.gov, its employees, and contractors do not endorse, warrant, or guarantee the products, services, or information described or offered at these other Internet sites. Any reference to a commercial product, process, or service is not an endorsement or recommendation by the 4Parents.gov, its employees, or contractors. For documents available from this server, the U.S. Government does not warrant or assume any legal liability or responsibility for the accuracy, completeness, or usefulness of any information, apparatus, product, or process disclosed.")

    }

function tabClick (){

	// /open/.test(obj.src);	
	var tabID = findTabId(this);
	
	if(openTab != tabID){
		toggleTab(tabImages[openTab]);
		toggleTab(tabImages[tabID]);
		
		toggleTabBody(tabBodies[openTab]);
		toggleTabBody(tabBodies[tabID]);
		
		
		openTab = tabID;
	}
}

function initial(){
	initialTabs ();	
}

function initialTabs(){
	var tabBlock = document.getElementById("tab_block");
	
	if(tabBlock){
		var tabs = tabBlock.getElementsByTagName('div');		
		tabImages = tabs[0].getElementsByTagName('img');
		
		
		for(var i=0; i < tabImages.length; i++){			
			tabImages[i].onclick = tabClick;
			if(i == openTab){
				toggleTab(tabImages[i]);
			}						
		}		
		
		tabBodies = getElementsByClassName(tabBlock,"body");		
		for(var i=0; i < tabBodies.length; i++){
			if(i != openTab){
				tabBodies[i].style.display = "none";
			}
		}
		
		lnks = tabBlock.getElementsByTagName('a');		
		
		for(var i=0; lnks && i < lnks.length; i++){		
			lnks[i].disabled = "true";
		}
		
	}	
}

function findTabId(obj){
	var i=0;
	
	for(i=0; i < tabImages.length && tabImages[i] != obj; i++){										
	}		
	
	return i;
}


function toggleTab(obj){
	
	if(/open/.test(obj.src)){
		obj.src = obj.src.replace("open", "closed");
	}
	else{
		
		obj.src = obj.src.replace("closed","open");
	}
}

function toggleTabBody(obj){	
	if(obj.style.display == "none"){
		obj.style.display = "";
	}
	else{
		obj.style.display = "none";
	}	
}


function getElementsByClassName(obj, cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = obj.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
}; 


