 /**
 * Form Validation    
 */
function validateForm()
{
    var rv=true;
    if(typeof valCtrls == "undefined"){valCtrls = "";}
	if(typeof confirmCtrls  == "undefined"){confirmCtrls = "";}
	if(typeof urlAgeError == "undefined"){urlAgeError = "";}
	if(typeof dateCtrl  == "undefined"){dateCtrl = "";}
	if(typeof birthdateCtrl  == "undefined"){birthdateCtrl = "";}
	if(typeof birthdateCtrl18  == "undefined"){birthdateCtrl18 = "";}
	if(typeof emailCtrl  == "undefined"){emailCtrl = "";}
	if(typeof monthyearCtrl  == "undefined"){monthyearCtrl = "";}
	if(typeof ageCtrl  == "undefined"){ageCtrl = "";}
	if(typeof ageCtrl18  == "undefined"){ageCtrl18 = "";}
	if(typeof radioCtrl == "undefined"){radioCtrl = "";}
	if(typeof zipCtrl  == "undefined"){zipCtrl = "";}
	if(typeof phoneCtrl  == "undefined"){phoneCtrl = "";}
	if(typeof pageErrorCtrl == "undefined"){pageErrorCtrl = "";}
	if(typeof stateCtrl == "undefined"){stateCtrl = "";}
        if(typeof textareaCtrl == "undefined"){textareaCtrl = "";}
    try
    { 
		// reset error messages
		var resetArr = new Array(valCtrls, confirmCtrls, dateCtrl, birthdateCtrl, emailCtrl, monthyearCtrl, ageCtrl,  radioCtrl, zipCtrl, phoneCtrl, pageErrorCtrl, stateCtrl, textareaCtrl);	
		for(var i=0; i<resetArr.length; i++)
		{
			var resetCtrl = resetArr[i];
			for(var j=0; j<resetCtrl.length; j++) 
			{
				var id = resetCtrl[j];
				if(!empty(id))
				{
					hideElementById(id+"|ERROR");
				}
			}
		}

		// check if empty
		if (valCtrls != "")
		{
			for(var i=0; i<valCtrls.length; i++) 
			{	
				var id = valCtrls[i];
				if(document.getElementById(id)){
					var element = document.getElementById(id);
				}else{
					var element = "undefined";
				}
				if(empty(element))
				{
					showElementById(id+"|ERROR");
					//elem.focus(); 
					rv=false;
				}
			}
		}

        // check if the values are the same
        if (typeof confirmCtrls != "undefined" || confirmCtrls != "")
        {
	        for(var i=0; i<confirmCtrls.length / 2; i=i+2) 
	        {
	            var id1 = confirmCtrls[i];
	            var confirmElem1 = document.getElementById(id1);
	
	            var id2 = confirmCtrls[i+1];
	            var confirmElem2 = document.getElementById(id2);
	
	            if (confirmElem1.value != confirmElem2.value)
	            { 
					showElementById(id2+"|ERROR");         
		            //confirmElem2.focus();
		            rv=false;
	            }
	        }
        }

	// check if value is a date
	if (dateCtrl != "")
	{
		var ctrl = dateCtrl; 
		for(var i=0; i<ctrl.length;i++)
		{
			var id = ctrl[i];
			var element = document.getElementById(id);
			if(!empty(element))
			{
				var value = document.getElementById(id).value;
			    if (!isDate(value))
			    {
					showElementById(id+"|ERROR");
					rv = false;
			    }
			}	
	    }
	}

	//check birthdate
	if (birthdateCtrl != "" || birthdateCtrl18 != "")
	{
		if(birthdateCtrl != "")
		{
			//Validation variables for 14+
			var birthdateId = birthdateCtrl;
			var validAge = 14;
		}
		else
		{
			//Validation variables for 18+
			var birthdateId = birthdateCtrl18;
			var validAge = 18;
		}

		var birthdateElem = document.getElementById(birthdateId);
	    var birthdateStr = birthdateElem.value;
	    if (birthdateStr.length > 0)
	    {
		    if (!isDate(birthdateStr))
		    { 
				showElementById(birthdateId+"|ERROR");                   
				rv = false;                    
		    }
			else
		    {
				// check if user is of age
				var birthdateArr = new Array();
				birthdateArr = birthdateStr.split('/');
				var birthMonth = birthdateArr[0];
				var birthDay = birthdateArr[1];
				var birthYear = birthdateArr[2];

		       if (getAge(birthMonth, birthDay, birthYear) < validAge)
		       { 
					if(urlAgeError == 'undefined'){alert("No Age Redirect URL defined");}
					if(urlAgeError != 'undefined')
					{
						window.location.href = urlAgeError;                     
					}
					rv = false;
		       }
		    }
	    }
	}

	 //check email
	if (emailCtrl != "")
	{
		var ctrl = emailCtrl;
		for(var i=0; i<ctrl.length;i++)
		{
			var id = ctrl[i];
			var element = document.getElementById(id);
			if(!empty(element))
			{
				var value = document.getElementById(id).value;
			    if (!isEmail(value))
			    {
					showElementById(id+"|ERROR");
					rv = false;
			    }
			}	
	    }
	}

	//check zip code
	if (zipCtrl != "")
	{
		var ctrl = zipCtrl;
		for(var i=0; i<ctrl.length;i++)
		{
			var id = ctrl[i];
			var element = document.getElementById(id);
			if(!empty(element))
			{
			    var value = document.getElementById(id).value;
			    if (!isZip(value))
			    {
				showElementById(id+"|ERROR");
					rv = false;
			    }
			}
	    }
	}

    //check month year
    if (monthyearCtrl != "")
    {
	var ctrl = monthyearCtrl;
		for(var i=0; i<ctrl.length; i++)
		{
			var id = ctrl[i];

			var element = document.getElementById(id);
			if(!empty(element))
			{
				var element = document.getElementById(id);
				var value = element.value;
				var regxp = /^\d?\d\/\d\d\d\d$/;
				if (!regxp.test(value))
				{ 
					showElementById(id+"|ERROR");
					rv = false;
				}

				var time=new Date();
				var currentYear=time.getYear();

				var valArr = new Array();
				valArr = value.split('/'); //Split MM/YYYY
				var monthVal = valArr[0];
				var yearVal = valArr[1];
				if(monthVal < 1 || monthVal > 12 || yearVal < currentYear)
				{
					showElementById(id+"|ERROR");
					rv = false;
				}
			}
		}
	}

	//check Age
	if (ageCtrl != "" || ageCtrl18 != "")
	{
		if (ageCtrl != "")
		{
			//Validation variables for 14+
			var ageList = ageCtrl;
			var regXU = /^(Under 13)$/;
			var validAge = 14;
		}
		else
		{
			//Validation variables for 18+
			var ageList = ageCtrl18;
			var regXU = /^(Under 18)$/;
			var validAge = 18;
		}
		for(var i=0; i<ageList.length;i++)
		{
			var id = ageList[i];
			var element = document.getElementById(id);
			if(!empty(element))
			{
				var ageID = document.getElementById(id);
				var ageStr = ageID.value;  //AnswerID|Value
				var ageArr = new Array();
				ageArr = ageStr.split('|'); //Split string
				var ageAnwerID = ageArr[0];
				var ageVal = ageArr[1];
				var regX = /^\d\d?\d$/;


				// check if user is under 14 years of age
				if (regXU.test(ageVal))
				{ 
					if(urlAgeError == 'undefined'){alert("No Age Redirect URL defined");}
					if(urlAgeError != 'undefined')
					{
						window.location.href = urlAgeError;                     
					}
					rv = false;
				}
				else if (!regX.test(ageVal))
				{

				}
				else if (ageVal < validAge)
				{
					if(urlAgeError == 'undefined'){alert("No Age Redirect URL defined");}
					if(urlAgeError != 'undefined')
					{
						window.location.href = urlAgeError;                     
					}
					rv = false;
				}
			}
		}
	}

	//Check Radio Buttons
	if (radioCtrl != "")
	{
		var ctrl = radioCtrl;
		var test = false;
		for (i = 0; i < ctrl.length; i++)
		{
			//Get Group Name
			var radioGroupName = ctrl[i];
			if (!testRadio(radioGroupName))
			{				
				showElementById(radioGroupName+"|ERROR");
				rv = false;
			}
		}
	}

	//check phone
	if (phoneCtrl != "")
	{
		var ctrl = phoneCtrl;
		for(var i=0; i<ctrl.length;i++)
		{
			var id = ctrl[i];
			var element = document.getElementById(id);
			if(!empty(element))
			{
			    var value = document.getElementById(id).value;
			    if (!isPhone(value))
			    {
				showElementById(id+"|ERROR");
				rv = false;
			    }
			}
	    }
	}







	    //check textarea
	    		if (textareaCtrl != "")
	    		{
	    			var ctrl = textareaCtrl;
	    			for(var i=0; i<ctrl.length;i++)
	    			{
	    				var id = ctrl[i];
	    				var element = document.getElementById(id);
	    				if(!empty(element))
	    				{
	    				    var value = document.getElementById(id).value;
	    				    if (element.value.length > 2000)
	    				    {
	    					showElementById(id+"|ERROR");
	    						rv = false;
	    				    }   				
	    				}
	    		   	 }
			}
 

	/* * * * * * * * *
	 * BEGIN LYRICA SPECIFIC 
	 * Check if address is required for Stepping Forward Signup
	 */
	//Does the checkbox exist?
	if(document.getElementById("Q11900|A14572"))
	{	
		//Checkbox Exists
		//Is the checkbox checked?
		if(isChecked(document.getElementById("Q11900|A14572")))
		{
			//Checkbox Checked
			//Address
			if(empty(document.getElementById("Q10017|A10017")))
			{
				showElementById("Q10017|A10017|ERROR");
				rv = false;
			}
			//City
			if(empty(document.getElementById("Q10019|A10019")))
			{
				showElementById("Q10019|A10019|ERROR");
				rv = false;
			}
			//Zip
			if(empty(document.getElementById("Q10021|A10021")))
			{
				showElementById("Q10021|A10021|ERROR");
				rv = false;
			}
		}	
		else
		{
			//Checkbox Not Checked
			//Fields Not Required hide elements
			hideElementById("Q10017|A10017|ERROR");
			hideElementById("Q10019|A10019|ERROR");
			hideElementById("Q10021|A10021|ERROR");
		}
	}

	/* 
	 * 
	 * END LYRICA SPECIFIC
	* * * * * * */

    }
    catch (e)
    {
    	alert("Validate Form Error: " + e.name);
        rv = false;
    } 
    if (!rv) 
    {	
    	showElementById(pageErrorCtrl+"|ERROR");
        window.location.href = "#top";
    }
  
    else
    {
    	//run this after no error occur
    	hideElementById(pageErrorCtrl+"|ERROR");

    }
    
    return rv;
    
}

