// *****************************************************************************
// *
// * Shane M Allred 
// * IBM Global Services
// * Version 1.2
// *
// * This file contains generic JavaScript functions that can be used for 
// * some generic types of form validation. 
// *
// * These functions include:
// * - Checking a required field
// * - Checking a list of required fields
// * - Trimming a string or field value
// * - Retrieving the selected value of a form control
// * - Setting the value or selected value of a form control
// * - Validating an email address
// * - Selecting a field
// * - Sending a referall page URI to a friend
// *
// * The following form control types are supported where applicable
// * - text
// * - textarea
// * - submit
// * - file
// * - password
// * - select-one
// * - select-multiple
// * - checkbox
// * - radio
// *
// *****************************************************************************

//Set the junction for the header search URL path
function DoSearch(){
var st = document.getElementById("q").value
var domain = window.location.hostname;
if (domain.search(/www-304/i)!= -1)
  jct = "/jct03001c";
else if (domain.search(/www-sso/i)!= -1) 
  jct = "/wwwalpha80";
else  
  jct = "";
st = encodeURIComponent(st);
st = st.replace(/\%20/g, "+")
var index=document.getElementById("sn").selectedIndex;
var target=eval("document.LocalSearchForm.Field"+(index+1)+".value");
target = jct+target+st;
window.location.href =target;
return false;
}

//Set the TA-IRIS-search URL
function setTairisSearchUrl(country,dummy)
{
 var strt_string="http://www-05.ibm.com/services/learning/";
 var end_string="/ta-iris.nsf/$$Search?CreateDocument";
 var final_string=strt_string + country + end_string;
 document.LocalSearchForm1.action=final_string;
 document.LocalSearchForm1.submit();
}

//Open the default e-mail editor with the referral page in the message

function emailPage(e_subject, e_body) {
  var mail_str = "mailto:?subject=" + 
    escape(e_subject) + "&body=" + escape(e_body) + " " + escape(location.href);

  location.href = mail_str;
}

function emailPage2() {
  var mail_str = "mailto:?body=" + escape(location.href);

  location.href = mail_str;
}

// Checks the validity of an email address
function checkEmail(email) {
  var at="@";
  var dot=".";
  var lat=email.indexOf(at);
  var lstr=email.length;
  var ldot=email.indexOf(dot);
  var l1dot=email.lastIndexOf(dot);

  if (email.indexOf(at)==-1&&ldot==l1dot){
    return false;
  }
  if ((email.indexOf(at)==-1&&ldot==l1dot)|| email.indexOf(at)==0 || email.indexOf(at)==lstr){
   return false;
  }
  if (email.indexOf(dot)==-1 || email.indexOf(dot)==0 || email.indexOf(dot)==lstr){
    return false;
  }
  if (email.indexOf(at,(lat+1))!=-1){
    return false;
  }
  if (email.substring(lat-1,lat)==dot || email.substring(lat+1,lat+2)==dot){
    return false;
  }
  if (email.indexOf(dot,(lat+2))==-1){
    return false;
  }
  if (email.indexOf(" ")!=-1 || email.indexOf("\\")!=-1 || email.indexOf(":")!=-1  || email.indexOf(";")!=-1 || email.indexOf("\"")!=-1){
    return false;
  }
  if (email.indexOf(",")!=-1 || email.indexOf("<")!=-1 || email.indexOf(">")!=-1  || email.indexOf("(")!=-1 || email.indexOf(")")!=-1 || email.indexOf("*")!=-1){
    return false;
  }
  return true;			
}

// Creates a popup window
function popupWindow(mypage, myname, w, h, scroll) {
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  var winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=' + scroll + ',resizable,status';
  var win = window.open(mypage, myname, winprops);
  win.focus();
}

// Checks the size of a field value against a user defined value
function checkLength(form, fieldName, size) {
  var value = getSelectedValue(form, fieldName);

  if (value.length > size) {
    return false;
  }

  return true;
}

// Checks an array of required fields
function checkRequiredFields(form, fieldNames, labels, message) {
  var isValid = true;

  for (var i = 0; i < fieldNames.length; i++) {
    var fieldName = fieldNames[i];
    var fieldLabel = labels[i];
  
    if (!checkRequiredField(form, fieldName)) {
      isValid = false;
      message += "\n" + fieldLabel;
    }
  }

  if (!isValid) {
    alert(message);
  }

  return isValid;
}

