// dropdown select location change

function selsub(Url) {
  Url=document.subsites.sites[document.subsites.sites.selectedIndex].value;
  document.location = Url;
}

excludeUrls = Array(
              'http://cws.huginonline.com',
              'http://dominoext.novartis.com',
              'http://download.macromedia.com',
              'http://etrials.novartis.com',
              'http://gaia.world-television.com',
              'http://infra.novartis.com',
              'http://mfile.akamai.com',
              'http://nibr.novartis.com',
              'http://novcont05.eu.novartis.net',
              'http://qsm3.asp.quartal.com',
              'http://search.novartis.com',
              'http://services.choruscall.com',
              'http://streamstudio.unit.net',
              'http://streamstudio.world-television.com',
              'http://web.gnf.org',
              'http://www.acromegalyinfo.com',
              'http://www.adhdinfo.com',
              'http://www.ah.novartis.com',
              'http://www.ar.novartis.com',
              'http://www.at.novartis.com',
              'http://www.benefiber.com',
              'http://www.blt.ch',
              'http://www.chiron.com',
              'http://www.cibavision.com',
              'http://www.coartem.com',
              'http://www.comtan.com',
              'http://www.consumer-health.se.novartis.com',
              'http://www.consumerhealth.eg.novartis.com',
              'http://www.corporate-ir.net',
              'http://www.denavir.com',
              'http://www.deramaxx.novartis.us',
              'http://www.diovan.com',
              'http://www.diovan.info',
              'http://www.elidel.com',
              'http://www.enablex.com',
              'http://www.estradot.com',
              'http://www.excedrin.com',
              'http://www.exelon.com',
              'http://www.exjade.com',
              'http://www.famvir.com',
              'http://www.femara.com',
              'http://www.femarainfo.com',
              'http://www.fenistil.ch',
              'http://www.flea-info.com',
              'http://www.flycontrol.novartis.com',
              'http://www.fmi.ch',
              'http://www.foradil.com',
              'http://www.foradil.us',
              'http://www.fungalnailinfection.com',
              'http://www.gerber.com',
              'http://www.gleevec.com',
              'http://www.glivec.com',
              'http://www.global-hr.orientation.novartis.com',
              'http://www.habitrol.com',
              'http://www.hk.novartis.com',
              'http://www.hu.novartis.com',
              'http://www.id.novartis.com',
              'http://www.in.pharma.novartis.com',
              'http://www.international.myeczema.com',
              'http://www.jubilaeumsstiftung.novartis.com',
              'http://www.kerilotion.com',
              'http://www.lamisil.com',
              'http://www.lamisilat.com',
              'http://www.locations.novartis.com',
              'http://www.lotrel.com',
              'http://www.malariaandhealth.com',
              'http://www.mea.novartis.com',
              'http://www.miacalcin.com',
              'http://www.mycongresses.com',
              'http://www.nibr.novartis.com',
              'http://www.nicotinell.com',
              'http://www.nightanddaycontacts.com',
              'http://www.nitd.novartis.com',
              'http://www.novartis-consumer-health.ch',
              'http://www.novartis-consumerhealth.de',
              'http://www.novartis-recruiting.com:8080',
              'http://www.novartis-transplant.com',
              'http://www.novartis-vaccines.com',
              'http://www.novartis.at',
              'http://www.novartis.be',
              'http://www.novartis.ca',
              'http://www.novartis.ch',
              'http://www.novartis.co.jp',
              'http://www.novartis.co.kr',
              'http://www.novartis.co.uk',
              'http://www.novartis.com',
              'http://www1.novartis.com',
              'http://www.novartis.com.au',
              'http://www.novartis.com.br',
              'http://www.novartis.com.cn',
              'http://www.novartis.com.co',
              'http://www.novartis.com.mx',
              'http://www.novartis.com.tr',
              'http://www.novartis.cz',
              'http://www.novartis.de',
              'http://www.novartis.dk',
              'http://www.novartis.es',
              'http://www.novartis.fi',
              'http://www.novartis.fr',
              'http://www.novartis.gr',
              'http://www.novartis.is',
              'http://www.novartis.it',
              'http://www.novartis.nl',
              'http://www.novartis.no',
              'http://www.novartis.pl',
              'http://www.novartis.ru',
              'http://www.novartis.se',
              'http://www.novartisclinicaltrials.com',
              'http://www.novartisconsumerhealth.ca',
              'http://www.novartisconsumerhealth.es',
              'http://www.novartisconsumerhealth.nl',
              'http://www.novartisfound.org.uk',
              'http://www.novartisfoundation.com',
              'http://www.novartisnutrition.com',
              'http://www.novartisoncology.com',
              'http://www.novartisophthalmics.com',
              'http://www.novartisvaccines.com',
              'http://www.o2optix.com',
              'http://www.pharma.us.novartis.com',
              'http://www.prexige.com',
              'http://www.rescula.com',
              'http://www.ritalin.com',
              'http://www.sandostatin.com',
              'http://www.sandoz.com',
              'http://www.stalevo.com',
              'http://www.starlix.com',
              'http://www.tbdots.com',
              'http://www.tiamutin.com',
              'http://www.transplantsquare.com',
              'http://www.triaminic.com',
              'http://www.trileptal.com',
              'http://www.us.cibavision.com',
              'http://www.us.novartis.com',
              'http://www.us.novartisoncology.com',
              'http://www.us.novartisophthalmics.com',
              'http://www.us.sandostatin.com',
              'http://www.us.zometa.com',
              'http://www.venturefund.novartis.com',
              'http://www.visudyne.com',
              'http://www.vivelledot.com',
              'http://www.xolair.com',
              'http://www.zelmac.ch',
              'http://www.zelnorm.com',
              'http://www.zometa.com'
              );