function submitForm(formID)
{
	document.forms[formID].submit();
}


function getAge(birthMonth, birthDay, birthYear)
{
    var now = new Date();
    var yearNow = now.getFullYear();
    var monthNow = now.getMonth();
    var monthNow = monthNow + 1; 
    var dateNow = now.getDate();
    
    var yearAge = yearNow - birthYear;            
    
    if (monthNow >= birthMonth)
    {
        var monthAge = monthNow - birthMonth;
    }    
    else
    {
        yearAge--;
        var monthAge = 12 + monthNow - birthMonth;
    }            
    
    if (dateNow >= birthDay)
    {
        var dateAge = dateNow - birthDay;             
        
    }    
    else
    {
        monthAge--;
        var dateAge = 31 + dateNow - birthDay;             
    
        if (monthAge < 0)
        {
            monthAge = 11;
            yearAge--; 
        }
    }

    return yearAge;           
}



//*********************************************************************************
// Begin: Date validation functions
//*********************************************************************************

var dtCh= "/";
var minYear=1800;
var maxYear=2100;

function isInteger(s){
    var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 31
        if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
        if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr)
{
    var daysInMonth = DaysArray(12)
    var pos1=dtStr.indexOf(dtCh)
    var pos2=dtStr.indexOf(dtCh,pos1+1)
    var strMonth=dtStr.substring(0,pos1)
    var strDay=dtStr.substring(pos1+1,pos2)
    var strYear=dtStr.substring(pos2+1)
    strYr=strYear
    if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
    if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
    }
    
    month=parseInt(strMonth)
    day=parseInt(strDay)
    year=parseInt(strYr)
    if (pos1==-1 || pos2==-1){
        return false
    }
    if (strMonth.length<1 || month<1 || month>12){
        return false
    }
    if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
        return false
    }
    if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
        return false
    }
    if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
        return false
    }
    return true
}

