function di(id,name)
{
	document.images[id].src=eval(name+".src");
}

butt = new Image(20, 19); butt.src = 'images/butt_off.gif';
butto = new Image(20, 19); butto.src = 'images/butt_over.gif';
pres = new Image(183, 19); pres.src = '/images/kc/build_pres_off.gif';
preso = new Image(183, 19); preso.src = '/images/kc/build_pres_over.gif';
report = new Image(148, 19); report.src = '/images/kc/build_report_off.gif';
reporto = new Image(148, 19); reporto.src = '/images/kc/build_report_over.gif';


function URLEncode(s)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";
	var encoded = "";

	for (var i = 0; i < s.length; i++ ) {
		var ch = s.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};

function displayCopy(urlToLink, selectBox)
{	
	var valueToPass;
	var optionLength;
	
	valueToPass = selectBox.options[selectBox.selectedIndex].value;
	optionLength = valueToPass.length;
	if (optionLength > 0)
	{
		//alert("URL : " + urlToLink + valueToPass);
		document.location.href = urlToLink + valueToPass;
	}	
}

// handles the Enter button being pressed on the Login Screen
function doKeyPressLogin(event, form)
{
	if (event.keyCode==13)
	{
		if (validateLogin(form) == true)
		{
			form.submit();
		}
	}
	
}

// handles the Enter button being pressed on the Login Screen
function doKeyPressChangePassword(event, form)
{
	if (event.keyCode==13)
	{
		if (validateChangePassword(form) == true)
		{
			form.submit();
		}
	}
	
}

// validates the Login Form
function validateLogin(form)
{
	var username;
	var password;
	var errorText;
	username = form.Username.value;
	password = form.Password.value;
	errorText = "";

	if (username.length < 1)
	{
		errorText = errorText + "Your username must not be blank\n";
		form.Username.focus();
	}
	else
	{
		if (username.length > 15)
		{
			errorText = errorText + "Your username must be less than 15 characters\n";
			form.Username.focus();
		}
	}
	if (password.length < 5)
	{
		errorText = errorText + "Your password must be AT LEAST 5 characters\n";
		form.Password.focus();
	}
	else
	{
		if (password.length > 15)
		{
			errorText = errorText + "Your password must be less than 15 characters\n";
			form.Password.focus();
		}
	}
	if (errorText.length != 0)
	{
		alert(errorText);
		validateLogin == false;
	}
	else
	{
		validateLogin == true;
		form.submit();
	}
	
}

// validates the ChangePassword Form (when user first logs in)
function validateChangePassword(form)
{
	var newPassword;
	var confirmNewPassword;
	var errorText;
	newPassword = form.newPassword.value;
	confirmNewPassword = form.confirmNewPassword.value;
	errorText = "";

	if (newPassword.length < 1)
	{
		errorText = errorText + "Your new password must NOT be blank!\n";
	}
	else 
	{
		if (newPassword.length < 5)
		{
			errorText = errorText + "Your new password must be AT LEAST 5 characters!\n";
		}
	}
	if (newPassword.length > 15)
	{
		errorText = errorText + "Your new password must be less than 15 characters!\n";
	}
	if (newPassword != confirmNewPassword)
	{
		errorText = errorText + "Your new passwords must match!\n";
	}
	if (errorText.length != 0)
	{
		alert(errorText);
		validateChangePassword == false;
	}
	else
	{
		validateChangePassword == true;
		form.submit();
	}
}

// validates the forgotten password form
function validateForgottenPassword(form)
{
	var emailAddress;
	var username;
	var returnBoolean;
	var errorText;
	
	errorText = "";
	emailAddress = form.existingEmail.value;
	username = form.existingUsername.value;
	
	if (username.length == 0)
	{
		errorText = errorText + "Your username must NOT be blank!\n";
		form.existingUsername.focus();
	}
	else
	{
		if (username.length > 15)
		{
			errorText = errorText + "Your username must be less than 15 characters!\n";
			form.existingUsername.focus();
		}
	}
	if (emailAddress.length > 0)
	{
		if (checkEmail(emailAddress) == false)
		{
			errorText = errorText + "The email address you have entered appears to be invalid.\n";
			form.existingEmail.focus();
		}
	}
	else 
	{
		if (emailAddress.length == 0)
		{
			errorText = errorText + "You must enter a valid email address\n";
			form.existingEmail.focus();
		}
	}
	if (errorText.length != 0)
	{
		alert(errorText);
	}
	else
	{
		form.submit();
	}
}

function validateAccountMessage(form){
	var accountMessage;
	accountMessage = form.txtMessage.value;
	
	if(accountMessage.length <= 0){
		alert("Please enter an account message before submitting the form.");
	}
	else{
		form.submit();
	}
}

/*
function validateAccountUsage(){	
	if(docForm.chkUsage.checked != true){
		alert("If you would like to receive monthly account statistics, please check the box on the form before submitting.");
	}
	else{
		docForm.submit();
	}
}
*/

function validateManageUsers(form){
	var numSelected;
	//initial value
	numSelected = 0
	for(var i=0; i<form.elements.length; i++){
		if(form.elements[i].type == "checkbox"){
			if(form.elements[i].checked == true){
				numSelected += 1;
			}
		}
	}
	if(numSelected > 0){
		if(numSelected == 1){
			if(confirm("You are about to delete " + numSelected + " user from this contract.\nAre you sure you want to continue?")){
				form.submit();
			} 
		}
		else{
			if(numSelected > 1){
				if(confirm("You are about to delete " + numSelected + " users from this contract.\nAre you sure you want to continue?")){
					form.submit();
				} 
			}
		}
	}
	else{
		alert("If you would like to delete a user, you must select at least one user from the list.");
	}
}

// This function is used to validate the Search Form when the image or the GO link is pressed
// have the function below because with only ONE <input> pressing ENTER ALWAYS submits!
function validateSearch(form, url)
{
	var searchPhrase;
	var errorText;
	errorText = "";
	searchPhrase = form.keywords.value;
	
	if(searchPhrase.length < 2)
	{
		alert("Your search phrase should be at least 2 characters long.");		
	}
	else
	{
		if (url == '')
		{
			form.submit();
		}
		else
		{
			var obj = form.cmbQuickType;
			var indexSelected = obj.selectedIndex;
			if (obj[indexSelected].value == 'knowledgecenter')
			{
				document.location.href = url + 'kc/search/?keywords=' + URLEncode(form.keywords.value) + '&content=sect1'; 
			}
			else
				form.submit();
		}
	}
	
}

function validateWatchListSearch(form)
{
	var searchPhrase;
	var errorText;
	errorText = "";
	searchPhrase = form.txtSearch.value;
	
	if(searchPhrase.length < 2)
	{
		alert("Your search phrase should be at least 2 characters long.");		
	}
	else
	{
		form.submit();
	}
	
}

// this handles the ENTER key being pressed to submit the form
function validateSearchKeyPress(form, url)
{
	var searchPhrase;
	var errorText;
	errorText = "";
	searchPhrase = form.keywords.value;
	
	if(searchPhrase.length < 2)
	{
		alert("Your search phrase should be at least 2 characters long.");		
		return(false);
	}
	else
	{
		if (url == '')
		{
			//form.submit();
			return(true);
		}
		else
		{
			var obj = form.cmbQuickType;
			var indexSelected = obj.selectedIndex;
			if (obj[indexSelected].value == 'knowledgecenter')
			{		
				url += 	'kc/search/?keywords=' + URLEncode(form.keywords.value) + '&content=sect1';			
				document.location.href = url;			
				return(false);
			}
			
			return(true);
		}
	}
	
}

