/**
Flash Version Detection
*/
b = navigator.userAgent.toLowerCase();
if ( (b.indexOf('msie') != -1) && (b.indexOf('win') != -1) && (b.indexOf('opera') == -1) ) {
	document.writeln('<script language="VBscript">');
	document.writeln('Function detectActiveXControl(activeXControlName)');
	document.writeln('  on error resume next');
	document.writeln('  detectActiveXControl = False');
	document.writeln('  detectActiveXControl = IsObject(CreateObject(activeXControlName))');
	document.writeln('End Function');
	document.writeln('</scr' + 'ipt>');
}
function getFlashVersion(){
	var installedVersion = 0;
	if ( (b.indexOf('msie') != -1) && (b.indexOf('win') != -1) && (b.indexOf('opera') == -1) ) {
		for (var i=3; i<10; i++){
			if(detectActiveXControl("ShockwaveFlash.ShockwaveFlash."+i) == true) installedVersion = i;
		}
	} else {
		if (navigator.plugins["Shockwave Flash"]) {
			var pluginDesc = navigator.plugins["Shockwave Flash"].description;
			installedVersion = parseInt( pluginDesc.charAt( pluginDesc.indexOf(".")-1 ) );
		}
		if(b.indexOf("webtv") != -1) installedVersion = 3;  
	}
	return installedVersion;
}
/**
Feedback form popup code
*/

		//Check Radio Buttons
		//email a friend work around
var no_popup_url = window.location.href;
var no_popup_check = no_popup_url.indexOf('nerve_man_spot');
if(no_popup_check==-1){
	no_popup_check = no_popup_url.indexOf('thank_you');
}
if(no_popup_check==-1){
	if (window.Event) {
		if (!getCookie( 'helpnervepain' ) ) {
				window.onbeforeunload = function(event) {
				return unloadMoz(event); // pass argument event block
			}
		}
	} else {
		 if (!getCookie( 'helpnervepain' ) ) {
				window.onbeforeunload = function() {
				return HandleOnClose(event); // pass IE's global event block
			}
		 }
	}
}
var posx;
var posy;

function getMouse(e){
	posx=0;posy=0;
	var ev=(!e)?window.event:e;//IE:Moz
	if (ev.pageX){//Moz
		posx=ev.pageX+window.pageXOffset;
		posy=ev.pageY+window.pageYOffset;
	}else if(ev.clientX){//IE
		posx=ev.clientX+document.body.scrollLeft;
		posy=ev.clientY+document.body.scrollTop;
	}else{return false}//old browsers
}

document.onclick=getMouse;

function unloadMoz(){
	getMouse;
	if (!posx || !posy){
		  window.open("feedback_prompt.aspx", "tinyWindow", 'toolbar=0,width=540,height=280,resizable=no,status=yes,scrollbars');
	}
	 
}

function HandleOnClose() {

   if (event.clientY < 0 || event.pageY < 0) {
		 window.open("feedback_prompt.aspx", "tinyWindow", 'toolbar=0,width=540,height=280,resizable=no,status=yes,scrollbars');
	}
}

/**
 * FAQ Resize    
 */
function faq_resize(x){
	var faq_state_check;
	var z;
	z = document.getElementById(x).className;
	faq_state_check = z.indexOf('collapse');
	
	if(faq_state_check>0){
		document.getElementById (x).className = "faq_a_text_expand";
	} else {
		document.getElementById (x).className = "faq_a_text_collapse";
	}
}

