function openDisclaimerWin(channel) {
	if (document.cookie) {
  		if (document.cookie.toLowerCase().indexOf("us_healthcare=yes") >= 0) {
			if (channel == "allergies")	{window.location.href="/montelukast_sodium/singulair/hcp/allergies/index.jsp";}
			else if (channel == "allergists") {window.location.href="/montelukast_sodium/singulair/hcp/for_allergists/index.jsp";}
			else if (channel == "ped") {window.location.href="/montelukast_sodium/singulair/hcp/asthma_peds/index.jsp";}
			else if (channel == "pulm") {window.location.href="/montelukast_sodium/singulair/hcp/pulm/index.jsp";}
			else if (channel == "take_charge") {window.location.href="/montelukast_sodium/singulair/hcp/allergies/take_charge_of_relief/index.jsp";}
			else if (channel == "back_to_school") {window.location.href="/montelukast_sodium/singulair/hcp/asthma_peds/resources/back_to_school.jsp";}
			
			else window.location.href="/montelukast_sodium/singulair/hcp/asthma/index.jsp";
			return;
		}
  	}
	
  	var myWin = window.open("/montelukast_sodium/singulair/hcp_disclaimer_popup.jsp?channel="+channel,"Healthcare","status=no,width=300,height=190,scrollbars=no")
  	if (myWin.opener == null)
		myWin.opener=window;
  	myWin.opener.name="opener";
	myWin.focus();
}


function openRelatedExtWin(url) {
    if(! confirm("Thank you for visiting Singulair.com.\n\nYou are now being connected to another site.\n\nDo you wish to continue?"))
        return;

    var externalWin = window.open(url,null,"toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=700,height=600");
    if (externalWin.opener == null)
        externalWin.opener=window;
        externalWin.opener.name="opener";
}


/************************************************
DESCRIPTION: Validates required fields for RMI demographic info

PARAMETERS:
   RMI form to validate

RETURNS:
   True if valid, alert window with errors if false.
*************************************************/
function validateRMI(frm) {
	// Set variables
	var isErr = false; // for any type of error
	var errMessage = ""; // 
	var errField = ""; // if there is an error, focus on the first required form field error
	
	// Get form values
	var firstname = frm.firstname.value;
	var lastname = frm.lastname.value;
	var email = frm.email.value;
	var address1 = frm.address1.value;
	var city = frm.city.value;
	var state = frm.state.value;
	var postalcode = frm.postalcode.value;
	//var birth_month = frm.birth_month.value;
	//var birth_day = frm.birth_day.value;
	//var birth_year = frm.birth_year.value;
	/*
	var radio_choice = false;
	for (counter = 0; counter < frm.gender.length; counter++)
	{
	if (frm.gender[counter].checked)
	radio_choice = true; 
	}
	
	if (!radio_choice) {
		isErr = true;
		errMessage = "Please Select Gender\r\n";
		if (errField.length <= 0) errField = "gender[0]";	
		}
	*/
	if(validateIsEmpty(firstname)) {  // firstname field is empty
		isErr = true;
		errMessage = "Please enter your First Name\r\n";
		if (errField.length <= 0) errField = "firstname";
	} else if(!isAlphabetic(firstname)) {
		isErr = true;
		errMessage = "You must enter only alphabetical characters in First Name\r\n";
		if (errField.length <= 0) errField = "firstname";
		}
		
	if(validateIsEmpty(lastname)) {  // lastname field is empty
		isErr = true;
		errMessage = errMessage + "Please enter your Last Name\r\n";
		if (errField.length <= 0) errField = "lastname";
	} else if(!isAlphabetic(lastname)) {
		isErr = true;
		errMessage = errMessage + "You must enter only alphabetical characters in Last Name\r\n";
		if (errField.length <= 0) errField = "lastname";
		}
		
	if (validateIsEmpty(email)) {  // email field is empty
		isErr = true;
		errMessage = errMessage + "Please enter your e-mail address\r\n";
		if (errField.length <= 0) errField = "email";
	} else {
		email = email.trim();
		var x = email.search(/ /);
		var y = email.search(/,/);
		var z = email.search(/;/);
		
		if ((x != -1) || (y != -1) || (z != -1)) { // Check for more than one email address
			isErr = true;
			errMessage = errMessage + "You are only allowed to enter one e-mail address at a time.\r\n";
			if (errField.length <= 0) errField = "email";
			}
		if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1) { // Check for valid email address
			isErr = true;
			errMessage = errMessage + "Please enter your valid e-mail address\r\n";
			if (errField.length <= 0) errField = "email";
			}
		}
		
	if(validateIsEmpty(address1)) {  // Address field is empty
		isErr = true;
		errMessage = errMessage + "Please enter your Address\r\n";
		if (errField.length <= 0) errField = "address1";
		}
		
	if(validateIsEmpty(city)) {  // City field is empty
		isErr = true;
		errMessage = errMessage + "Please enter your City\r\n";
		if (errField.length <= 0) errField = "city";
	} else if(!isAlphabetic(city)) {
		isErr = true;
		errMessage = errMessage + "You must enter only alphabetical characters in City name\r\n";
		if (errField.length <= 0) errField = "city";
		}
		
	if(state <= 0) {  // State field is empty
		isErr = true;
		errMessage = errMessage + "Please enter your State\r\n";
		if (errField.length <= 0) errField = "state";
		}
		
	if(validateIsEmpty(postalcode)) {  // postalcode field is empty
		isErr = true;
		errMessage = errMessage + "Please enter your ZIP Code\r\n";
		if (errField.length <= 0) errField = "postalcode";
	} else {
		postalcode = postalcode.trim(); // remove whitespace around value
		if (!validateUSZip(postalcode)) { // Check zip code is in valid format
			isErr = true;
			errMessage = errMessage + "Please enter a valid ZIP Code in 5 digit format.\r\n";
			if (errField.length <= 0) errField = "postalcode";
			}
		}
	
	// var info = document.getElementByID(info_for_who);
	// if(!info.checked) {
	//	isErr = true;
	//	errMessage = errMessage + "Please tell us if this information is for you or someone else\r\n";
	//	if (errField.length <= 0) errField = "info_for_who";
	//	}

	/*
	if((validateIsEmpty(birth_month)) || (validateIsEmpty(birth_day)) || (validateIsEmpty(birth_year))) {
		isErr = true;
		errMessage = errMessage + "Please enter Date of Birth\r\n";
		if (errField.length <= 0) errField = "birth_month";
	}	
	if (frm.magazine) { // if magazine field exists
		if (!validateBoxes(frm.magazine)) { // no radio boxes were checked - producing an error
			isErr = true;
			errMessage = errMessage + "Please enter Magazine\r\n";
				
			if (errField.length <= 0) errField = "magazine[0]";
		}
	}
	*/
	
	if (isErr) {
		alert(errMessage);
		
		eval("frm." + errField + ".focus()");
		
		return false;
	}
	
	return true;
}