// Checks a single required field
function checkRequiredField(form, fieldName) {
  var hasValue = false;

  if (getSelectedValue(form, fieldName) != "") {
    hasValue = true;
  }

  return hasValue;
}

// Prepopulates form elements based on type
function prepopulateForm(form, fields, values) {
  for (var i = 0; i < fields.length; i++) {
    var fieldName = fields[i];
    var fieldValue = values[i];

    setSelectedValue(form, fieldName, fieldValue);      
  }
}

// Trims the leading and trailing spaces from a text input field
function trimField(form, fieldName) { 
  var field = form.elements[fieldName];
		
  field.value = trimValue(field.value);
}

// Trims the leading and trailing spaces from a string
function trimValue(value) {
  var reg1 = /^(\s*)(.*[^\s])(\s*)$/;
  var reg2 = /^(\s*)$/;

  if (reg1.test(value)) {  
    return value.replace(reg1, "$2");
  }
  else if (reg2.test(value)) {
    return "";
  }
  else {
    return value;
  }
}

// Get the element type of the field or array of fields
function getElementType(field) {
  var elmType = "";

  if (field != undefined) {
    elmType = field.type;

    if (elmType == undefined && field[0]) {
      elmType = field[0].type;
    }
  }
  
  return elmType;
}

// Determines if a string value is a true array
function isArrayVal(value) {
  var objType = getType(value);

  if (objType == "Array") {
    return true;
  }
  else {
    return false;
  }
}

// Returns the object type
function getType(object) {
  if (object == null) {
    return "undefined";
  }

  var id = object.constructor.toString();

  var index1 = id.indexOf (" ");
  var index2 = id.indexOf ("(");

  return id.substring (index1 + 1, index2);
}

// Selects a form field
function selectField(form, fieldName) {
  var field = form.elements[fieldName];
  var elmType;

  if (field != undefined) {
    elmType = getElementType(field);

    if (elmType == "text" || elmType == "textarea" || elmType == "password" || elmType == "file") {
      if (field[0]) {
        field = field[0];
      }

      field.focus();
      field.select();
    }
    else if (elmType == "select-one" || elmType == "select-multiple") {
      field.focus();
    }
    else if (elmType == "radio" || elmType == "checkbox" || elmType == "submit") {
      if (field[0]) {
        field = field[0];
      }

      field.focus();
    }
  }
}


// Sets the selected value for form element this could be a single value or an array
function setSelectedValue(form, fieldName, value) {
  var field = form.elements[fieldName];
  var elmType;

  if (field != undefined) {
    elmType = getElementType(field);
   
    if (elmType == "hidden" || elmType == "text" || elmType == "textarea" || elmType == "password" || elmType == "file" || elmType == "submit") {
      setTextValue(field, value);
    }
    else if (elmType == "select-one" || elmType == "select-multiple") {
      setSelectValue(field, value);
    }
    else if (elmType == "checkbox") { 
      setCheckboxValue(field, value);	
    }
    else if (elmType == "radio") { 
      setRadioValue(field, value);	
    }
  }
}

// Sets hidden, text, textarea, password, file, submit elements
function setTextValue(field, value) {
  if (field[0]) {
    for (var i = 0; i < field.length; i++) {
      if (isArrayVal(value) && value[i]) {
        field[i].value = value[i];
      }
      else if (!isArrayVal(value)) {
        field[0].value = value;
        break;
      }
    }
  }
  else if (isArrayVal(value)) {
    field.value = value[0];
  }
  else {
    field.value = value;
  }
}

// Sets select and multi select box elements
function setSelectValue(field, value) {
  if (field[0]) {
    for (var i = 0; i < field.length; i++) {
      if (isArrayVal(value)) {
        for (var j = 0; j < value.length; j++) {
          if (field[i].value == value[j]) {
            field[i].selected = true;
          }
        }
      }
      else {
        if (field[i].value == value) {
          field[i].selected = true;
        }
      }
    }
  }
}