//*********************************************************************************
// END: Form Validation
//*********************************************************************************


/*********************************************************************************
 * DIAGNOSTIC TOOL VALIDATION
 *********************************************************************************/

function submitFromAnchor(formID) 
{	
	var questionsList = document.forms[formID]["questions"];
	var questionsArr = questionsList.value.split(",");
	var optionalRadioList = document.forms[formID]["optionalradio"];
	var optionalArr = optionalRadioList.value.split(",");
	var controlsToHide = new Array();
	var numberOfControlsToHide = 0;
	var allSelected = true;			
	var answerArr;
	var answerArr2;
	var buttonChecked;
	var errorElem;
	var questionDiv;

	try
	{			
		var formResults = "";
		
		// loop through questions with radiobutton answers to validate each question and store selected values into formResults variable
		for (var i = 0; i < questionsArr.length; i++)
		{	
			answerArr = document.forms[formID][questionsArr[i]];
			errorElem = questionsArr[i] + "|ERROR";
			questionDiv = questionsArr[i] + "|QUESTION";
			buttonChecked = false;
			
			if(answerArr != undefined)
			{
				for (var j = 0; j < answerArr.length; j++)
				{
					if (answerArr[j].checked)
					{
						buttonChecked = true;

						// add selected Q|A pair to the result string
						var qaPair = answerArr[j].name + "|" + answerArr[j].value + ",";
						if (formResults.indexOf(qaPair) < 0)
						{
							formResults = formResults + qaPair;
						}
						break;
					}
				}
			}
			else
			{
				buttonChecked = true;
			}
			
			// show error message
			if (!buttonChecked)
			{
				showElementById(errorElem);
				showElementById(questionDiv);
				allSelected = false;
			}
			else 
			{
				// question validated -> hide question
				controlsToHide[numberOfControlsToHide] = questionDiv;
				numberOfControlsToHide = numberOfControlsToHide + 1;
			}
		}
		
		// loop through optional questions
		for (var i = 0; i < optionalArr.length; i++)
		{	
			answerArr2 = document.forms[formID][optionalArr[i]];
			errorElem = optionalArr[i] + "|ERROR";
			questionDiv = optionalArr[i] + "|QUESTION";
			
			if(answerArr2 != undefined)
			{
				for (var j = 0; j < answerArr2.length; j++)
				{
					if (answerArr2[j].checked)
					{
						// add selected Q|A pair to the result string
						var qaPair = answerArr2[j].name + "|" + answerArr2[j].value + ",";
						if (formResults.indexOf(qaPair) < 0)
						{
							formResults = formResults + qaPair;
						}
						break;
					}
				}
			}
			// question validated -> hide question
			controlsToHide[numberOfControlsToHide] = questionDiv;
			numberOfControlsToHide = numberOfControlsToHide + 1;
		}

		
		// loop thru questions with checkbox answers to store selected values into formResults variable
		for (var i=0; i<document.forms[formID].elements.length; i++)
		{
			var elem = document.forms[formID].elements[i];
			if (elem.type=="checkbox")
			{	
				if (elem.checked)
				{
					// add checked Q|A pair into formResults string
					var qaPair = elem.name + "|" + elem.value + ",";
					if (formResults.indexOf(qaPair) < 0)
					{
						formResults = formResults + qaPair;
					}
				}
				// question validated -> hide question
				questionDiv = elem.name + "|QUESTION";
				controlsToHide[numberOfControlsToHide] = questionDiv;
				numberOfControlsToHide = numberOfControlsToHide + 1;
			}

			
		}

					
		//cleanup last comma character
		if (formResults.length > 0) { formResults = formResults.substring(0, formResults.length-1); }
		if (allSelected)
		{
			// save results in a cookie
			setCookie(getQuizCookieName(formID), formResults, new Date("1/1/2100"));
			
			// submit the form
			document.forms[formID].submit();
		}
		else
		{

			// show top-page error
			showElementById("ERROR");
						
			// hide controls that passed validation
			for (var i=0; i<numberOfControlsToHide; i++)
			{
				hideElementById(controlsToHide[i]);
			}				
		}
			
	}
	catch (e)
	{
		alert (e.name);
	}
}