function validateMailFriend(form){
	var senderEmail;
	var receiverEmail;
	var errorMessage;
	
	errorMessage = "";
	senderEmail = form.txtSenderEmail.value;
	receiverEmail = form.txtRecepientEmail.value;
	
	//Sender's email
	if(senderEmail.length <= 0){
		errorMessage = errorMessage + "Please enter your email address. \n";
	}
	else{
		if (checkEmail(senderEmail) == false){
			errorMessage = errorMessage + "The sender email address you have entered appears to be invalid. \n";
		}
	}
	//Recepient's email
	if(receiverEmail.length <= 0){
		errorMessage = errorMessage + "Please enter the recepient's email address. \n";
	}
	else{
		if (checkEmail(receiverEmail) == false){
			errorMessage = errorMessage + "The recepient email address you have entered appears to be invalid. \n";
		}
	}
	//Decide whether to submit or not
	if (errorMessage.length > 0){
		alert(errorMessage);
	}
	else{
		form.submit();
	}
}



function validateCallBack(form){
	var name;
	var telephone;
	
	var errorMessage;
	
	errorMessage = "";

	name = form.name.value;
	if(name.length <= 0){
		errorMessage = errorMessage + "Please enter your name. \n";
	}
	
	email = form.email.value;
		if(email.length <= 0){
			errorMessage = errorMessage + "Please enter your email. \n";
	}
	
	
	telephone = form.telephone.value;
		if(telephone.length <= 0){
			errorMessage = errorMessage + "Please enter your telephone number. \n";
	}

	//Decide whether to submit or not
	if (errorMessage.length > 0){
		alert(errorMessage);
	}
	else{
		form.submit();
	}	
}



function validateContactUs(form){
	var title;
	var firstName;
	var surname;
	var jobFunction;
	var company;
	var country;
	var telephone;
	var email;
	var contactMethod;
	var message;
	var errorMessage;
	
	errorMessage = "";

	firstName = form.txtFirstName.value;
	if(firstName.length <= 0){
		errorMessage = errorMessage + "Please enter your first name. \n";
	}

	surname = form.txtSurname.value;
	if(surname.length <= 0){
		errorMessage = errorMessage + "Please enter your surname. \n";
	}

	if (form.cmbJobFunction.selectedIndex == 0) { //note checking for first item in drop-down list which will always be blank
		errorMessage = errorMessage + "Please select a job function from the dropdown list. \n";
	}
	else {
		jobFunction = form.cmbJobFunction.options[form.cmbJobFunction.selectedIndex].value; // jobFunction = form.cmbJobFunction.value;
	}

	company = form.txtCompany.value;
	if(company.length <= 0){
		errorMessage = errorMessage + "Please enter your company name. \n";
	}

	if (form.cmbCountry.selectedIndex == -1) {
		errorMessage = errorMessage + "Please select a country from the dropdown list. \n";
	}
	else {
		country = form.cmbCountry.options[form.cmbCountry.selectedIndex].value; // country = form.cmbCountry.value;
	}

	telephone = form.txtTelephone.value;

	email = form.txtEmail.value;

	contactMethod = "";
    for (i=0; i<form.radContactMethod.length; i++){
		if (form.radContactMethod[i].checked){
           contactMethod = form.radContactMethod[i].value;
		}
	}

	//contact method
	if(contactMethod.length <= 0){
		errorMessage = errorMessage + "Please select a contact method. \n";
	}
	else{
		if(contactMethod == "Email"){
			if(email.length <= 0){
				errorMessage = errorMessage + "You have chosen email as your prefered contact method, therefore, please enter your email. \n";
			}
		}
		if(contactMethod == "Phone"){
			if(telephone.length <= 0){
				errorMessage = errorMessage + "You have chosen phone as your prefered contact method, therefore, please enter your phone number. \n";
			}
		}				
	}
	//Check for validity of email (only if an email address is submitted)
	if(email.length > 0){
		if (checkEmail(email) == false){
			errorMessage = errorMessage + "The email address you have entered appears to be invalid. \n";
		}
	}
	//Decide whether to submit or not
	if (errorMessage.length > 0){
		alert(errorMessage);
	}
	else{
		form.submit();
	}	
}



function validateTrialCentre(form){
	var title;
	var firstName;
	var surname;
	var jobFunction;
	var company;
	var address1;
	var city;
	var county;
	var postcode;
	var country;
	var telephone;
	var email;
	var contactMethod;
	var message;
	var errorMessage;
	
	errorMessage = "";

	firstName = form.txtFirstName.value;
	if(firstName.length <= 0){
		errorMessage = errorMessage + "Please enter your first name. \n";
	}

	surname = form.txtSurname.value;
	if(surname.length <= 0){
		errorMessage = errorMessage + "Please enter your surname. \n";
	}

	if (form.cmbJobFunction.selectedIndex == 0) { //note checking for first item in drop-down list which will always be blank
		errorMessage = errorMessage + "Please select a job function from the dropdown list. \n";
	}
	else {
		jobFunction = form.cmbJobFunction.options[form.cmbJobFunction.selectedIndex].value; // jobFunction = form.cmbJobFunction.value;
	}

	address1 = form.txtAddress1.value;
	if(address1.length <= 0){
		errorMessage = errorMessage + "Please enter your address. \n";
	}

	city = form.txtCity.value;
	if(city.length <= 0){
		errorMessage = errorMessage + "Please enter your city. \n";
	}

	county = form.txtCounty.value;
	if(county.length <= 0){
		errorMessage = errorMessage + "Please enter your county. \n";
	}

	postcode = form.txtPostcode.value;
	if(postcode.length <= 0){
		errorMessage = errorMessage + "Please enter your postcode. \n";
	}

	company = form.txtCompany.value;
	if(company.length <= 0){
		errorMessage = errorMessage + "Please enter your company name. \n";
	}

	if (form.cmbCountry.selectedIndex == -1) {
		errorMessage = errorMessage + "Please select a country from the dropdown list. \n";
	}
	else {
		country = form.cmbCountry.options[form.cmbCountry.selectedIndex].value; // country = form.cmbCountry.value;
	}

	telephone = form.txtTelephone.value;

	email = form.txtEmail.value;
	
	if (!form.termsConfirmation.checked){
	errorMessage = errorMessage + "Please ensure you have read our Terms and Conditions and checked the box to indicate this. \n";
	}

	contactMethod = "";
    for (i=0; i<form.radContactMethod.length; i++){
		if (form.radContactMethod[i].checked){
           contactMethod = form.radContactMethod[i].value;
		}
	}

	//contact method
	if(contactMethod.length <= 0){
		errorMessage = errorMessage + "Please select a contact method. \n";
	}
	
			if(email.length <= 0){
				errorMessage = errorMessage + "Please enter your email. \n";
			}
		
		
			if(telephone.length <= 0){
				errorMessage = errorMessage + "Please enter your phone number. \n";
			}
						
	
	//Check for validity of email (only if an email address is submitted)
	if(email.length > 0){
		if (checkEmail(email) == false){
			errorMessage = errorMessage + "The email address you have entered appears to be invalid. \n";
		}
	}
	//Decide whether to submit or not
	if (errorMessage.length > 0){
		alert(errorMessage);
	}
	else{
		form.submit();
	}	
}