// Sets checkbox elements
function setCheckboxValue(field, value) { 
  if (field[0]) {
    for (var i = 0; i < field.length; i++) {
      if (isArrayVal(value)) {
        for (var j = 0; j < value.length; j++) {
          if (field[i].type == "checkbox" && field[i].value == value[j]) {
            field[i].checked = true;
          }
        }
      }
      else {
        if (field[i].type == "checkbox" && field[i].value == value) {
          field[i].checked = true;
        }
      }
    }
  }
  else {
    if (isArrayVal(value)) {
      for (var i = 0; i < value.length; i++) {
        if (field.type == "checkbox" && field.value == value[i]) {
          field.checked = true;
        }
      }
    }
    else {
      if (field.type == "checkbox" && field.value == value) {
        field.checked = true;
      }
    }
  }
}

// Sets radio button elements
function setRadioValue(field, value) {
  var isNotSelected = true;
 
  if (field[0] && !isArrayVal(value)) {
    for (var i = 0; i < field.length && isNotSelected; i++) {
      if (field[i].value == value) {
        field[i].checked = true;
        isNotSelected = false;
      }
    }
  }
  else if (!isArrayVal(value)) {
    if (field.value == value) {
      field.checked = true;
    }
  }
}

// Returns the selected value for form element this could be a single value or an array
function getSelectedValue(form, fieldName) {
  var field = form.elements[fieldName];
  var sValue;
  var elmType;

  if (field != undefined) {
    elmType = getElementType(field);
   
    if (elmType == "hidden" || elmType == "text" || elmType == "textarea" || elmType == "password" || elmType == "file" || elmType == "submit") {
      sValue = getTextValue(field);
    }
    else if (elmType == "select-one" || elmType == "select-multiple") {
      sValue = getSelectValue(field);
    }
    else if (elmType == "radio" || elmType == "checkbox") { 
      sValue = getRadioCheckValue(field);	
    }
  }

  if (sValue == undefined) {
    sValue = "";
  }
  else if (isArrayVal(sValue) && sValue.length == 1) {
    sValue = sValue[0];
  }
  
  return sValue;
}

// Returns the value(s) of hidden, text, textarea, password, file, and submit fields
function getTextValue(field) {
  var sValue;

  if (field[0]) {
    sValue = new Array();

    for (var i = 0; i < field.length; i++) {
      if (trimValue(field[i].value).length != 0) {
        sValue[sValue.length] = trimValue(field[i].value);
      }
    }
  }
  else {
    sValue = "";

    if (trimValue(field.value).length != 0) {
      sValue = trimValue(field.value);
    }
  }
  
  return sValue;
}

// Returns the selected select box or multiple select box value(s)
function getSelectValue(field) {
  var sValue;
   
  if (field[0]) {
    sValue = new Array();

    for (var i = 0; i < field.length; i++) {
      if (field[i].selected && trimValue(field[i].value).length != 0) {     
        sValue[sValue.length] = trimValue(field[i].value);
      }
    }
  }
  else {
    sValue = "";

    if (field.selected && trimValue(field.value).length != 0) {     
      sValue = trimValue(field.value);
    }
  }

  return sValue;  
}

// Returns the selected radio button or check box value(s)
function getRadioCheckValue(field) {
  var sValue;

  if (field[0]) {
    sValue = new Array();

    for (var i = 0; i < field.length; i++) {
      if (field[i].checked && trimValue(field[i].value).length != 0) {
        sValue[sValue.length] = trimValue(field[i].value);
      }
    }
  }
  else {
    sValue = "";

    if (field.checked && trimValue(field.value).length != 0) {
      sValue = trimValue(field.value);
    }
  }

  return sValue;
}

// Formats the US currency
function formatUSCurrency(amount, hasCents) {
  var strValue = new String(amount);
  var strDec = "";

  var numReg = /^(\d+)(\.\d{2})?$/;

  if (numReg.test(strValue)) {
    var commaReg  = /(\d+)(\d{3})/;

    strDec = strValue.replace(numReg, '$2');
    strValue = strValue.replace(numReg, '$1');
    
    while (commaReg.test(strValue)) {
      strValue = strValue.replace(commaReg, '$1,$2');
    }

    strValue = "$" + strValue;

    if (hasCents) {
      strValue += strDec;
    }
  }

  return strValue;
}