/**
 * 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 futuremonthyearCtrl == "undefined"){futuremonthyearCtrl = "";}
	if(typeof stateCtrl == "undefined"){stateCtrl = "";}
    
    try
    { 
		// reset error messages
		var resetArr = new Array(valCtrls, confirmCtrls, dateCtrl, birthdateCtrl, emailCtrl, monthyearCtrl, ageCtrl,  radioCtrl, zipCtrl, phoneCtrl, pageErrorCtrl, futuremonthyearCtrl, stateCtrl);	
		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))
				{
					hideElement(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))
				{
					showElement(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)
		        { 
					showElement(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))
				    {
						showElement(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))
			    { 
					showElement(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 = urlAgeError;
							return false;                 
						}
						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))
				    {
						showElement(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))
				    {
						showElement(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))
					{ 
						showElement(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)
					{
						showElement(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 = 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 = urlAgeError;               
						}
						rv = false;
					}
				}
			}
		}
	
		//Check Radio Buttons
		//email a friend work around
		var emailafriend_url = window.location.href;
		var emailafriend_check = emailafriend_url.indexOf('email_a_friend');
		if(emailafriend_check==-1){
			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))
					{				
						showElement(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))
				    {
					showElement(id+"|ERROR");
					rv = false;
				    }
				}
		    }
		}

	        //check future month year
		if (futuremonthyearCtrl != "")
	    	{
			var ctrl = futuremonthyearCtrl;
				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))
						{ 
							showElement(id+"|ERROR");
							rv = false;
						}

						var time=new Date();
						var currentYear=time.getFullYear();
						var currentMonth=time.getMonth()+1;

						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 || (monthVal < currentMonth && yearVal == currentYear))
						{
							showElement(id+"|ERROR");
							rv = false;
						}
					}
				}
		}
				
		//check state abbreviation
		if (stateCtrl != "")
		{
			var ctrl = stateCtrl;
			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 (!isState(value))
				    {
						showElement(id+"|ERROR");
						rv = false;
				    }
				}
		    }
		}
	
	    }
	    catch (e)
	    {
	    	alert("Validate Form Error: " + e.name);
	        rv = false;
	    }
	    if (!rv) 
	    {	
	    	showElement(pageErrorCtrl+"|ERROR");
	        window.location.href = "#top";
	    }
	  
	    else
	    {
	    	//run this after no error occur
	    	hideElement(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
}

/*********************************************************************************
 * 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 {
      submitFormCookie(); 
      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) {
            showElement(errorElem); 
            showElement(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
         showElement("ERROR"); 
         // hide controls that passed validation
         for (var i = 0; i < numberOfControlsToHide; i++) {
            hideElement(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 takeAgainAssessPain()
{
    deleteCookie('assessPain');
    deleteCookie('assessPainScore');
    window.location.href=window.location.href;
}
function submitPollFromAnchor(formID) 
{		
	try
	{
		hideElement("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)
		{
			showElement("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
    {   
        // reset error messages
      hideElement("main|ERROR");
      for(var i=0; i<valCtrls.length; i++) 
      {
            var id = valCtrls[i];
            hideElement(id+"|ERROR");
      }

      // reset form fields
      for(var i=0; i<valCtrls.length; i++) 
      {
        var id = valCtrls[i];
        var elem = document.getElementById(id);
        if (elem.type == "radio")
        {
            var answerArr = document.forms["email_a_friend_form"][id];
            for (j = 0; j < answerArr.length; j++)
            {
                answerArr[j].checked = false;
            }
        }
        else
        {
          elem.value = "";
        }
      }
    }
    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" : "");
}
function setCookieAssessPain(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));
}

/**
 * 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(variable.type == "select-one")
		{
			if(variable.value.toLowerCase().indexOf('--') > 0)
			{
				return true;
			}
			if(variable.value.toLowerCase().indexOf("please select") > 0)
			{
				return true;
			}
			if(variable.value.toLowerCase().indexOf("select one") > 0)
			{
				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 =   /^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$/;
	var regEx = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;	
	if (regEx.test(value)){
		return true;
	}else{
		return false;
	}
}
/**
 * Validates State Abbreviation is Valid
 *
 * @value  state abbreviation entered into form
 */