// This function creates a popup window with set properties
function CreatePopUp(target,name,w,h,scroll,loc,stat,menu,tool,pos,res)
{
    var LeftPos = 50
    var TopPos = 50
    var objWin;

    if(pos=="center")
    {
        LeftPos=(screen.width)?(screen.width-w)/2:100;
        TopPos=(screen.height)?(screen.height-h)/2:100;
    }
    var settings='width='+w+',height='+h+',top='+TopPos+',left='+LeftPos+',scrollbars='+scroll+',location='+loc+',directories=no,status='+stat+',menubar='+menu+',toolbar='+tool+',resizable='+res;

    objWin = window.open(target,name,settings);
    if (objWin) objWin.focus();
    return objWin;
}

// This function launches a pop-up to display the mail a friend page
function launchMailFriend(refererURL)
{
    winPopUp = CreatePopUp('/mailfriend/index.asp?url=' + refererURL,'new',412,350,'no','no','no','no','no','center','no');
}

// This function launches a pop-up to display the page for emailing clippings
function launchEmailClipping(pid, clipGUID, type, clipType, clipTitle, clipComment)
{
    winPopUp = CreatePopUp('/kc/clippings/email.asp?pid=' + pid + '&clipGUID=' + clipGUID + '&type=' + type + '&clipType=' + clipType + '&title=' + clipTitle + '&clipComment=' + clipComment,'new',412,500,'no','no','no','no','no','center','no');
}

function validateEmailClippings(form){
	var senderEmail;
	var receiverEmail;
	var errorMessage;
	var numOfAts;
	var numOfSemiColons;
	var arrEmails;
	
	errorMessage = "";
	numOfAts = 0;
	numOfSemiColons = 0;
	senderEmail = form.txtSenderEmail.value;
	receiverEmail = form.txtRecepientEmail.value;
	
	//Sender's email
	if(senderEmail.length <= 0){
		errorMessage = errorMessage + "Please enter your email address. \n";
	}
	else{
		if (checkEmail(senderEmail) == false){
			errorMessage = errorMessage + "The sender email address you have entered appears to be invalid. \n";
		}
	}
	//Recepient's email
	if(receiverEmail.length <= 0){
		errorMessage = errorMessage + "Please enter the recepients' email address(s). \n";
	}
	else{
		//First check whether the user has entered more than one email
		for(var i=0; i<receiverEmail.length; i++){
			if(receiverEmail.charAt(i) == "@"){
				numOfAts += 1;
			}
		}
		//If it is only one email address
		if(numOfAts == 1){
			//The user has entered only one email address so check its validity
			if (checkEmail(receiverEmail) == false){
				errorMessage = errorMessage + "The recepient email address you have entered appears to be invalid. \n";
			}		
		}
		//If the user has entered more than one email check whether they have seperated them by semicolons or not
		if(numOfAts > 1 && numOfAts < 11){
			for(var j=0; j<receiverEmail.length; j++){
				if(receiverEmail.charAt(j) == ";"){
					numOfSemiColons += 1;
				}
			}
			//The number of semicolons should be one less than the number of @. If not error
			if(numOfSemiColons = (numOfAts - 1)){
				//Enter the email addresses into an array
				arrEmails = receiverEmail.split(";");
				//Now loop through the array checking each email address for validity
				for(var n=0; n<(arrEmails.length - 1); n++){
					if(checkEmail(arrEmails[n]) == false){
						errorMessage = errorMessage + "The recepient email address, " + arrEmails[n] + " appears to be invalid. \n";	
					}
				}
			}
			else{
				errorMessage = errorMessage + "You should seperate the recepient email addresses using semicolons (;), not after the last address though. \n";	
			}
		}
		//The user has entered more than 10 email address so error
		if (numOfAts > 10){
			errorMessage = errorMessage + "It appears that you are attempting to email this clipping to more than 10 people. The maximum number of email addresses allowed are 10. \n";
		}
	}
	//Decide whether to submit or not
	if (errorMessage.length > 0){
		alert(errorMessage);
	}
	else{
		form.submit();
	}
}

function checkForSpaces(sThing)
{
    if (sThing.indexOf(' ') == -1 )
    {
        return false;
    }
    else
    {
        return true;
    }
}

function checkEmail(emailAddress){
	//var filter = /^[\w\.]+@{1}[\w\.]+$/
	
	//if (filter.test(emailAddress)){
		return true;
	//}
	//else{
	//	return false;
	//}
}

// checks the Edit My Profile Form for errors
function validateEditMyProfile(form)
{
	var title;
	var firstName;
	var lastName;
	var jobFunction;
	var company;
	var companyType;
	var address;
	var town;
	var postCode;
	var country;
	var email;
	var verifyEmail;
	var marketingInfo;
	var errorText;
	errorText = ""
	
	form.title.options[form.title.selectedIndex].value;
	
	/*
	Ensure that <SELECT> element validation work with NETSCAPE 4.x
	*/
	
	if (form.title.selectedIndex == -1) {
		errorText = errorText + "Please enter a Title\n";
		form.title.focus();
	}
	else {
		title = form.title.options[form.title.selectedIndex].value; //form.title.value;
	}
	
	firstName = form.firstName.value;

	if (firstName.length == 0)
	{
		errorText = errorText + "Please enter your First name\n";
		form.firstName.focus();
	}

	lastName = form.lastName.value;
	if (lastName.length == 0)
	{
		errorText = errorText + "Please enter your Last name\n";
		form.lastName.focus();
	}

	if (form.jobFunction.selectedIndex == -1) {	
		errorText = errorText + "Please enter your Job Function\n";
		form.jobFunction.focus();
	}
	else {
		jobFunction = form.jobFunction.options[form.jobFunction.selectedIndex].value; //form.jobFunction.value;
	}

	company = form.company.value;
	if (company.length == 0)
	{
		errorText = errorText + "Please enter your Company name\n";
		form.company.focus();
	}

	if (form.companyType.selectedIndex == -1)
	{
		errorText = errorText + "Please enter your Company type\n";
		form.companyType.focus();
	}
	else {
		companyType = form.companyType.options[form.companyType.selectedIndex].value  //form.companyType.value;
	}
		
	address = form.address.value;
	if (address.length == 0)
	{
		errorText = errorText + "Please enter your Address\n";
		form.address.focus();
	}
	
	town = form.city.value;
	if (town.length == 0)
	{
		errorText = errorText + "Please enter your Town/City\n";
		form.city.focus();
	}
	
	postCode = form.postCode.value;
	if (postCode.length == 0)
	{
		errorText = errorText + "Please enter your Postal/Zip Code\n";
		form.postCode.focus();
	}
	
	if (form.country.selectedIndex == -1)
	{
		errorText = errorText + "Please enter a Country\n";
		form.country.focus();
	}
	else {
		country = form.country.options[form.country.selectedIndex].value //form.country.value;	
	}
	
	email = form.email.value;
	
	verifyEmail = form.verifyEmail.value;
	
	if (email.length == 0)
	{
		errorText = errorText + "Please enter an Email address\n";
		form.email.focus();
	}
	else
	{
		if (checkEmail(email) == false) 
		{
			errorText = errorText + "Please enter a valid email address\n";
			form.email.focus();
		}
	}
	if (verifyEmail.length == 0)
	{
		errorText = errorText + "Please enter a Verify Email address\n";
		form.verifyEmail.focus();
	}
	else
	{
		if (checkEmail(verifyEmail) == false) 
		{
			errorText = errorText + "Please enter a valid Verify email address\n";
			form.verifyEmail.focus();
		}
	}
	if (email != verifyEmail)
	{
		errorText = errorText + "Your email addresses must match\n";
		form.email.focus();
	}

	marketingInfo = form.marketingInfo.value;
	
	if (errorText.length != 0)
	{
		alert(errorText);
	}
	else
	{
		form.submit();
	}
		
}