// Formats the currency based on provided pattern using jQuery
// Initialized via jQuery('#pricewtax').currency({s:",",d:".",c:2});  to format the text of the element
// Or initialized via jQuery.currency(12345.00,{s:",",d:".",c:2}); to format the number and return string
// Called via the jQuery(document).ready(function() on a page
(function(A){A.fn.extend({currency:function(B){var C={s:",",d:".",c:2};C=A.extend({},C,B);return this.each(function(){var D=(C.n||A(this).text());D=(typeof D==="number")?D:((/\./.test(D))?parseFloat(D):parseInt(D)),s=D<0?"-":"",i=parseInt(D=Math.abs(+D||0).toFixed(C.c))+"",j=(j=i.length)>3?j%3:0;A(this).text(s+(j?i.substr(0,j)+C.s:"")+i.substr(j).replace(/(\d{3})(?=\d)/g,"$1"+C.s)+(C.c?C.d+Math.abs(D-i).toFixed(C.c).slice(2):""));return this})}})})(jQuery);jQuery.currency=function(){var A=jQuery("<span>").text(arguments[0]).currency(arguments[1]);return A.text()};

// Copies student information to contact if they are the same (used with phone extension field)
function contactSameAsStudent2() {
  var frm = document.tsForm;
  var field = frm.elements["usrContactSASInd"];
    
    if (field != null && field[0]) {
      field = field[0];
    }

    if (field != null && field.checked) { 
      setSelectedValue(frm, "usrContactName", getSelectedValue(frm, "usrFirstName") + " " + getSelectedValue(frm, "usrLastName"));
      setSelectedValue(frm, "usrContactPhone", getSelectedValue(frm, "usrPhone"));
      setSelectedValue(frm, "usrContactPhoneExtn", getSelectedValue(frm, "usrPhoneExtn"));
      setSelectedValue(frm, "usrContactEmail", getSelectedValue(frm, "usrEmail"));
    }
    else {
      setSelectedValue(frm, "usrContactName", "");
      setSelectedValue(frm, "usrContactPhone", "");
      setSelectedValue(frm, "usrContactPhoneExtn", "");
      setSelectedValue(frm, "usrContactEmail", "");
    }
  }

// *****************************************************************************
// *
// * Add additional custom methods below here
// *
// * These methods were not created by Shane M Allred but some were modified
// * to call the new functions created. This allows the old function names to
// * still be supported.
// *
// ***************************************************************************** 

// Checks a EMEA  customer number
function checkCustomerNumberCBT(element)
{
 var num=true;
 len=element.length;
 element.toString();
 n=Number(element);
 if(len<5) 
    num=false; 
    return num; 
 }
 
 
// Checks a Canadian customer number
function checkCustomerNumberCA(custnum) {
  var re1 = /^\d{6}$/;
  return re1.test(custnum);
}

// Checks a German customer number
function checkDECustomerNumber(custnum) {
  var re1 = /^\d{6}$/;
  return re1.test(custnum);
}

// Checks a US customer number
function checkCustomerNumber(custnum) {
  var re1 = /^\d{7}$/;
  if(custnum=="newcust"){
  	return true;
  }
  return re1.test(custnum);
}