/**********************
 *  QUIZ VALIDATION
 **********************/
function getQuizCookieName(quizID)
{
	return "cwpQuiz_" + quizID;
}

var timerID;
function setRedirectTimer(url)
{
	timerID = self.setTimeout("redirectOnTimer('" + url + "')", 1000 * 10);
}
	
function redirectOnTimer(url)
{
	clearTimeout(timerID);
	window.location.href = url;
}

function takeAgain(quizID) 
{
	deleteCookie(getQuizCookieName(quizID));
	window.location.href=window.location.href;
}
function submitPollFromAnchor(formID) 
{		
	try
	{
		hideElementById("main|ERROR");
		
		var questionsList = document.forms[formID]["questions"];
		var buttonsArr = questionsList.value.split(",");
		var allSelected = true;
		
		for (i=0; i<buttonsArr.length; i++)
		{	
			var buttonElem = document.forms[formID][buttonsArr[i]];				
			var buttonChecked = false;
			
			for (j=0; j<buttonElem.length; j++)
			{
				if (buttonElem[j].checked)
				{
					buttonChecked = true;
					break;
				}
			}
			
			if (!buttonChecked)
			{
				allSelected = false;
				break;
			}
		}
		
		if (!allSelected)
		{
			showElementById("main|ERROR")
		}
		else
		{	
			document.forms[formID].submit();
		}
	}
	catch (e)
	{
		alert (e);
	}
}