// validates the Change Password Form - for Edit My Profile
function validateProfileChangePass(form)
{
	var username;
	var oldPassword;
	var newPassword;
	var verifyNewPassword;
	var errorText;
	errorText = "";
	
	username = form.username.value;
	oldPassword = form.oldPassword.value;
	newPassword = form.newPassword.value;
	verifyNewPassword = form.verifyNewPassword.value;
	
	if (username.length <= 0)
	{
		errorText = errorText + "You must enter your username\n";
		form.username.focus();
	}
	if (oldPassword.length < 5)
	{
		errorText = errorText + "Your old password must be at least 5 characters\n";
		form.oldPassword.focus();
	}
	if (newPassword.length < 5)
	{
		errorText = errorText + "Your new password must be at least 5 characters\n";
		form.newPassword.focus();
	}
	else
	{
		if (newPassword.length > 15)
		{
			errorText = errorText + "Your new password must be 15 characters or less\n";
			form.newPassword.focus();
		}
	}
	if (verifyNewPassword.length < 5)
	{
		errorText = errorText + "Your verify password must be at least 5 characters\n";
		form.verifyNewPassword.focus();
	}
	else
	{
		if (verifyNewPassword.length > 15)
		{
			errorText = errorText + "Your verify password must be 15 characters or less\n";
			form.verifyNewPassword.focus();
		}
	}
	if (newPassword != verifyNewPassword)
	{
		errorText = errorText + "Your new password must be the same as your verify password\n";
		form.newPassword.focus();
	}
	if (newPassword == oldPassword)
	{
		errorText = errorText + "Your new password cannot be the same as your old password\n";
		form.newPassword.focus();
	}
	
	if (errorText.length != 0)
	{
		alert(errorText);
	}
	else
	{
		form.submit();
	}
	
}

// validates the Subscription Purchase Form
// If hidden form value (checkBillingCode) = 1, then a billingCode has been passed - check 0-length
// check that the selectedOption is not the default - "Please Select.."
function subscriptionPurchase(subscriptionPurchaseForm)
{
	var checkBillingCode;
	var billingCode;
	var errorText;
	errorText = "";
	
	checkBillingCode = subscriptionPurchaseForm.checkBillingCode.value;
	
	if (subscriptionPurchaseForm.chosenCreditLine.selectedIndex == 0)
	{
		errorText = errorText + "Please choose a Subscription to purchase this research\n";
	}
	
	if (checkBillingCode == 1)
	{
		billingCode = subscriptionPurchaseForm.billingCode.value;
		if (billingCode.length == 0) 
		{
			errorText = errorText + "You must provide a billing code for this purchase\n";
		}
	}
	
	if (errorText.length != 0)
	{
		alert(errorText);
	}
	else
	{
		subscriptionPurchaseForm.submit();
	}
	
}

function confirmSavedSearchDeletion(){
	if(confirm("You are about to delete a saved search query.\nAre you sure you want to continue?")){
		return true;
	}
}

function validateSaveSearch(form){
	var searchDescription;
	searchDescription = form.txtSearchDescription.value;
	
	if(searchDescription.length <= 0){
		alert("Please enter a descriptive word/phrase for your search.");
	}
	else{
		form.submit();
	}
}

function updateEmailAlertNewsCheckbox(){
	var newsOption;
	
	newsOption = docForm.cmbNews.value;
	if(newsOption == 0){
		docForm.chkNews.checked = false;
	}
	else{
		docForm.chkNews.checked = true;	
	}
}

function updateEmailAlertNewsDropDown(){
	var newsCheckbox;
	
	if(docForm.chkNews.checked == true){
		newsCheckbox = "on";
	}
	else{
		newsCheckbox = "off";	
	}	
	if(newsCheckbox == "off"){
		docForm.cmbNews.options[0].selected = true;
	}
}

function validateEmailAlert(form){
	var newsOption;
	
	newsOption = form.cmbNews.value;
	if(newsOption == 0 && form.chkNews.checked == true){
		alert("You have selected to receive email alerts for news and comments that match your watchlist.\nHowever you have not selected how frequently you wish to receive these emails.\nPlease use the drop-down list on the form to indicate how frequently you wish to receive these emails.");
	}
	else{
		form.submit();
	}
}

// validates the Credit Card Purchase Form
function basicCCCheck(form)
{
	var cardNumber;
	var expiryDate;
	var cv2Number;
	
	var errorText;
	var errorMessage;
	var paymenttype		
	errorMessage = "";
	
	cardNumber = form.cardno.value;
	expiryDate = form.cardexpire.value;
	cv2Number = form.seccode.value;
	
	
	for (i=0; i<form.paymenttype.length; i++){
			if (form.paymenttype[i].checked){
	           paymenttype = form.paymenttype[i].value;
			}
	}
	
	if (paymenttype == "creditcard") {
	
	

	
	
	
	
	if (form.cardtype.value == "")
	{
		errorMessage = errorMessage + "Please select a Card type\n";
	}
	if (cardNumber.length == 0)
	{
		errorMessage = errorMessage + "Please supply a Card number\n";
	}
	if ((expiryDate.length == 0) || (expiryDate.length != 5) || (expiryDate.substr(2,1) != '/') || (isNaN(expiryDate.substr(0,2))) || (isNaN(expiryDate.substr(3,2))))
	{
		errorMessage = errorMessage + "The Expiry date is invalid\n";
	}
	
	if (cv2Number.length == 0)
	{
		errorMessage = errorMessage + "Please supply a Security Code Number\n";
	}
	
	
	} else {
	
	
	if (form.invoiceno.value.length == 0)
		{
			errorMessage = errorMessage + "Please supply an invoice number\n";
	}
	
	}
	var title;
		var firstName;
		var surname;
		var jobFunction;
		var company;
		var country;
		var telephone;
		var email;
		var contactMethod;
		var message;
		
	
		firstName = form.txtFirstName.value;
		if(firstName.length <= 0){
			errorMessage = errorMessage + "Please enter your first name. \n";
		}
	
		surname = form.txtSurname.value;
		if(surname.length <= 0){
			errorMessage = errorMessage + "Please enter your surname. \n";
		}
	
		
		
		
		
		
		if (form.cmbJobFunction.value == '') { //note checking for first item in drop-down list which will always be blank
			errorMessage = errorMessage + "Please select a job function from the dropdown list. \n";
		}
		else {
			jobFunction = form.cmbJobFunction.value; // jobFunction = form.cmbJobFunction.value;
		}		
	
	
	
	
	
	
	
	
		company = form.txtCompany.value;
		if(company.length <= 0){
			errorMessage = errorMessage + "Please enter your company name. \n";
		}
	
		if (form.cmbCountry.selectedIndex == -1) {
			errorMessage = errorMessage + "Please select a country from the dropdown list. \n";
		}
		else {
			country = form.cmbCountry.options[form.cmbCountry.selectedIndex].value; // country = form.cmbCountry.value;
		}
	
		telephone = form.txtTelephone.value;
	
		email = form.txtEmail.value;
	
	
	
		//contact method
		
				if(email.length <= 0){
					errorMessage = errorMessage + "Please enter your email. \n";
				}
			
				if(telephone.length <= 0){
					errorMessage = errorMessage + "Please enter your phone number. \n";
				}
							
		
		//Check for validity of email 
		if(email.length > 0){
			if (checkEmail(email) == false){
				errorMessage = errorMessage + "The email address you have entered appears to be invalid. \n";
			}
	}
	
	
	
	
	
	if (errorMessage.length != 0)
	{
		alert(errorMessage);
	}
	else
	{
		form.submit();
	}
	
}