function isState(value)
{
	var regEx = /^(AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MI|MN|MO|MS|MT|NC|ND|NE|NH|NJ|NM|NV|NY|OH|OK|OR|PA|PR|RI|SC|SD|TN|TX|UT|VA|VI|VT|WA|WI|WV|WY)$/i;
	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 showElement(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 hideElement(elemID)
{
	if(document.getElementById(elemID))
	{
		document.getElementById(elemID).style.display="none";
	}    
}

/**
 * Clear Default text in textbox 
 * 
 *	@elem		The element text box that will be cleared.
 *
 *	Writen by:	Bryce Acer
 *	Date:		6/1/2006
 */
    function validateTellaFriend()
    {   

    if (document.getElementById("txtsendername").value=="" ||isEmail(document.getElementById("txtsenderemail").value)==false || document.getElementById("txtrecipientname").value=="" 
    || isEmail(document.getElementById("txtrecipientemail").value)==false)
    {            
            if (document.getElementById("txtsendername").value=="")
            {
                 document.getElementById("errorSenderName").innerHTML="*Please enter your Name";
                 document.getElementById("errorSenderName").style.display="block";
            }
            else
            { 
                document.getElementById("errorSenderName").style.display="none";
            }
            if (isEmail(document.getElementById("txtsenderemail").value)==false || document.getElementById("txtsenderemail").value=="" )
            {
                 document.getElementById("errorSenderEmail").innerHTML="*Please enter your E-mail";
                 document.getElementById("errorSenderEmail").style.display="block";
            }
            else
            {
                 document.getElementById("errorSenderEmail").style.display="none";
            }
            if (document.getElementById("txtrecipientname").value=="")
            {
                 document.getElementById("errorRecipientName").innerHTML="*Please enter your friend's Name";
                 document.getElementById("errorRecipientName").style.display="block";
            }    
            else
            {
                document.getElementById("errorRecipientName").style.display="none";
            }
            if (isEmail(document.getElementById("txtrecipientemail").value)==false || document.getElementById("txtrecipientemail").value=="" )
            {
              document.getElementById("errorRecipientEmail").innerHTML="*Please enter your friend's E-mail";
              document.getElementById("errorRecipientEmail").style.display="block";
              
            }
            else
            {
                document.getElementById("errorRecipientEmail").style.display="none";
            }
            document.getElementById("errorGenericValidationMsg").style.display="block";
            return false;
    }
    else
    {
        return true;
    }
   }
    
  function submitFormCookie() {

   var score = 0; 
   var cookieControls = "";
       if(document.getElementById('Q1|1').checked){score += 1; cookieControls +='Q1|1;';}
       if(document.getElementById('Q1|2').checked) {score += 2;cookieControls +='Q1|2;';}
       if(document.getElementById('Q1|3').checked){ score += 3; cookieControls +='Q1|3;';}
       if(document.getElementById('Q1|4').checked) {score += 4; cookieControls +='Q1|4;';}
       if(document.getElementById('Q1|5').checked) {score += 5; cookieControls +='Q1|5;';}
       if(document.getElementById('Q1|6').checked){ score += 6; cookieControls +='Q1|6;';}
       if(document.getElementById('Q2|1').checked) {score += 1; cookieControls +='Q2|1;';}
       if(document.getElementById('Q2|2').checked){ score += 2; cookieControls +='Q2|2;';}
       if(document.getElementById('Q2|3').checked) {score += 3; cookieControls +='Q2|3;';}
       if(document.getElementById('Q2|4').checked){ score += 4; cookieControls +='Q2|4;';}
       if(document.getElementById('Q3|1').checked) {score += 1; cookieControls +='Q3|1;';}
       if(document.getElementById('Q3|2').checked){ score += 2; cookieControls +='Q3|2;';}
       if(document.getElementById('Q3|3').checked) {score += 3; cookieControls +='Q3|3;';}
       if(document.getElementById('Q3|4').checked){ score += 4; cookieControls +='Q3|4;';}
       if(document.getElementById('Q3|5').checked) {score += 5; cookieControls +='Q3|5;';}
       if(document.getElementById('Q3|6').checked) {score += 6; cookieControls +='Q3|6;';}
       if(document.getElementById('Q3|7').checked){ score += 7; cookieControls +='Q3|7;';}
       if(document.getElementById('Q3|8').checked){ score += 8; cookieControls +='Q3|8;';}
       if(document.getElementById('Q3|9').checked) {score += 9; cookieControls +='Q3|9;';}
       if(document.getElementById('Q3|010').checked){ score += 10; cookieControls +='Q3|010;';}
       if(document.getElementById('Q3|011').checked){ score += 11; cookieControls +='Q3|011;';}
       if(document.getElementById('Q4|1').checked) {score += 1; cookieControls +='Q4|1;';}
       if(document.getElementById('Q4|2').checked){ score += 2; cookieControls +='Q4|2;';}
       if(document.getElementById('Q4|3').checked) {score += 3; cookieControls +='Q4|3;';}
       if(document.getElementById('Q4|4').checked){ score += 4; cookieControls +='Q4|4;';}
       if(document.getElementById('Q4|5').checked) {score += 5; cookieControls +='Q4|5;';}
       if(document.getElementById('Q4|6').checked){ score += 6; cookieControls +='Q4|6;';}
       if(document.getElementById('Q4|7').checked) {score += 7; cookieControls +='Q4|7;';}
       if(document.getElementById('Q5|1').checked){ score += 1; cookieControls +='Q5|1;';}
       if(document.getElementById('Q5|2').checked) {score += 2; cookieControls +='Q5|2;';}
       if(document.getElementById('Q6|1').checked){ score += 1; cookieControls +='Q6|1;';}
       if(document.getElementById('Q6|2').checked) {score += 2; cookieControls +='Q6|2;';}
       if(document.getElementById('Q6|3').checked){ score += 3; cookieControls +='Q6|3;';}
       if(document.getElementById('Q7|1').checked) {score += 1; cookieControls +='Q7|1;';}
       if(document.getElementById('Q7|2').checked){ score += 2; cookieControls +='Q7|2;';}
       setCookieAssessPain('assessPain',cookieControls);
       setCookieAssessPain('assessPainScore',score);          
   }
   
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));

}


// To store the cookies into the 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=''";

    }

} 


/**
 * Form Validation    
 */
 function GoToPartnerUrl(urlId, name,link) {
   PartnerLinkClicked(name,link); 
   url = null; 
   switch(urlId) {
      case '1' : {
         url = "http://www.pfizer.com/pfizer/are/index.jsp"; 
         break; 
         }
      case '2' : {
         url = "http://www.pfizer.com/pfizer/mn_privacy.jsp"; 
         break; 
         }
      case '3':{
         url="http://www.pfizer.com/pfizer/mn_terms.jsp"
         }
      }
  if(url) {
      window.location = url; 
      }
 }

   
   
   
   