function checkPONumber(ponumber) {

var POStatus =true;
var re1= /[^a-zA-Z0\?\s\.\-\:\#\"/]/;
var invalidponumber=new Array("123","777","813","814","0888","888","999999","9999999","APPLY ELA CREDIT/CODE A3M","CHECK # 50209894","CHECK#354011","CK REC'D #021245","CK# 022937","CREDIT #    5348446 02/01","ED PACK 667851-1 AND 2","ED001","EDAP20051018","EDPACK VOUCHER","EDPACKONLINEVOUCHER3243","EDPACKONLINEVOUCHER3244","INV. TS16101","INVOICE 250835X","INVOICE TO UNIT 822","PLEASE INV TO:M/S 9370700","PO WAIVER REF VOUCH 6726","RECD CHECK # 131981","USE CONTRACT# N1000007038","VOUCHER # 2263","VOUCHER 4979","VOUCHER 5656","VOUCHER# 3277","XYZ123", "COSTCENT# 10370/HJPMC", "PRE-PAID INV # 6362654", "4IBMTEACH", "41BMTEACH");
for(j=0;j<invalidponumber.length;j++){
var ponum=invalidponumber[j];
if(ponum.toUpperCase()==ponumber.toUpperCase())
POStatus=false;
}

return (POStatus && re1.test(ponumber));
}


// Function to check field validation is numeric only
function checkFieldIsNumber(element)
{
var num=true;
 len=element.length;
 element.toString();
 n=Number(element);
 if (len > 0)
 {
 if(isNaN(n))
 num=false; 
 }
 return num; 

 }

// Function to check education card validation
function checkEdCard(element)
{
var num=true;
 len=element.length;
 element.toString();
 n=Number(element);
 if (len > 0)
 {
 if(isNaN(n))
 num=false; 
 }
 return num; 

 }
// Checks the credit card expiration
function checkCreditCardExp1(classDate, cardDate) {
  var daysInMonth = new Array("31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31");
  var SECOND = 1000; // the number of milliseconds in a second
  var MINUTE = SECOND * 60; // the number of milliseconds in a minute
  var HOUR = MINUTE * 60; // the number of milliseconds in an hour
  var DAY = HOUR * 24; // the number of milliseconds in a day
  var WEEK = DAY * 7; // the number of milliseconds in a week

  var result, cardMonth, cardDay, cardYear;
  var re = /^0*(\d{1,2})\/(\d{2})$/;

  if (re.test(cardDate)) {
    result = re.exec(cardDate);
  
    cardMonth = parseInt(result[1]);
    cardDay = parseInt(daysInMonth[cardMonth - 1]);
    cardYear = parseInt("20" + result[2]);
  }
  else {
    alert ("You have entered an invalid date.");
  }

  if (cardYear % 400 == 0 || (cardYear % 100 != 0 && cardYear % 4 == 0)) {
    cardDay = 29;
  }

  var fullCardDate = cardMonth + "/" + cardDay + "/" + cardYear;
  
  //set start_date to current date
  var start_date = new Date();
  var end_date = new Date(fullCardDate);

  //if classDate is available, set start_date to classDate
  if(trimValue(classDate).length>0) {
    start_date = new Date(classDate);
  }

  var start_time = start_date.getTime(); 
  var end_time = end_date.getTime();
  var diff_time = end_time - start_time;

  if (Math.round(diff_time / DAY) > 60) {
    return true;
  }
  else {
    return false;
  }
}
//

function checkCreditCardExpEMEA(classDate, cardDate) {
 
  var daysInMonth = new Array("31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31");
  var SECOND = 1000; // the number of milliseconds in a second
  var MINUTE = SECOND * 60; // the number of milliseconds in a minute
  var HOUR = MINUTE * 60; // the number of milliseconds in an hour
  var DAY = HOUR * 24; // the number of milliseconds in a day
  var WEEK = DAY * 7; // the number of milliseconds in a week
 
  var result, cardMonth, cardDay, cardYear;
  var re = /^0*(\d{1,2})\/(\d{2})$/;
  if (re.test(cardDate)) {
    result = re.exec(cardDate);
    cardMonth = parseInt(result[1]);
    cardDay = parseInt(daysInMonth[cardMonth - 1]);
    cardYear = parseInt("20" + result[2]);
 if(cardMonth < 1 || cardMonth > 12){
      alert ("You have entered an invalid date.");
      return false;
 
 }
  }
  else {
    alert ("You have entered an invalid date.");
    return false;
 
  }
 
  if ((cardYear % 400 == 0 || (cardYear % 100 != 0 && cardYear % 4 == 0)) && cardMonth == 2) {
    cardDay = 29;
  }
 
  var fullCardDate = cardMonth + "/" + cardDay + "/" + cardYear;
  //set start_date to current date
  var start_date = new Date();
  var end_date = new Date(fullCardDate);
 
  //if classDate is available, set start_date to classDate
  if(trimValue(classDate).length>0) {
    start_date = new Date(classDate);
  }
 
  var start_time = start_date.getTime(); 
  var end_time = end_date.getTime();
  var diff_time = end_time - start_time;

  if (Math.round(diff_time / DAY) > 60) {
    return true;
  }
  else {
    return false;
  }
}

function checkCreditCardLength(cardType, cardNumber){
	var cardtype = cardType;
	var cardNo = cardNumber;
	 if(cardtype == "A" && (trimValue(cardNo).length)==15 && checkFieldIsNumber(cardNo)){
	 return true; 
 	} 
	 else if(cardtype == "D" && (trimValue(cardNo).length)==14 && checkFieldIsNumber(cardNo)){ 
	 return true; 
 	}
	 else if((cardtype == "I" ||cardtype == "M") && (trimValue(cardNo).length)==16 && checkFieldIsNumber(cardNo)){ 
	 return true; 
	 }
	 else if(cardtype == "V" && (((trimValue(cardNo).length)==13) || ((trimValue(cardNo).length)==16)) && checkFieldIsNumber(cardNo)){ 
	 return true; 
 	}
	 else{
	 return false;
	 }
 }


// Checks credit card verification number length
function checkCVVLength(cardType, cardCvvNumber, verifyCardCvvNumber) {
	var cardtype = cardType;
	var cvvNo = cardCvvNumber;
	var verifycvvNo = verifyCardCvvNumber;

	 if(cardtype == "A" && (trimValue(cvvNo).length)==4 && checkFieldIsNumber(cvvNo) && checkFieldIsNumber(verifycvvNo)){
	 return true; 
 	} 
	 else if((cardtype == "I" || cardtype == "M" || cardtype == "V" || cardtype == "D") && (trimValue(cvvNo).length)==3 && checkFieldIsNumber(cvvNo) && checkFieldIsNumber(verifycvvNo)){ 
	 return true; 
	}
	 else{
	 return false;
	}
}


// Checks credit card verification number fields match
function checkCVVMatch(cardCvvNumber, verifyCardCvvNumber) {
	var cvvNo = cardCvvNumber;
	var verifycvvNo = verifyCardCvvNumber;

	 if(cvvNo == verifycvvNo){
	 return true; 
 	} 
	 else{
	 return false;
	 }
}

//
// Checks the required fields (supports the old function name)
function checkAllRequired(form, fields, labels, message) {
  return checkRequiredFields(form, fields, labels, message);
}

// Checks a required field (supports the old function name)
function checkRequired(form, field, label, message) {
  if (!checkRequiredField(form, field)) {
    alert(label + " " + message);
    return false;
  }
  else {
    return true;
  }
}

// Returns the selected value for a radio button group (supports the old function name)
function getSelectedRadioValue(form, field) {
  return getSelectedValue(form, field);
}

// Returns the selected value for a select box single select (supports the old function name)
function getSelectedDropDownValue(form, field) {
  return getSelectedValue(form, field);
}

// Selects a text field (supports the old function name)
function selectTextField(form, field) {
  selectField(form, field);
}

// Returns the relative path to use with SSO and JavaScript
function getRelativePath(mypage) {
  var relPath = ""; 
  var context = "/services/learning/";
  var servletExt = ".wss";
  var paramStr = "?";
  var dir = "/";
  
  var url = window.location.href;
  
  var index1 = url.indexOf(servletExt) + servletExt.length;
  var index2 = url.indexOf(paramStr);
 
  if (index1 > servletExt.length && index2 != -1 && index1 < index2) {
    var pth = url.substr(index1, index2 - index1);
    
    var index = 0;
    
    while (index != -1) {
      index = pth.indexOf(dir, index);
       
      if (index != -1) {
        relPath += ".." + dir;  
        index++;
      }
    }
  }
  
  return relPath + mypage.replace(context, "");
}

// Creates a popup window that will work with SSO
function tsPopup(mypage, myname, w, h, scroll) {  
  var win_url = "https://www-03.ibm.com" + mypage;
  popupWindow(win_url, myname, w, h, scroll)
// Old function from GWA  popupWindow(getRelativePath(mypage), myname, w, h, scroll)
}

// Removes all spaces from a string
function deleteSpaces(string) {
	var finalString = "";
	string = '' + string;
	splitString = string.split(" ");
	for(i = 0; i < splitString.length; i++)
		finalString += splitString[i];
	return finalString;
}

//check if company name string contains any variation of IBM and returns false if found
function checkCompany(element)
{
 var company=true;
 var form=document.tsForm;
 var cname=form.usrCustomerName.value;
 var cname1=cname.toUpperCase();
 var temp=cname.substring(0,3);
 var cname2=temp.toUpperCase();
 if((cname1=="IBM")||(cname1=="I.B.M.")||(cname1=="I.B.M")||(cname1=="I B M")||(cname=="International Business Machines")||(cname2=="IBM")||(cname=="international business machines")||(cname=="International Business Machine")||(cname=="international business machine"))
 company=false;
 return company;
}

//check if a string contains PO Box or Post office box in all its variations and returns true if found
function containsPO(address){
	address = deleteSpaces(address);
	var POString = new Array(6);
	POString[0] = "POBOX";
	POString[1] = "P.OBOX";
	POString[2] = "PO.BOX";
	POString[3] = "P.O.BOX";
	POString[4] = "POSTOFFICEBOX";
	POString[5] = "POST.OFFICE.BOX";
	for(i=0;i<POString.length;i++)
		if(address.toUpperCase().indexOf(POString[i]) > -1)
			return true;
	return false;
}

// to return country names for corresponding country codes
function populateCountry(cCode){
 countrylist = new Array(14);
 countrylist[0] = new Array(2);
 countrylist[1] = new Array(2);
 countrylist[2] = new Array(2);
 countrylist[3] = new Array(2);
 countrylist[4] = new Array(2);
 countrylist[5] = new Array(2);
 countrylist[5] = new Array(2);
 countrylist[6] = new Array(2);
 countrylist[7] = new Array(2);
 countrylist[8] = new Array(2);
 countrylist[9] = new Array(2);
 countrylist[10] = new Array(2);
 countrylist[11] = new Array(2);
 countrylist[12] = new Array(2);
 countrylist[13] = new Array(2);
 
 countrylist[0][0] = "618";
 countrylist[0][1] = "Austria";
 
 countrylist[1][0] = "624";
 countrylist[1][1] = "Belgium";
 
 countrylist[2][0] = "678";
 countrylist[2][1] = "Denmark";
 
 countrylist[3][0] = "702";
 countrylist[3][1] = "Finland";
 
 countrylist[4][0] = "706";
 countrylist[4][1] = "France";
 
 countrylist[5][0] = "724";
 countrylist[5][1] = "Germany";
 
 countrylist[6][0] = "754";
 countrylist[6][1] = "Ireland";
 
 countrylist[7][0] = "758";
 countrylist[7][1] = "Italy";
 
 countrylist[8][0] = "788";
 countrylist[8][1] = "Netherlands";
 
 countrylist[9][0] = "806";
 countrylist[9][1] = "Norway";
 
 countrylist[10][0] = "838";
 countrylist[10][1] = "Spain";
 
 countrylist[11][0] = "846";
 countrylist[11][1] = "Sweden";
 
 countrylist[12][0] = "848";
 countrylist[12][1] = "Switzerland";
 
 countrylist[13][0] = "866";
 countrylist[13][1] = "United Kingdom";
 
 for(i=0;i<=13;i++){
  if(countrylist[i][0] == cCode){
   return(countrylist[i][1]);
  }
 }
}

//function for catalog on-demand check boxes (allChapters)
function checkUncheckAll(theElement) {
     var theForm = theElement.form, z = 0;
     for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'allChapters'){
      theForm[z].checked = theElement.checked;
      }
     }
}