// validates the Credit Card Purchase Form
function basicNonCCCheck(form)
{

	
	var errorText;
	var errorMessage;	
	errorMessage = "";

	
	
	
	
	var title;
		var firstName;
		var surname;
		var jobFunction;
		var company;
		var country;
		var telephone;
		var email;
		var contactMethod;
		var message;
		
	
		firstName = form.txtFirstName.value;
		if(firstName.length <= 0){
			errorMessage = errorMessage + "Please enter your first name. \n";
		}
	
		surname = form.txtSurname.value;
		if(surname.length <= 0){
			errorMessage = errorMessage + "Please enter your surname. \n";
		}
	
		
		
		
		
		
		if (form.cmbJobFunction.value == '') { //note checking for first item in drop-down list which will always be blank
			errorMessage = errorMessage + "Please select a job function from the dropdown list. \n";
		}
		else {
			jobFunction = form.cmbJobFunction.value; // jobFunction = form.cmbJobFunction.value;
		}		
	
	
	
	
	
	
	
	
		company = form.txtCompany.value;
		if(company.length <= 0){
			errorMessage = errorMessage + "Please enter your company name. \n";
		}
	
		if (form.cmbCountry.selectedIndex == -1) {
			errorMessage = errorMessage + "Please select a country from the dropdown list. \n";
		}
		else {
			country = form.cmbCountry.options[form.cmbCountry.selectedIndex].value; // country = form.cmbCountry.value;
		}
	
		telephone = form.txtTelephone.value;
	
		email = form.txtEmail.value;
	
	
	
		//contact method
		
				if(email.length <= 0){
					errorMessage = errorMessage + "Please enter your email. \n";
				}
			
				if(telephone.length <= 0){
					errorMessage = errorMessage + "Please enter your phone number. \n";
				}
							
		
		//Check for validity of email 
		if(email.length > 0){
			if (checkEmail(email) == false){
				errorMessage = errorMessage + "The email address you have entered appears to be invalid. \n";
			}
	}
	
	
	
	
	
	if (errorMessage.length != 0)
	{
		alert(errorMessage);
	}
	else
	{
		form.submit();
	}
	
}




//function to make sure at least one character is entered
function checkBillingCode (viewCode)
{
	if (document.viewCode.authenticateViewCode.value == '')
	{
		alert('Please enter a View Code value');
	}
	else
	{
		document.viewCode.submit();
	}
}

// validates the Online Order Purchase Form
function invoiceOrderPurchase(form)
{
	var telephone;
	var confirmEmail;
	var storedEmail;
	
	var errorText;
	errorText = "";
	
	telephone = form.telephone.value;
	storedEmail = form.storedEmail.value;
	confirmEmail = form.confirmEmail.value;

	if (telephone.length == 0)
	{
		errorText = errorText + "Please supply a Contact telephone number\n";
	}
	if (confirmEmail.length == 0)
	{
		errorText = errorText + "Please supply a Confirmation of your email address\n";
	}
	
	if (storedEmail != confirmEmail)
	{
		errorText = errorText + "Please supply a matching email address\n";
	}
	
	if (errorText.length != 0)
	{
		alert(errorText);
	}
	else
	{
		form.submit();
	}
	
}

// Validates the registration form and submits if all valid
function validateRegistration() {
	var rtn = true;
	var frm = document.forms['vortal'];

	// If Netscape 4 only provide server side validation
	if (navigator.appName=='Netscape' && parseInt(navigator.appVersion) == 4)
	{
		frm.submit();
	}
	
	if (document.getElementById) {
		// Check username
		if (frm.Username.value.length == 0)
		{
			document.getElementById('errUsername').innerHTML = 'Please enter a username.';
			document.getElementById('errUsername').style.display = 'block';
			rtn = false;
		}
		else if (frm.Username.value.indexOf(' ') >= 0)
		{
			document.getElementById('errUsername').innerHTML = 'The username must not contain spaces.';
			document.getElementById('errUsername').style.display = 'block';
			rtn = false;
		}
		else
		{
			document.getElementById('errUsername').style.display = 'none';
			document.getElementById('errUsername').innerHTML = '';
		}
	
		// Check title
		if (frm.Title[frm.Title.selectedIndex].text.length == 0)
		{
			document.getElementById('errTitle').innerHTML = 'Please select a title.';
			document.getElementById('errTitle').style.display = 'block';
			rtn = false;
		}
		else
		{
			document.getElementById('errTitle').style.display = 'none';
			document.getElementById('errTitle').innerHTML = '';
		}
	
		// Check firstname
		if (frm.Forename.value.length == 0)
		{
			document.getElementById('errForename').innerHTML = 'Please enter a forename.';
			document.getElementById('errForename').style.display = 'block';
			rtn = false;
		}
		else if (frm.Forename.value.indexOf(' ') == 0)
		{
			document.getElementById('errForename').innerHTML = 'The forename must not start with a space.';
			document.getElementById('errForename').style.display = 'block';
			rtn = false;
		}
		else
		{
			document.getElementById('errForename').style.display = 'none';
			document.getElementById('errForename').innerHTML = '';
		}
	
		// Check surname
		if (frm.Surname.value.length == 0)
		{
			document.getElementById('errSurname').innerHTML = 'Please enter a surname.';
			document.getElementById('errSurname').style.display = 'block';
			rtn = false;
		}
		else if (frm.Surname.value.indexOf(' ') == 0)
		{
			document.getElementById('errSurname').innerHTML = 'The surname must not start with a space.';
			document.getElementById('errSurname').style.display = 'block';
			rtn = false;
		}
		else
		{
			document.getElementById('errSurname').style.display = 'none';
			document.getElementById('errSurname').innerHTML = '';
		}
	
		// Check job function
		if (frm.JobFunction[frm.JobFunction.selectedIndex].text.length == 0)
		{
			document.getElementById('errJobFunction').innerHTML = 'Please select a job function.';
			document.getElementById('errJobFunction').style.display = 'block';
			rtn = false;
		}
		else
		{
			document.getElementById('errJobFunction').style.display = 'none';
			document.getElementById('errJobFunction').innerHTML = '';
		}
	
		// Check email
		if (frm.Email.value.length == 0)
		{
			document.getElementById('errEmail').innerHTML = 'Please enter an email address.';
			document.getElementById('errEmail').style.display = 'block';
			rtn = false;
		}
		else if (frm.Email.value.indexOf(' ') == 0)
		{
			document.getElementById('errEmail').innerHTML = 'The email address must not start with a space.';
			document.getElementById('errEmail').style.display = 'block';
			rtn = false;
		}
		else
		{
			document.getElementById('errEmail').style.display = 'none';
			document.getElementById('errEmail').innerHTML = '';
		}
	
		// Check verify email
		if (frm.VerifyEmail.value.length == 0)
		{
			document.getElementById('errVerifyEmail').innerHTML = 'Please confirm the email address.';
			document.getElementById('errVerifyEmail').style.display = 'block';
			rtn = false;
		}
		else if (frm.VerifyEmail.value != frm.Email.value)
		{
			document.getElementById('errVerifyEmail').innerHTML = 'The email addresses do not match.';
			document.getElementById('errVerifyEmail').style.display = 'block';
			rtn = false;
		}
		else
		{
			document.getElementById('errVerifyEmail').style.display = 'none';
			document.getElementById('errVerifyEmail').innerHTML = '';
		}
		// Check job function
		if (frm.checkTC.checked == false)
		{
			document.getElementById('errVerifyTC').innerHTML = "Please confirm you have read, understood and agreed to Datamonitor's Terms and Conditions of Use.<br/><br/>";
			document.getElementById('errVerifyTC').style.display = 'block';
			rtn = false;
		}
		else
		{
			document.getElementById('errVerifyTC').style.display = 'none';
			document.getElementById('errVerifyTC').innerHTML = '';
		}
	}

	if (rtn)
	{
		frm.submit();
	}
}

