/********************************* SETTINGS ***********************************/

/* sid is used for highlighting the actual menu-entry.
 */
var sid = null;
var xid = null;

/* set to true in case php is available on webserver
 * set to false if no php is available - javascript is then used to send
 * your formular per mail
 */
var php = false;

/********************************* FUNCTIONS **********************************/

function switchMenu (id) {
//  alert ('method called: switchMenu (' + id + ')');
  closeAll ();
  openMenu (id);
//  alert ('method called: openMenu (' + id + ')');
}

function centerHeading (id) {
  document.getElementById(id).style.textAlign = 'center';
}

function openMenu (id) {
//  alert ('method called: openMenu (' + id + ')');
  document.getElementById(id).style.position = 'static';
  document.getElementById(id).style.visibility = 'visible';
}

function closeMenu (id) {
//  alert ('method called: closeMenu (' + id + ')');
  document.getElementById(id).style.position = 'absolute';
  document.getElementById(id).style.visibility = 'hidden';
}

function closeAll () {
  closeMenu ('science');
  closeMenu ('products');
  closeMenu ('contact');
  closeMenu ('services');
}

function highLink(id) {
	if (xid != null) {
  		document.getElementById(xid).status = 'link';//style.color = '#004a90';
  	}	//zureucksetzen des alten items
  	document.getElementById(id).status = 'hover';//style.color = '#FF0000';
	xid = id;
  	//alert ('End: ' + id);
}

function openAll () {
  openMenu ('science');
  openMenu ('products');
  openMenu ('services');
  openMenu ('contact');
}

function highLight (id) {
//  alert ('Begin: ' + id);
  var str = id.src;
  if (sid != null) sid.src = sid.src.replace("red_", "blue_");
  id.src = str.replace("blue_", "red_");
  sid = id;
//  alert ('End: ' + id);
}

function highLightWell (id) {
  var str = id.src;
  if (sid != null) sid.src = sid.src.replace("active_", "normal_");
  id.src = str.replace("normal_", "active_");
  sid = id;
}

function switchImage (id, status) {
  /* status:
   * 0 ... change to blue
   * 1 ... change to red
   */
  // alert (id.src + '-' + sid);
  if (id != sid) {
    if (status == 0) {
     id.src = id.src.replace ("red_", "blue_");
    } else {
      id.src = id.src.replace ("blue_", "red_");
    }
  }
}

function switchWellButton (id, status) {
  /* status:
   * 0 ... change to normal
   * 1 ... change to active
   */
  // alert (id.src + '-' + sid);
  if (id != sid) {
    if (status == 0) {
     id.src = id.src.replace ("active_", "normal_");
    } else {
      id.src = id.src.replace ("normal_", "active_");
    }
  }
}

function createText () {
  var newLine = String.fromCharCode(0013); // Creates ASCII sequence for carriage return
  var id = document.reqinfo;
  var text = '';
  if (id.Name.value != '')      					{ text += 'Name:                ' + id.Name.value + newLine; }
  if (id.Title.value != '')     					{ text += 'Title:               ' + id.Title.value + newLine; }
  if (id.Company.value != '')   					{ text += 'Company/Institution: ' + id.Company.value + newLine; }
  if (id.Address.value != '')   					{ text += 'Address:             ' + id.Address.value + newLine; }
  if (id.Address2.value != '')  					{ text += 'Address (second line): ' + id.Address2.value + newLine; }
  if (id.ZipCode.value != '' || id.City.value != ''){ text += 'City, State, Zip:      ' + id.City.value + ', ' + id.State.value + '  ' + id.ZipCode.value + newLine; }
  if (id.Country.value != '')   					{ text += 'Country:             ' + id.Country.value + newLine; }
  if (id.Phone.value != '')     					{ text += 'Phone:               ' + id.Phone.value + newLine; }
  if (id.Fax.value != '')       					{ text += 'Fax:                 ' + id.Fax.value + newLine; }
  if (id.Email.value != '')     					{ text += 'Email:               ' + id.Email.value + newLine; }
                                  text += newLine + 'Interested in: ' + newLine;
  if (id.cb_software_trials.checked)				{ text += '  ImmunoSpot Software Trials ' + newLine; }
  if (id.cb_immunospot_4_academic.checked)          { text += '  ImmunoSpot Academic Software ' + newLine; }
  if (id.cb_immunospot_4_professional.checked)      { text += '  ImmunoSpot Professional Software ' + newLine; }
  if (id.cb_immunospot_double_color.checked)        { text += '  Professional ImmunoSpot Double-Color Software ' + newLine; }
  if (id.cb_immunoscan.checked)           			{ text += '  ImmunoScan: The Affordable High-Quality System ' + newLine; }
  if (id.cb_immunospot_s4.checked)           		{ text += '  ImmunoSpot Analyzer: The Professional Workstation' + newLine; }
  if (id.cb_immunospot_s4_uv.checked)           	{ text += '  ImmunoSpot UV Analyzer: The Cutting-Edge System' + newLine; }
  if (id.cb_spotmap.checked)           				{ text += '  SpotMap Software ' + newLine; }
  if (id.cb_immunocompliance.checked)           	{ text += '  The ImmunoCompliance package' + newLine; }
  if (id.cb_immunoqualify.checked)           		{ text += '  The ImmunoQualify software' + newLine; }
  if (id.cb_immunoquality.checked)          		{ text += '  The ImmunoQuality package' + newLine; }
  if (id.cb_plate_scanning.checked)          		{ text += '  Plate Scanning ' + newLine; }
  if (id.cb_scanalysis.checked)          			{ text += '  ScAnalysis ' + newLine; }
  if (id.cb_pbmc_reference_samples.checked)         { text += '  Reference Samples ' + newLine; }
  if (id.cb_cef_peptides.checked)          			{ text += '  CEF Peptides ' + newLine; }
  if (id.cb_serum_free_media.checked)          		{ text += '  Serum-Free Media ' + newLine; }
  if (id.cb_plate_loader.checked)          			{ text += '  Plate Loader ' + newLine; }
  if (id.cb_plate_washer.checked)          			{ text += '  Plate Washer' + newLine; }
  if (id.cb_immunospot_interactive.checked)         { text += '  ImmunoSpot Interactive ' + newLine; }
  if (id.cb_wet_assay_training.checked)          	{ text += '  Wet Assay Training ' + newLine; }
  if (id.cb_elispot_analysis_consultation.checked)  { text += ' ELISPOT Analysis Consultation ' + newLine; }
  if (id.cb_contract_research.checked)          	{ text += ' Immune Monitoring Contract Research ' + newLine; }
  if (id.Interests.value != '') 					{ text += newLine + 'Other interests: ' + newLine + id.Interests.value + newLine; }
  if (id.cb100.checked)          					{ text += newLine + 'Wants to receive additional info regarding latest products' + newLine; }
  if (id.Comments.value != '')  					{ text += newLine + 'Comments: ' + newLine + id.Comments.value + newLine; }
//  alert (text);
  return text;
}