/**********************\
|*  Quick Poll
\**********************/
function seePollResults(formID)
{
	document.forms[formID]["seeResults"].value = "true";
	document.forms[formID].submit();
}

/**********************\
|*  Printer Friendly
\**********************/
function turnOffPrintFriendly()
{
    window.location.href=document.referrer;
}

/**********************
 *  Email a Friend
 **********************/
function resetForm()
{
    try
    {   
        //document.getElementById("errorGenericValidationMsg").style.display = "none";
        document.getElementById("errorSenderName").style.display = "none";
        document.getElementById("errorSenderEmail").style.display = "none";
        document.getElementById("errorRecipientName").style.display = "none";
        document.getElementById("errorRecipientEmail").style.display = "none";
        document.getElementById("errorMessageSent").style.display = "none";
        
        document.getElementById("txtSenderName").value = "";
        document.getElementById("txtSenderEmail").value = "";
        document.getElementById("txtRecipientName").value = "";
        document.getElementById("txtRecipientEmail").value = "";
        document.getElementById("rdoMessageSent1").checked = false;
        document.getElementById("rdoMessageSent2").checked = false;
    }
    catch (e)
    {
        alert (e);
    }
}

/**********************\
|*  Cookies
\**********************/

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function getCookieforDisplayValueinTemp(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    cookieSet(name);
    return unescape(dc.substring(begin + prefix.length, end));
}


// For store the cookies into temporary folder.

function cookieSet(name)
{
    var cookieValue = getCookie(name); 
    if (document.cookie != document.cookie) 
    {
        index = document.cookie.indexOf(cookieValue);
    } else
    {
        index = -1;
    }
    if (index == -1) 
    {
        document.cookie= name + " = " + cookieValue+ ";expires=''";
    }
} 
/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

/**
 * Determine whether a variable is considered to be empty based on its type
 * types = number, string, boolean, object, function, undefined
 * 
 *	@varable	A variable
 *
 *	Returns FALSE if var has a non-empty and non-zero value:
 *	"" (an empty string)
 *	null (an empty string)
 *	0 (an empty number)
 *	false (an empty boolean)
 *	0 (an empty value length of an object)
 *	null (an empty value of an object)
 *	undefined (an empty object type)
 */