// validates either the Financial Markets Events Register or the FM Panels Register form
function iASValidate(form, panel)
{
	var fullName
	var telephone;
	var confirmEmail;
	var storedEmail;
	var question;
	
	var errorText;
	errorText = "";
	
	fullName = form.confirmName.value;
	telephone = form.confirmPhone.value;
	storedEmail = form.storedEmail.value;
	confirmEmail = form.confirmEmail.value;
	
	if (fullName.length == 0)
	{
		errorText = errorText + "Please supply your Full Name\n";
	}
	if (telephone.length == 0)
	{
		errorText = errorText + "Please supply a Contact telephone number\n";
	}
	if (confirmEmail.length == 0)
	{
		errorText = errorText + "Please supply a Confirmation of your email address\n";
	}
	if (storedEmail != confirmEmail)
	{
		errorText = errorText + "Please supply a matching email address\n";
	}
	if (panel == 1)
	// we are validating a panels registration form
	{
		question = form.panelQuestion.value;
		if (question.length == 0)
		{
			errorText = errorText + "Please supply a Panels question\n";
		}
	}
	
	if (errorText.length != 0)
	{
		alert(errorText);
	}
	else
	{
		form.submit();
	}
	
}

// *************************
// KNOWLEDGE CENTER SPECIFIC
// *************************

function addTextControl(){
	if(!document.getElementById) return;	
	// text-sizing controls not added if javascript disabled (or IE 4/NS 4)
	document.write('<span class="label">Text size:</span> <a title="small" href="#" id="text_small" onclick="setTextSize(\'' + 'repbody' + '\', 12, this.id); return false;" style="font-size:12px"><b>A</b></a> <span style="color:#666">|</span> <a title="medium" href="#" id="text_med" onclick="setTextSize(\'' + 'repbody' + '\', 14, this.id); return false;" style="font-size:14px"><b>A</b></a> <span style="color:#666">|</span> <a title="large" href="#" id="text_large" onclick="setTextSize(\'' + 'repbody' + '\', 16, this.id); return false;" style="font-size:16px"><b>A</b></a> ');
	// set default size (12px)
	setTextSize('repbody', 12, 'text_small');
}			

function resetTextControls(){
	var c = new Array('text_small', 'text_med', 'text_large');
	for(var i=0; i<c.length; i++){
		var el = document.getElementById(c[i]);
		if(el) el.className='';
	}
}

function setTextSize(el_className, size, control_id){
	// resize text
	if(!document.getElementById) return;			

	var divs = document.getElementsByTagName("div");
	for(var i=0; i<divs.length; i++){
		var el = divs[i];
		if(el.className == el_className) el.style.fontSize = size + 'px';
	}
	
	resetTextControls();
					
	if(control_id){
		var el = document.getElementById(control_id);
		if(el) el.className = "current_state";
	}
}


function resizeFig(fig_id, small_file, large_file, control_id, image_location){
	
	// AD - Have taken out min/max height args as there is no need if we use component to resize during deployment
	
	// enlarge/reduce figures
	// args:
	// control_id = id of anchor for "Enlarge image"

	if(!document.getElementById){
		// redirect to large image file (IE4/NS4)
		window.location = image_location + large_file;
		return;
	}
	
	// toggle link text
	var l = document.getElementById(control_id);
	var ln = (l.innerHTML == 'Enlarge image')? 'Reduce image' : 'Enlarge image';
	l.innerHTML = ln;
	
	var img = document.images[fig_id];
	
	// toggle image
	var s = (img.src.substr(img.src.lastIndexOf('/')+1));
	var f = (s == small_file)? large_file : small_file ;

	if (l.innerHTML == 'Enlarge image')
	{
		img.src = image_location + "small_" +  f;
	}
	else
	{			
		img.src = image_location +  f;
	}
}

function setToolbarState(e, over){
	// sets rollover/rollout state of table/figure toolbar cells
	if(!document.getElementsByTagName) return;								
	
	var targ;						
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	
	// find parent td
	p = targ;
	while(p.tagName != "TD"){
		p = p.parentNode;
	}
	
	// set td state
	var bgcol;
	var bgpic;					
	if(over){																
		bgcol = "#CBCBFF";
		bgpic = "url(/images/toolbar_bg_over.gif)";																													
	} else {
		bgcol = "#DFE4ED";
		bgpic = "url(/images/toolbar_bg.gif)";										
	}								
	p.style.backgroundColor = bgcol;
	p.style.backgroundImage = bgpic;			
}

// function to handle the Browse Report Drop-Down for Interactive Reports
function interactiveBrowseDropDown(tocURL, reportURL, selectBox)
{	
	var browserType = navigator.appName;
	var section;
	var optionLength;
	
	// the value of what was selected in the drop-down
	section = selectBox.options[selectBox.selectedIndex].value;

	optionLength = section.length;
	if (optionLength > 0)
	{		
		if (section == 'TOC')
		{
			//redirect to TOC page
			document.location.href = tocURL;
		}
		else if (section == 'LOF')
		{
			//redirect to LOF page
			document.location.href = tocURL + '&table=lof';
		}
		else if (section == 'LOT')
		{
			//redirect to LOT page
			document.location.href = tocURL + '&table=lot';
		}
		else
		{
			if (browserType.indexOf("Netscape") == 0)
			{
				// we know they're using FireFox/Netscape etc
				document.location.href = reportURL + '&sect=' + section;
			}
			else
			{
				// we know they're using a MS-based browser - for some reason a &s character gets interpreted as a "section sign" causing
				// the pid to become invalid
				document.location.href = reportURL + '&amp;sect=' + section;
			}
		}
	}	
}

