function isBlank(obj, message){
	if (obj.value == ''){
		alert(message);
		obj.focus();
		return false;
	}
	return true;
}

function isEmail(obj, message){
	if(!( /[^@]+@[^@]+/.test(obj.value))){
		alert(message);
		obj.focus();
		return false;
	}
	return true;
		
}

function isStdChar(obj, message){
	if( /[^a-zA-Z]/.test(obj.value) ){
		alert(message);
		obj.focus();
		return false;
	}
	return true;		
}

function isSame (obj1,obj2,message) {	
	if (obj1.value == obj2.value) {
		alert(message);
		obj2.focus();
		return false;
	}
	return true;
}

function validate(objForm){	
	if ( (!isBlank(objForm.order1, 'Number of copies is required.')) ||
			 (!isBlank(objForm.firstname, 'First name is required.')) || (!isBlank(objForm.lastname, 'Last name is required.')) ||
			 (!isStdChar(objForm.firstname, 'Invalid character(s) entered.')) || (!isStdChar(objForm.lastname, 'Invalid character(s) entered.')) ||
			 (!isSame(objForm.firstname, objForm.lastname, "First name and last name shouldn't be same.")) ||
			 (!isBlank(objForm.organization, 'Organization is required.')) || (!isBlank(objForm.address1, 'Address is required.')) ||
			 (!isBlank(objForm.city, 'City is required.')) || (!isBlank(objForm.state, 'State is required.')) ||
			 (!isBlank(objForm.zipcode, 'Zip code is required.')) || (!isBlank(objForm.phone, 'Phone number is required.')) ||
			 (!isEmail(objForm.email, 'A valid email is required.')) || (!isEmail(objForm.confirm, 'A valid email is required.'))
	
	){
		return false;
	}			

	if( objForm.email.value != objForm.confirm.value){
		alert("Email address doesn't match confirmation email.");
		return false;
	}

  
	return true;
}  

//***************************************************//
//         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=.hhs.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 description()
{
	
  var winW = 500, winH = 500;

	if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
	  winW = window.innerWidth;
	  winH = window.innerHeight;
	  //winH = document.body.clientHeight;
	  
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
	  winW = document.body.offsetWidth;
	  winH = document.body.offsetHeight;
	  //winH = document.body.clientHeight;	  
	  
	 }
	}
	
	var pWinH = 400, pWinW = 400, url;	
	
	if(description.arguments.length == 1){
		url = description.arguments[0];
	}
	else if (description.arguments.length == 4){
		url = description.arguments[0];
		pWinW =description.arguments[1];
		pWinH = description.arguments[2]+60;
		displaytitle = description.arguments[3]
	}
  var disp_setting="dependent=yes,toolbar=no,location=no,directories=no,status=no,statusbar=no,menubar=no,scrollbars=no,resizable=yes";
  	disp_setting += ",height=" + pWinH;
  	disp_setting += ",width=" + pWinW;
  	disp_setting += ",left=" + ((winW - pWinW) / 2);
  	disp_setting += ",top=" + ((winH - pWinH) / 2);  	
  	
  	
  var desc=window.open('about:blank',"winp",disp_setting); 
  var htmlHead="<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'><html lang='en'><head><title>"+displaytitle+"</title><META http-equiv='Content-Type' content='text/html; charset=utf-8'>"
	htmlHead = htmlHead + "<meta http-equiv='Keywords' content='hhs, health, human, services, health and human services, Leavitt, secretary, Mike Leavitt, surgeon general, hipaa, hippa, civil rights, bioterror, terrorism, smallpox, anthrax, sars, chemical, biological, social, social services, disease, families, children, substances, abuse, aging, diabetes, aids, food, drug, drugs, administration, safety, wellness, disaster, emergency, grants, funding, policy, policies, regulate, regulation, regulations, care, healthcare, privacy, medical, doctor, medicine, test, treatment, welfare, mental'>"
	htmlHead =htmlHead +"<meta http-equiv='Description' content='Your source for planning, communicating, and coordinating efforts to prepare and respond to pandemic influenza'></head><body style='margin: 0px 5px 0px 5px;'>" 		
  	var body="<table border=0 cellpadding=0 cellspacing=0 summary='This table is used to format page content' width='100%' height='100%'><tr><td valign='top'><center>"
  	body = body + "<img src='" + url + "'  alt='Analysis of avian influenza sampling.  [Credit FWS]'></center><p>" +displaytitle+"</p>"
  	body = body + "</td></tr><tr><td valign='bottom'><p align='right' style='padding-right:5%;padding-bottom:10px;'><INPUT type='button' value='Close' OnClick='window.close()'> </p></td></tr></table>"
  	var htmlfoot ="</body></html>"
  
  desc.document.write(htmlHead)
  desc.document.write(body)
  desc.document.write(htmlfoot)
   
   desc.focus();
}

function windowHeight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
  return myHeight;
}