function empty(variable)
{
	if(typeof variable == "number"){
		if (variable == 0){
			return true;
		}
	}
	else if (typeof variable == "string"){
		if(variable == null || variable == "" || variable.length < 0){
			return true;
		}
	}
	else if (typeof variable == "boolean"){
		if (variable == false){
			return true;
		}
	}
	else if (typeof variable == "object"){
		if (variable.value.length == 0 || variable.value == null){
			return true;
		}
	}
	else if (typeof variable == "function"){
		return false;
	}
	else if (typeof variable == "undefined"){
		return true;
	}
	else if (typeof variable == "null"){
		return true;
	}
	return false;
	 
}
/**
 * Determine whether a radio button is checked
 * 
 *	@radioGroupname		The name of the radio group that will be tested
 *
 *	Returns FALSE if a radio button is not checked.
 *	Returns TRUE if a radio button is checked.
 */
function testRadio(radioGroupName)
{
	var test = false;
	//Get Radio Buttons in Group
	
	var radioGroup = document.getElementsByName(radioGroupName);
	//Loop Through Each Button and Test if Checked
	for (i=0; i < radioGroup.length; i++)
	{
		if(radioGroup[i].checked)
		{
			test = true;
		}
	}
	return test;
}

/**
 * Validates Checkbox/Radio is checked
 * 
 *	@element	checkbox/Radio object
 */
function isChecked(element){
	if(element.checked){
		return true;
	}else{
		return false;
	}
}

/**
 * Validates Zip Code is 5 - 7 digits
 * 
 *	@zipValue		The value of the zipcode field
 */
 
function isZip(value)
{
	var regEx = /^(\d\d\d\d\d?\d?\d)$/;
	if(regEx.test(value)){
		return true;
	}else{
		return false;
	}	
}

/**
 * Validates Phone Number 123-456-7890
 * 
 *	@value	phone number entered into form
 */
function isPhone(value)
{
	var regEx = /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/;
	if(regEx.test(value)){
		return true;
	}else{
		return false;
	}
}

/**
 * Validates Email Address
 * 
 *	@value	email address entered into form
 */
function isEmail(value)
{
	var regEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (regEx.test(value)){
		return true;
	}else{
		return false;
	}
}

/**
 * Show an HTML element 
 * 
 *	@elemID		The ID of the html element that will be displayed
 */
function showElementById(elemID)
{
	if(document.getElementById(elemID))
	{
		document.getElementById(elemID).style.display="block";
	}
}

/**
 * Hide an HTML element 
 * 
 *	@elemID		The ID of the html element that will be hidden
 */
function hideElementById(elemID)
{
	if(document.getElementById(elemID))
	{
		document.getElementById(elemID).style.display="none";
	}    
}

/**
 * Clear Default text in textbox 
 * 
 *	@elemID		The ID of the html element text box that will be cleared.
 *
 *	Writen by:	Bryce Acer
 *	Date:		1/6/2006
 */
function clearDefault(elemID)
{
	if (elemID.defaultValue==elemID.value) elemID.value = ""
}/**
 * Validates State Abbreviation is Valid
 *
 * @value  state abbreviation entered into form
 */
function isState(value)
{
	var regEx = /^(AK|AL|AR|AS|AZ|CA|CO|CT|DC|DE|FL|FM|GA|GU|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MH|MI|MN|MO|MP|MS|MT|NB|NC|ND|NH|NJ|NM|NV|NY|OH|OK|OR|PA|PR|PW|RI|SC|SD|TN|TX|UT|VA|VT|WA|WI|WV|WY)$/i;
	if (regEx.test(value)){
		return true;
	}else{
		return false;
	}
}


//Function to Get the checked values of radio button and check box
function getOptionalQuestion(objControl,objHiddenControl)
 {
    getRadioValue(document.getElementById(objControl),document.getElementById(objHiddenControl));
 }
 
 /* Including this function for the Forms  for getting the values of selected answers in to the
 hidden variables*/
    
    function getRadioValue(objCntrl,objhdn)
    {
      objhdn.value = objCntrl.value;
    }
    
    
    /*Added for send_to_friend.aspx rdoMessageSent */
 