function getNumberOfCharactersTyped() 
{
	if(document.docForm.txtQuestion.value.length>400)
		document.docForm.txtQuestion.value = document.docForm.txtQuestion.value.substr(0,400)	
		
	var oDiv = document.getElementById('numOfCharacters');
	oDiv.innerHTML = "So far you have typed: " + document.forms["docForm"].txtQuestion.value.length + " characters.";
}

//This function validates the "Ask an Analyst" form
function validateAskAnalyst(form){
	var name;
	var email;
	var phone;
	var question;
	
	errorMessage = "";
	name = form.txtName.value;
	email = form.txtEmail.value;
	phone = form.txtTelephone.value;
	question = form.txtQuestion.value;
	
	//name
	if(name.length <= 0){
		errorMessage = errorMessage + "Please enter your full name. \n";
	}
	//email
	if(email.length <= 0){
		errorMessage = errorMessage + "Please enter your email address. \n";
	}
	else{
		if (checkEmail(email) == false){
			errorMessage = errorMessage + "The email address you have entered appears to be invalid. \n";
		}
	}
	//phone
	if(phone.length <= 0){
		errorMessage = errorMessage + "Please enter your telephone number. \n";
	}
	//question
	if(question.length <= 0){
		errorMessage = errorMessage + "Please enter your question or comment. \n";
	}
	else{
		if (question.length > 4000){
			errorMessage = errorMessage + "The question you have entered is more than the allowed 4000 characters. \n";
		}
	}	
	//Decide whether to submit or not
	if (errorMessage.length > 0){
		alert(errorMessage);
	}
	else{
		form.submit();
	}
}

// This function double-checks that the user wants to Approve an Interactive Report to be moved for Deployment
function displayApproveWarning(form)
{
	if(confirm("You are about to Approve this Interactive Report for deployment to www.datamonitor.com\nAre you sure you want to continue?"))
	{
		form.submit();
	}				
}

// This function launches a pop-up to display a progress bar while some longer-running-than-usual process is performed
function openProgressBarPopUp(target) 
{
    winPopUp = CreatePopUp(target,'new',412,225,'no','no','no','no','no','center','no');
}

// This function launches a pop-up to display the Ask an analyst from a specific Section of an Interactive Report
function openAnalystPopUp(page, pid, kc, sectionNumberTitle, type, news)
{
    winPopUp = CreatePopUp(page + '?pid=' + pid + '&KC=' + kc + '&sectionNumberTitle=' + sectionNumberTitle + '&type=' + type + '&news=' + news,'new',412,450,'no','no','no','no','no','center','no');
}
// This function launches a pop-up to display the Clipping page for an Interactive Report
function openClippingPopUp(page, pid, clipGUID, type, clipType, clipChapterTitle, clipSectionTitle, clipPosition, clipBespokeTitle)
{
    winPopUp = CreatePopUp(page + '?pid=' + pid + '&clipGUID=' + clipGUID + '&type=' + type + '&clipType=' + clipType + '&chapterTitle=' + encodeURIComponent(clipChapterTitle) + '&sectionTitle=' + encodeURIComponent(clipSectionTitle) + '&clipPosition=' + clipPosition + '&bespokeTitle=' + encodeURIComponent(clipBespokeTitle),'new',412,500,'no','no','no','no','no','center','no');
}

// This function launches a pop-up to edit an existing clipping
function openEditClippingPopUp(page, clipGUID)
{
    winPopUp = CreatePopUp(page + '&clipGUID=' + clipGUID,'new',412,500,'no','no','no','no','no','center','no');
}

function deleteClipping(formName)
{
	if(confirm("Are you sure you want to permanently remove this clipping?"))
	{
		if (document.getElementById)
		{
			var form = document.getElementById(formName);
			if (form) form.submit();
		}
	}
}

//This function validates the "Ask an Analyst" form
function validateClipForm(formId){
	var title;
	var errorMessage;
	var form = document.getElementById(formId);
	
	errorMessage = "";
	title = form.txtClipTitle.value;
	
	//clip title
	if(title.length <= 0)
	{
		errorMessage = errorMessage + "Please enter a Title for your Clipping. \n";
	}

	//Decide whether to submit or not
	if (errorMessage.length > 0)
	{
		alert(errorMessage);
	}
	else
	{
		form.submit();
	}
}

// This function displays information based on what the user chooses on the Task Pane of Computer Wire reports in the knowledge centre.
function ChangeOutputToCWTaskPaneSelection()
{
	var elem = document.getElementById('taskPaneDownloadOptions');
	var elem1 = document.getElementById('taskPaneCompaniesMentioned');
	if (!elem) { return false; }	
	if(elem.className == 'show')
	{
		elem.className = 'hide';
		elem1.className = 'show';
	}
	else if (elem.className == 'hide')
	{
		elem.className = 'show';
		elem1.className = 'hide';
	}
}

// This function displays information based on what the user chooses on the Task Pane.
function changeTaskPaneSelection(select)
{
	var div;
	
	if (document.getElementById && document.createTextNode)
	{
		for (i = 0; i < select.options.length; i++)
		{
			div = document.getElementById(select.options[i].value);
			if (div)
			{
				if (i == select.selectedIndex)
				{
					div.className = 'show';
				}
				else
				{
					div.className = 'hide';
				}
			}
		}
	}
}

// Initialises the visible content within the task pane
function initialiseTaskPane(taskPaneID)
{
	if (document.getElementById && document.createTextNode)
	{
		var select = document.getElementById(taskPaneID);
		if (select)
			changeTaskPaneSelection(select);
	}
}

function initialiseInteractiveReportTaskPane(taskPaneSelectID)
{
	if (document.getElementById && document.createTextNode)
	{
		var select = document.getElementById(taskPaneSelectID);
		if (select)
			changeInteractiveReportTaskPaneSelection(select);
	}
}

function changeInteractiveReportTaskPaneSelection(select)
{
	var url;
	
	if (document.getElementById && document.createTextNode)
	{
		for (i = 0; i < select.options.length; i++)
		{
			url = select.options[i].value;
			if (url)
				if (i == select.selectedIndex)
					window.open(url,'taskPaneIFrame');
		}
	}
}

