function openZetiaComplianceWin() {
	var myWin = window.open("/ezetimibe/zetia/hcp/shared/compliance_program/index.jsp","Compliance","toolbar=no,scrollbars=1,location=no,statusbar=0,menubar=0,resizable=1,width=631,height=400")
	if (myWin.opener == null)
		myWin.opener = window;
	myWin.opener.name = "opener";
}

function openZetiaPrivacyWin() {
	var myWin = window.open("/ezetimibe/zetia/hcp/shared/privacy/index.jsp","Healthcare","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=631,height=400")
	if (myWin.opener == null)
		myWin.opener = window;
	myWin.opener.name = "opener";
}

function openZetiaCopyWin() {
	var myWin = window.open("/ezetimibe/zetia/hcp/shared/copyright/index.jsp","Healthcare","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=631,height=400")
	if (myWin.opener == null)
		myWin.opener = window;
	myWin.opener.name = "opener";
}

function openZetiaTermsWin() {
	var myWin = window.open("/ezetimibe/zetia/hcp/shared/terms/index.jsp","Healthcare","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=631,height=400")
	if (myWin.opener == null)
		myWin.opener = window;
	myWin.opener.name = "opener";
}

function openZetiaPAPWin() {
	var myWin = window.open("/ezetimibe/zetia/hcp/shared/pap/index.jsp","Physician","toolbar=no,scrollbars=1,location=no,statusbar=0,menubar=0,resizable=1,width=631,height=400")
	if (myWin.opener == null)
		myWin.opener = window;
	myWin.opener.name = "opener";
}

function openReprintWin(page_name) {
	var myWin = window.open("/ezetimibe/zetia/hcp/clinical_studies/journal_reprints/"+page_name+".jsp","reprint","width=450,height=410,scrollbars=no,location=no,status=no,resizable=no")
	if (myWin.opener == null)
		myWin.opener = window;
	myWin.opener.name = "opener";
}

/************************************************
DESCRIPTION: Validates required fields for order forms

PARAMETERS:
   form to validate

RETURNS:
   True if valid, alert window with errors if false.
*************************************************/
function validate(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 email = frm.email.value;
	var firstname = frm.firstname.value;
	var lastname = frm.lastname.value;
	var postalcode = frm.postalcode.value;
	var proftype = frm.proftype.selectedIndex;
	
	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)) {
		isErr = true;
		errMessage = errMessage + "Please enter Last Name\r\n";
		if (errField.length <= 0) errField = "lastname";
	}

	if(validateIsEmpty(postalcode)) {  // postalcode field is empty
		isErr = true;
		errMessage = errMessage + "Please enter 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";
		}
	}
	if (validateIsEmpty(email)) {  // email field is empty
		isErr = true;
		errMessage = errMessage + "Please enter your valid 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][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(proftype == 0) {
		isErr = true;
		errMessage = errMessage + "Please enter your Professional Designation\r\n";
		if (errField.length <= 0) errField = "proftype";
	}
	
	
	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}\W+\d{4}$)|(^\d{9}$)/) == -1) return false;
	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;
}
function isAlphabetic(string) {
   if (string.search) {
      if(string.replace(" ", "").search(/[^a-zA-Z]/) != -1) 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;


function openWindow(url) {
	var myWin = window.open(url,"ZETIA","toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=650,height=520")
	if (myWin.opener == null)
		myWin.opener = window;
	myWin.opener.name = "opener";
}

function openTranscriptWindow(url) {
	var myWin = window.open(url,"ZETIA","toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=450,height=500")
	if (myWin.opener == null)
		myWin.opener = window;
	myWin.opener.name = "opener";
}

function getURLParam(strParamName) {
	var strReturn = "";
	var strHref = window.location.href;
	if ( strHref.indexOf("?") > -1 ) {
		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ ) {
			if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ) {
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
	return strReturn;
}

/************************************************
DESCRIPTION: Open MPS popup window

PARAMETERS: url number and page name

RETURNS: popup window with link button to next page
*************************************************/

function openContainerWin(urlnum, mpspage) {
	var myWin = window.open("/ezetimibe/zetia/hcp/mps_pop/index.jsp?urlnum=" + urlnum + "&mps_page=" + mpspage + " ","container","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=480,height=250")
	if (myWin.opener == null)
		myWin.opener = window;
	myWin.opener.name = "opener";
}