function RadioMessageSent1Click()
{
  document.getElementById('hdnMessageSent').value = "rdoMessageSent1|I thought you might be interested in this information";
}

function RadioMessageSent2Click()
{
  document.getElementById('hdnMessageSent').value = "rdoMessageSent2|Check out this information that I found online. I hope you find it useful!";
}

//To get the value of BI in each and every dynamic form
 function getChkBI(objCntrl, objhdn)
 {
    if(document.getElementById(objCntrl).checked==true)
    {
       document.getElementById(objhdn).value="BI";
    }
    else
    {
        document.getElementById(objhdn).value="";
    }
 }
 
//To get the values of check boxes checked
function getChkbox(objCntrl, objhdn, valueInsert)
 {
    if(document.getElementById(objCntrl).checked)
    {
       document.getElementById(objhdn).value=valueInsert;
    }
    else
    {
        document.getElementById(objhdn).value="";
    }
 }  


function setHeaderFont()
{
var baseUrl = window.location.href;
    if(baseUrl != null && baseUrl.indexOf("PrinterFriendly=TRUE") > 0)
    {
        var allParas = document.getElementsByTagName("p");        
        var lenP = allParas.length;
        var strCookie = readCookie('style');
        if(strCookie.indexOf("siteLarge") > 0)
        {
            for(i = 0; i < lenP; i++)
            {             
                if(allParas[i].className == "contentheader")
                     allParas[i].className = "contentLargeheader";
                else if(allParas[i].className == "contentsubhead")
                     allParas[i].className = "contentLargeSubhead";
                else if(allParas[i].className == "errortext")
                     allParas[i].className = "errorLargeText";
            }
        }
        else if(strCookie.indexOf("siteSmall") > 0)
        {
            for(i = 0; i < lenP; i++)
            {             
                if(allParas[i].className == "contentheader")
                     allParas[i].className = "contentSmallheader";
                else if(allParas[i].className == "contentsubhead")
                     allParas[i].className = "contentSmallSubhead";
                else if(allParas[i].className == "errortext")
                     allParas[i].className = "errorSmallText";
            }
        }
        
        if(baseUrl.indexOf("assess") > 0)
        {
            var allParas = document.getElementsByTagName("span");        
            var lenP = allParas.length;        
            if(strCookie.indexOf("siteLarge") > 0)
            {
                for(i = 0; i < lenP; i++)
                {            
                    if(allParas[i].className == "errortext")
                        allParas[i].className = "errorLargeText";
                }
            }
            else if(strCookie.indexOf("siteSmall") > 0)
            {
                for(i = 0; i < lenP; i++)
                {             
                    if(allParas[i].className == "errortext")
                         allParas[i].className = "errorSmallText";
                }
            }
        }
    }    
}

function OpenPopup(urlId, name, link)
{
    PartnerLinkClicked(name,link); 
    url = null; 
    switch(urlId) {
      case '1' : {
         url = "http://www.pfizer.com/pfizer/mn_terms.jsp"; 
         break; 
        }
         case '2' : {
         url = "http://www.pfizer.com/privacy"; 
         break; 
         }
         case '3' : {
         url = "http://www.pfizer.com/pfizer/are/index.jsp"; 
         break; 
         }
         case '4' : {
         url = "https://www.pfizerpro.com/sites/ppro/pages/products/lyrica.aspx"; 
         break; 
         }
    }
    if(url) {
      window.open(url); 
    }
}