/************************************************
DESCRIPTION: Validates that a string is a United
  States zip code in 5 digit format or zip+4
  format. The following are acceptable:
  	12345
	12345-1234
	12345+1234
	12345 1234
	123451234

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
*************************************************/
function validateUSZip(strValue) {
	if (strValue.search(/(^\d{5}$)|(^\d{5}-\d{4}$)|(^\d{5}\+\d{4}$)|(^\d{5}\s+\d{4}$)|(^\d{9}$)/) == -1) return false;
	return true;
}

/************************************************
DESCRIPTION: Validates a radio or checkbox set

PARAMETERS:
	fldName - form field to validate

RETURNS:
   True if valid, otherwise false.
*************************************************/
function validateBoxes(fldName) {
	var numBoxes = fldName.length; // num of radio boxes
	var prevUnchecked = false;
	var currentUnchecked = false;
	
	for (var i=0; i < numBoxes; i++) { // cycle through radio boxes to see if any are checked
		if (! fldName[i].checked) {
			currentUnchecked = true;
			if (prevUnchecked ==  false) {
				prevUnchecked = currentUnchecked;
			}
		} else {
			prevUnchecked = false;
			break;
		}
	}
	
	if (prevUnchecked) return false;
	else return true;
}

/************************************************
DESCRIPTION: Checks if a string is empty

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid (empty), otherwise false (not empty).
*************************************************/
function validateIsEmpty(strValue) {
	strValue = strValue.trim();
	if(strValue.length > 0) return false;
	return true;
}

/************************************************
DESCRIPTION: Removes leading and trailing spaces.

PARAMETERS: Source string from which spaces will
  be removed;

RETURNS: Source string with whitespaces removed.
*************************************************/
function trimString (strValue) {
	strValue = this != window? this : strValue;
	return strValue.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

// Added as a method to the String.prototype
String.prototype.trim = trimString;

/*******************************************************
DESCRIPTION: Check that a string contains only letters

PARAMETERS: Source string

RETURNS: True or false.
******************************************************/	
function isAlphabetic(string) {
   if (string.search) {
       if(string.replace(" ", "").search(/[^a-zA-Z]/) != -1) return false
   }
   return true;
}