// check form element values before submitting
// if all fields look good return true so that the form can be submitted
function CheckForm(theForm, fes) {
  // first check that all "required" fields are filled
  for (i = 0; i < theForm.elements.length; i++) {
    if (typeof(fes[theForm.elements[i].name]) == "undefined") {
      continue;
    }
    if (fes[theForm.elements[i].name].required == 1) {
      if (fes[theForm.elements[i].name].type == "text") {
//	    if (!checkString(theForm.elements[i],
//	                     theForm.elements[i].name, false))
        if (!checkString(theForm.elements[i], fes[theForm.elements[i].name].desc, false))
	  return false;
        } else if (fes[theForm.elements[i].name].type == "select") {
	  if (!checkRequiredSelect(theForm.elements[i], iSelectPrefix + fes[theForm.elements[i].name].desc+iSelectSuffix)) return false;
	} else if (fes[theForm.elements[i].name].type == "radio") {
          var radiochecked = theForm.elements[i].checked;
	  var radioname = theForm.elements[i].name;
	  var j = i+1;
          while (j < theForm.elements.length) {
	    if (theForm.elements[j].type == "radio" &&
	        theForm.elements[j].name == radioname) {
              if (!radiochecked) radiochecked = theForm.elements[j].checked;
	        j++;
	      } else
	        break;	// reached end of radio button sequence
	    }
	    if (!radiochecked)
	      return warnMustFill(theForm.elements[i], iRadioPrefix + fes[theForm.elements[i].name].desc+iRadioSuffix);
	    i = j  - 1;
	}
     }
  }

  // now check the contents of all fields that require tests
  for (i = 0; i < theForm.elements.length; i++) {
    if (typeof(fes[theForm.elements[i].name]) == "undefined") {
      continue;
    }
    if (fes[theForm.elements[i].name].ctype == "Alphabetic") {
      if (!checkAlphabetic(theForm.elements[i],
	  iPrefix + fes[theForm.elements[i].name].desc + iAlphabeticSuffix,
	  (fes[theForm.elements[i].name].required == 1) ? false : true))
        return false;
    } else if (fes[theForm.elements[i].name].ctype == "Alphanumeric") {
        if (!checkAlphanumeric(theForm.elements[i],
	    iPrefix + fes[theForm.elements[i].name].desc + iAlphanumericSuffix,
	    (fes[theForm.elements[i].name].required == 1) ? false : true))
          return false;
    } else if (fes[theForm.elements[i].name].ctype == "Number") {
        if (!checkNumber(theForm.elements[i],
	    iPrefix + fes[theForm.elements[i].name].desc + iNumberSuffix,
	    (fes[theForm.elements[i].name].required == 1) ? false : true))
	  return false;
    } else if (fes[theForm.elements[i].name].ctype == "Email") {
        if (!checkEmail(theForm.elements[i],
	    iPrefix + fes[theForm.elements[i].name].desc +
	    iEmailSuffix,(fes[theForm.elements[i].name].required == 1) ? false : true))
	  return false;
    } else if (fes[theForm.elements[i].name].ctype == "None") {

    }
  }

    //theForm.submitTime.value=new Date();;
    return true;
}

function formelement(req, typ, contentt, flddesc) {
  this.required = req;  	       // is this a required item?
  this.ctype = contentt;
        			       // is content numeric, alphabetic etc.
        			       // applies only to text item fields
        			       // possible values are "Alphabetic", "Number",
        			       //	"Alphanumeric", "Email", "None"
  this.type = typ;		       // what is the type of this item
        			       // "text", "select", "radio"
  this.desc = flddesc;  	       // descriptive string for item
  return this;
}