function checkForm () {
  /* checks if form is correctly filled out. marks required fields with a light
   * red background and puts focus on first required field which is empty
   */
  var required = new Array (document.reqinfo.Name,
                        document.reqinfo.Company,
                        document.reqinfo.Email);
  var ok = true;
  var missing = null;
  var errmsg = 'Fields marked with an asterisk (*) are required and have to be provided!';
  var bgcolor = '#ffccbb';
// alert("Debug 1");

  for (i = 0; i < required.length; i++) {
    if (required[i].value == '') {
      if (missing == null) missing = required[i];
      ok = false;
      required[i].style.background = bgcolor;
    } else {
      required[i].style.background = 'transparent';
    }
  }
// alert("Debug 2");

  if (!ok) {
    alert (errmsg);
    missing.focus ();
    missing = null;
  } else {
    if (php) {
      document.reqinfo.submit ();
    } else {
      var email = 'ctl-europe@immunospot.com';
      var subject = 'Information Request';
      var body = createText ();
      var cc_recipient = 'bcc=deanv@immunospot.com'; /* Had to make this a bcc field due to a Netscape bug */
      location.href = 'mailto:' + email + '?' +
                      cc_recipient + '&' +
                      'subject=' + subject + '&' +
                      'body=' + body;
    }
  }
}



function checkForm2 () {
  /* checks if form is correctly filled out. marks required fields with a light
   * red background and puts focus on first required field which is empty
   */
  var required = new Array (document.plateinfo.name,
                        document.plateinfo.first,
						document.plateinfo.fcompany,
						document.plateinfo.phone,
						document.plateinfo.email,
						document.plateinfo.address,
						document.plateinfo.city,
						document.plateinfo.zip,
						document.plateinfo.ponumber,
						document.plateinfo.numofplates);
						
  var ok = true;
  var missing = null;
  var errmsg = 'Fields marked with an asterisk (*) are required and have to be provided!';
  var bgcolor = '#ffccbb';

  for (i = 0; i < required.length; i++) {
    if (required[i].value == '') {
      if (missing == null) missing = required[i];
      ok = false;
      required[i].style.background = bgcolor;
    } else {
      required[i].style.background = 'transparent';
    }
  }

  if (!ok) {
    alert (errmsg);
    missing.focus ();
    missing = null;
	document.plateinfo.same.checked = false;
  } else {
  	this.print();
  }
}


function checkForm3 () {
  /* checks if form is correctly filled out. marks required fields with a light
   * red background and puts focus on first required field which is empty
   */
  var required = new Array (document.plateinfo.name,
                        document.plateinfo.first,
						document.plateinfo.fcompany,
						document.plateinfo.phone,
						document.plateinfo.email,
						document.plateinfo.address,
						document.plateinfo.city,
						document.plateinfo.zip);
						
  var ok = true;
  var missing = null;
  var errmsg = 'Fields marked with an asterisk (*) are required and have to be provided!';
  var bgcolor = '#ffccbb';

  for (i = 0; i < required.length; i++) {
    if (required[i].value == '') {
      if (missing == null) missing = required[i];
      ok = false;
      required[i].style.background = bgcolor;
    } else {
      required[i].style.background = 'transparent';
    }
  }

  if (!ok) {
    alert (errmsg);
    missing.focus ();
    missing = null;
	document.plateinfo.same.checked = false;
  } 
}


function setBillingAddr() {
	
	if (document.plateinfo.same.checked) {
		document.plateinfo.baddress.value = document.plateinfo.address.value;
		document.plateinfo.bcompany.value = document.plateinfo.company.value;
		document.plateinfo.bcity.value = document.plateinfo.city.value;
		document.plateinfo.bzip.value = document.plateinfo.zip.value;
		document.plateinfo.bstate.selectedIndex = document.plateinfo.state.selectedIndex
		
	} else {
		document.plateinfo.baddress.value = "";
		document.plateinfo.bcompany.value = "";
		document.plateinfo.bcity.value ="";
		document.plateinfo.bzip.value ="";
	}
}


function checkLength(leng) {
		text = document.plateinfo.Interests.value;
		if (text.length > leng) {
			alert("The text length is limited.");
	}
}