//functions for catalog on-demand check boxes (chapters)
function checkUncheckSome(controller,theElements) {
     var formElements = theElements.split(',');
     var theController = document.getElementById(controller);
     for(var z=0; z<formElements.length;z++){
      theItem = document.getElementById(formElements[z]);
      if(theItem.type){
        if (theItem.type=='checkbox') {
            theItem.checked=theController.checked;
        }
      } else {
          theInputs = theItem.getElementsByTagName('input');
      for(var y=0; y<theInputs.length; y++){
      if(theInputs[y].type == 'checkbox' && theInputs[y].id != theController.id)
        {
         theInputs[y].checked = theController.checked;
        }
      }
      }
    }
}

//functions for catalog on-demand check boxes (subChapters)
function uncheckParent(controller,theElements) {
     var formElements = theElements.split(',');
     var theController = document.getElementById(controller);
     for(var z=0; z<formElements.length;z++){
      theItem = document.getElementById(formElements[z]);
      if(theItem.type){
        if (theItem.type=='checkbox') {
            theItem.checked=false;
        }
      } else {
          theInputs = theItem.getElementsByTagName('input');
      for(var y=0; y<theInputs.length; y++){
      if(theInputs[y].type == 'checkbox' && theInputs[y].id != theController.id)
        {
         theInputs[y].checked=false;
        }
      }
      }
    }
}

/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;