function textCounter(field, countfield, maxlimit) {
  if (field.value.length > maxlimit) // if too long...trim it!
  field.value = field.value.substring(0, maxlimit);
  // otherwise, update 'characters left' counter
  else
  countfield.value = maxlimit - field.value.length;
}

function textChecker(field, countfield, maxlimit) {
  if (field.value.length != maxlimit) // if too short...extend it!
  {
    field.value = field.value.substring(0, maxlimit);
    alert("Invalid Phone Number Please Re-enter a standard 10 Digit Number WITHOUT DASHES");
  }

  // otherwise, update 'characters left' counter
  else
  countfield.value = maxlimit - field.value.length;
}

function fncTestForm(pForm) {
    
    if (pForm.replyTo.value == "") {
        alert("Please include your email");
        pForm.replyTo.focus();
        return false;
        }
    
    if (pForm.replyTo.value.indexOf("@") == -1) {
        alert("Please include a proper email");
        pForm.replyTo.focus();
        return false;
        }
    
    if (pForm.firstName.value == "") {
        alert("Please include your first name");
        pForm.firstName.focus();
        return false;
        }
    
    if (pForm.lastName.value == "") {
        alert("Please include your last name");
        pForm.lastName.focus();
        return false;
        }
    
    if (pForm.phoneNumber.value == "") {
        alert("Please include your phone number");
        pForm.phoneNumber.focus();
        return false;
        }           
    
    if (pForm.message.value == "") {
        alert("Please include a message");
        pForm.message.focus();
        return false;
        }           
    return true;
}
		function checkform(of)
		{
		// Test if DOM is available and there is an element called required
			if(!document.getElementById || !document.createTextNode){return;}
			if(!document.getElementById('required')){return;}

		// Define error messages and split the required fields
			var errorID='errormsg';
			var errorClass='error'
			var errorMsg='Please enter or change the fields marked with ';
			var errorImg='/images/alert.gif';
			var errorAlt='Error';
			var errorTitle='This field has an error!';
			var reqfields=document.getElementById('required').value.split(',');

		// Cleanup old mess
			// if there is an old errormessage field, delete it
			if(document.getElementById(errorID))
			{
				var em=document.getElementById(errorID);
				em.parentNode.removeChild(em);
			}
			// remove old images and classes from the required fields
			for(var i=0;i<reqfields.length;i++)
			{
				var f=document.getElementById(reqfields[i]);
				if(!f){continue;}
				if(f.previousSibling && /img/i.test(f.previousSibling.nodeName))
				{
					f.parentNode.removeChild(f.previousSibling);
				}
				f.className='';
			}
		// loop over required fields
			for(var i=0;i<reqfields.length;i++)
			{
		// check if required field is there
				var f=document.getElementById(reqfields[i]);
				if(!f){continue;}
		// test if the required field has an error, 
		// according to its type
				switch(f.type.toLowerCase())
				{
					case 'text':
						if(f.value=='' && f.id!='replyTo'){cf_adderr(f)}							
		// email is a special field and needs checking
						if(f.id=='replyTo' && !cf_isEmailAddr(f.value)){cf_adderr(f)}							
					break;
					case 'textarea':
						if(f.value==''){cf_adderr(f)}							
					break;
					case 'checkbox':
						if(!f.checked){cf_adderr(f)}							
					break;
					case 'select-one':
						if(!f.selectedIndex && f.selectedIndex==0){cf_adderr(f)}							
					break;
				}
			}
			return !document.getElementById(errorID);

			/* Tool methods */
			function cf_adderr(o)
			{
				// create image, add to and colourise the error fields
				var errorIndicator=document.createElement('img');
				errorIndicator.alt=errorAlt;
				errorIndicator.className='errorPic';
				errorIndicator.src=errorImg;
				errorIndicator.title=errorTitle;
				o.className=errorClass;
				o.parentNode.insertBefore(errorIndicator,o);

			// Check if there is no error message
				if(!document.getElementById(errorID))
				{
				// create errormessage and insert before submit button
					var em=document.createElement('div');
					em.id=errorID;
					var newp=document.createElement('p');
					newp.appendChild(document.createTextNode(errorMsg))
					// clone and insert the error image
					newp.appendChild(errorIndicator.cloneNode(true));
					em.appendChild(newp);
					// find the submit button 
					for(var i=0;i<of.getElementsByTagName('input').length;i++)
					{
						if(/submit/i.test(of.getElementsByTagName('input')[i].type))
						{
							var sb=of.getElementsByTagName('input')[i];
							break;
						}
					}
					if(sb)
					{
						sb.parentNode.insertBefore(em,sb);
					}	
				} 
			}
			function cf_isEmailAddr(str) 
			{
			    return str.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/);
			}
		}			  