//------------------------------------------------------------------------------------
//PBuilder/RBuilder functions - Start
//------------------------------------------------------------------------------------
function validateBuilderForm(form,op,type){
	var senderEmail;
	var receiverEmail;
	var errorMessage;
	var numOfAts;
	var numOfSemiColons;
	var arrEmails;
	var compositeTitle;
	var builderType;
	
	errorMessage = "";
	numOfAts = 0;
	numOfSemiColons = 0;
	senderEmail = form.senderEmail.value;
	receiverEmail = form.targetEmailAddresses.value;
	
	if (type == 1)
	{
		builderType = "report";
	}
	else
	{
		builderType = "presentation";
	}
	
	
	// check to see if they have added a Title for their Presentation/Report - type 1 is ReportBuilder
	if (type == 1)
	{
		compositeTitle = form.compositeReportTitle.value;
		if (compositeTitle.length <= 0)
		{
			errorMessage = errorMessage + "Please enter a title for your report. \n";
		}	
	}
	else
	{
		compositeTitle = form.compositePresentationTitle.value;
		if (compositeTitle.length <= 0)
		{
			errorMessage = errorMessage + "Please enter a title for your presentation. \n";
		}	
	}
	
	//If we are submitting the form for saving the presentation...
	if(op == "save"){
	
		//Decide whether to submit or not
		if (errorMessage.length > 0)
		{
			alert(errorMessage);
		}
		else
		{
			// add a step value to the page
			form.step.value = "step3.asp";
			//Clear the email and message textboxes
			form.senderEmail.value = "";
			form.targetEmailAddresses.value = "";
			form.emailMessageBody.value = "";
			//Set the value of the hidden field to "save"
			form.op.value = "save";
			//Select all the items in the listbox before submitting the form
			for(var n=0; n<document.docForm.clippingID.options.length; n++){
				document.docForm.clippingID.options[n].selected = true;
			}
			//Submit the form
			form.submit();
		}
	}
	//If we are submitting the form for saving and emailing the presentation then validate the form entries...
	else{
		//Sender's email
		if(senderEmail.length <= 0){
			errorMessage = errorMessage + "Please enter your email address. \n";
		}
		else{
			if (checkEmail(senderEmail) == false){
				errorMessage = errorMessage + "The sender email address you have entered appears to be invalid. \n";
			}
		}
		//Recepient's email
		if(receiverEmail.length <= 0){
			errorMessage = errorMessage + "Please enter the destination email address(es) for your " + builderType + ". \n";
		}
		else{
			//First check whether the user has entered more than one email
			for(var i=0; i<receiverEmail.length; i++){
				if(receiverEmail.charAt(i) == "@"){
					numOfAts += 1;
				}
			}
			//If it is only one email address
			if(numOfAts == 1){
				//The user has entered only one email address so check its validity
				if(checkEmail(receiverEmail) == false){
					errorMessage = errorMessage + "The destination email address you have entered appears to be invalid. \n";
				}		
			}
			//If the user has entered more than one email check whether they have seperated them by semicolons or not
			if(numOfAts > 1 && numOfAts < 11){
				for(var j=0; j<receiverEmail.length; j++){
					if(receiverEmail.charAt(j) == ";"){
						numOfSemiColons += 1;
					}
				}
				//The number of semicolons should be one less than the number of @. If not error
				if(numOfSemiColons = (numOfAts - 1)){
					//Enter the email addresses into an array
					arrEmails = receiverEmail.split(";");
					//Now loop through the array checking each email address for validity
					for(var k=0; k<(arrEmails.length - 1); k++){
						if(checkEmail(arrEmails[k]) == false){
							errorMessage = errorMessage + "The destination email address, " + arrEmails[k] + " appears to be invalid. \n";
						}
					}
				}
				else{
					errorMessage = errorMessage + "You should seperate the destination email addresses using semicolons (;). \n";	
				}
			}
			//The user has entered more than 10 email address so error
			if(numOfAts > 10){
				errorMessage = errorMessage + "It appears that you are attempting to email this " + builderType + " to more than 10 people. The maximum number of email addresses allowed are 10. \n";
			}
		}
		//Decide whether to submit or not
		if (errorMessage.length > 0){
			alert(errorMessage);
		}
		else{
			//Select all the items in the listbox before submitting the form
			for(var m=0; m<document.docForm.clippingID.options.length; m++){
				document.docForm.clippingID.options[m].selected = true;
			}
			
			// add a step value to the page
			form.step.value = "step3.asp";
			//Set the value of the hidden field to "email"
			form.op.value = "email";
			//Submit the form
			form.submit();
		}
	}
}

function checkMessageTextbox(textbox){
	if(textbox.value == ""){
		textbox.value = "Enter your message here...";
	}
	else{
		if(textbox.value == "Enter your message here..."){
			textbox.value = "";
		}
	}
}
	
function upOne() {
    if(document.getElementById) {
        var box = document.getElementById('clippingID');
        if(box) {
            var index = box.selectedIndex;
           	if (index > 0) {
          		var elOptNew = document.createElement('option');
          		var elOptOld = box.options[index];
          		elOptNew.text = elOptOld.text;
          		elOptNew.value = elOptOld.value;
          		elOptNew.title = elOptOld.text;
         		  elOptOld = box.options[index-1];
              try {
          			box.add(elOptNew, elOptOld); // standards compliant; doesn't work in IE
          		}
          		catch(ex) {
          			box.add(elOptNew, box.selectedIndex-1); // IE only
          		}
         		  box.remove(index + 1);
           		box.selectedIndex = index-1;
          	}
        }
    }
}
	
function downOne() {
    if(document.getElementById) {
        var box = document.getElementById('clippingID');
        if(box) {
            var index = box.selectedIndex;
           	if ((index >= 0)&&(index < box.options.length-1)) {
          		var elOptNew = document.createElement('option');
          		var elOptOld = box.options[index];
          		elOptNew.text = elOptOld.text;
          		elOptNew.value = elOptOld.value;
          		elOptNew.title = elOptOld.text;
         		  elOptOld = box.options[index+2];
              try {
          			box.add(elOptNew, elOptOld); // standards compliant; doesn't work in IE
          		}
          		catch(ex) {
          			box.add(elOptNew, box.selectedIndex+2); // IE only
          		}
         		  box.remove(index);
           		box.selectedIndex = index+1;
          	}
        }
    }
}
	
function toTop() {
    if(document.getElementById) {
        var box = document.getElementById('clippingID');
        if(box) {
            var index = box.selectedIndex;
           	if (index > 0) {
          		var elOptNew = document.createElement('option');
          		var elOptOld = box.options[index];
          		elOptNew.text = elOptOld.text;
          		elOptNew.value = elOptOld.value;
          		elOptNew.title = elOptOld.text;
         		  box.remove(index);
         		  elOptOld = box.options[0];
              try {
          			box.add(elOptNew, elOptOld); // standards compliant; doesn't work in IE
          		}
          		catch(ex) {
          			box.add(elOptNew, 0); // IE only
          		}
           		box.selectedIndex = 0;
          	}
        }
    }
}
	
function toBottom() {
    if(document.getElementById) {
        var box = document.getElementById('clippingID');
        if(box) {
            var index = box.selectedIndex;
           	if (index < box.options.length-1) {
          		var elOptNew = document.createElement('option');
          		var elOptOld = box.options[index];
          		elOptNew.text = elOptOld.text;
          		elOptNew.value = elOptOld.value;
          		elOptNew.title = elOptOld.text;
         		  box.remove(index);
         		  elOptOld = box.options[box.options.length];
              try {
          			box.add(elOptNew, elOptOld); // standards compliant; doesn't work in IE
          		}
          		catch(ex) {
					box.add(elOptNew, box.options.length); // IE only 
          		}
           		box.selectedIndex = box.options.length-1;
          	}
        }
    }
}
//------------------------------------------------------------------------------------
//PBuilder functions - End
//------------------------------------------------------------------------------------