function GoToUrl(urlID) {
   url = null; 
   switch(urlID) {
      case "1" : {
         url = "http://www.diabetes.org";
         break; 
         }
      case "2" : {
         url = "http://www.painfoundation.org"; 
         break; 
         }
      case "3" : {
         url = "http://www.theacpa.org"; 
         break; 
         }
      case "4" : {
         url = "http://www.neuropathy.org"; 
         break; 
         }
      case "5" : {
         url = "http://www.nfcacares.org"; 
         break; 
         }
      case "6" : {
         url = "http://www.diabetes.org/type-1-diabetes/nerve-damage.jsp"; 
         break; 
         }
      case "7" : {
         url = "http://www.diabetes.niddk.nih.gov";
         break; 
         }
      case "8" : {
         url = "http://www.cdc.gov"; 
         break; 
         }
      case "9" : {
         url = "http://www.cdc.gov/diabetes/pubs/tcyd/eye.htm";
         break; 
         }
      case "10" : {
         url = "http://www.cdc.gov/diabetes/pubs/tcyd/foot.htm";
         break; 
         }
      case "11" : {
         url = "http://www.mayoclinic.com/health/AboutThisSite/AM00021"; 
         break; 
         }
      case "12" : {
         url = "http://www.efa.org"; 
         break; 
         }
     case "13" : {
         url = "http://www.epilepsy.org";
         break; 
         }
     case "14" : {
         url = "http://www.epilepsy.com"; 
         break; 
         }
     case "15" : {
         url = "http://www.epilepsyfoundation.org/about/quickstart/newlydiagnosed/index.cfm"; 
         break; 
         }
     case "16" : {
         url = "http://my.webmd.com/content/article/38/1812_50850"; 
         break; 
         }
     case "17" : {
         url = "http://my.webmd.com/content/article/87/99658.htm"; 
         break; 
         }
     case "18" : {
         url = "http://www.mayoclinic.com/health/epilepsy/DS00342/UPDATEAPP=false&FLUSHCACHE=0"; 
         break; 
         }
     case "19" : {
         url = "http://www.ninds.nih.gov/disorders/epilepsy/detail_epilepsy.htm"; 
         break; 
         }
     case "20" : {
         url = "http://www.epilepsyfoundation.org/answerplace/Social/"; 
         break; 
         }
     case "21" : {
         url = "http://my.webmd.com/content/article/87/99659.htm"; 
         break; 
         }
     case "22" : {
         url = "http://www.mayoclinic.com/health/epilepsy/DS00342/UPDATEAPP=false&FLUSHCACHE=0"; 
         break; 
         }
     case "23" : {
         url = "http://www.epilepsyfoundation.org/answerplace/Life/adults/women/"; 
         break; 
         }
     case "24" : {
         url = "http://my.webmd.com/content/article/88/99683.htm"; 
         break; 
         }
     case "25" : {
         url = "http://www.ninds.nih.gov/disorders/epilepsy/detail_epilepsy.htm";
         break; 
         }
     case "26" : {
         url = "http://www.epilepsyfoundation.org/advocacy/legalaspects.cfm"; 
         break; 
         }
     case "27" : {
         url = "http://www.vzvfoundation.org/"; 
         break; 
         }
     case "28" : {
         url = "http://www.ninds.nih.gov/"; 
         break; 
         }
     case "29" : {
         url = "http://www.ninds.nih.gov/disorders/shingles/shingles.htm";
         break; 
         }
     case "30" : {
         url = "http://www.fmaware.org/site/PageServer?pagename=community_awarenessDay2010";
         break; 
         }
     case "31" : {
         url = "http://www.DiabetesNervePainStudy.com";
         break; 
         }
      }
   if(url) {
      window.location = url;    
      }
   }

var SessionValue ="";   
        
function GetSessionValue(key) {
   try {
      xmlHttp = new XMLHttpRequest(); 
      }
   catch (e) {
      try {
         xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); 
         }
      catch (e) {
         try {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
            }
         catch (e) {
            alert("Your browser does not support AJAX!"); 
            return false; 
            }
         }
      }
   url = "GetSessionValue.aspx?key=" + key + "&dummy=" + new Date().getTime(); 
   xmlHttp.open("GET", url, false); 
  // xmlHttp.onreadystatechange = UpdateSessionValue; 
   xmlHttp.send(null); 
      if(xmlHttp.status == 200)
      {
         SessionValue = xmlHttp.responseText; 
      }
     return SessionValue;
   }


function getObject2(obj) {
	theObj = document.getElementById(obj).style;
	return theObj;
}
// Setting the display of an object to block
function display(obj) {
	var theObj = getObject2(obj);
	theObj.display = "block";
}

// Setting the display of an object to none
function unDisplay(obj) {
	var theObj = getObject2(obj);
	theObj.display = "none";
}
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get;
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}

