
var nn4x = false; var nav = false; var ie = false; var w3c = false; /* some browser varialbes */
if (document.getElementById) { w3c = true; } /* browser is ns6, ns7, mozilla, or other w3c standard browser */
else if (document.all) { ie = true; } /* browser is ie4+ */
else if (document.layers) { nn4x = true; } /* browser is ns4.x  */
/* browser NS6+ code (ie5+ also supports this syntax, but we already took care of IE) */
else { w3c = true; }/* last/default case to w3c standards */

if (navigator.appName == 'Netscape') { nav = true; } /* broser is netscape type */

function whichCSS() { /* which ccs file to use */
  /* nn4.x font has to be one px bigger, plus any positioning can be different */
  if (document.layers) { return '<link rel="stylesheet" type="text/css" href="cssjs/mainCelcorpNet4x.css" />' }
  else { return '<link rel="stylesheet" type="text/css" href="cssjs/mainCelcorp.css" />' }
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {
    if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
      document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; 
      onresize=MM_reloadPage;
    }
  }
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) {
    location.reload();
  }
}
MM_reloadPage(true)

function over(im,act) {
  var myImage = eval('document.' + im);
  var newImage = eval(im + '_' + act);
  myImage.src = newImage.src;
}
          
function lTrim(str) {
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(0)) != -1) {
    var j=0, i = s.length;
    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
      j++;
      s = s.substring(j, i);
  }
  return s;
}
function rTrim(str) {
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
    var i = s.length - 1;
    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
      i--;
      s = s.substring(0, i+1);
  }
  return s;
}
function trim(str) {
  return rTrim(lTrim(str));
}

function validEmail(str) {
  var re1 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/
  var re2 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/
  if (str.search(re1) != 0) { return false; }
  else if (str.search(re2) > -1) { return false; }
  else { return true; }
}

function testForm(frmName) {
  if (trim(eval('document.' + frmName + '.yourname').value) == '') {
    alert('Please enter your name.');
    return false;
  }
  if (trim(eval('document.' + frmName + '.company').value) == '') {
    alert('Please enter your Company.');
    return false;
  }
  if (trim(eval('document.' + frmName + '.city').value) == '') {
    alert('Please enter your City.');
    return false;
  }
  if (trim(eval('document.' + frmName + '.state').value) == '') {
    alert('Please enter your State.');
    return false;
  }
  if (!validEmail(trim(eval('document.' + frmName + '.email').value)) && trim(eval('document.' + frmName + '.phone').value) == '') {
    alert('Please enter a valid email or phone number.');
    return false;
  }
setCookie(frmName,'success', exp);
}

var expDays = 365; 
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*30*24*60*60*1000)); 

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function isNumber(str) {
  var tmp = document.tst.value;
  if (str == '') { alert('please enter something'); document.tst.tel.focus(); return false;}
  var validChars = "0123456789";
  for (var i =0; i <= str.length -1; i++) {
    if (validChars.indexOf(str.charAt(i)) == -1) {
      document.tst.tel.select(); document.tst.tel.focus(); return false;
    }
  }
}

function isPhone(frm,ph,rad,newPh) {
  phone = eval('document.' + frm + '.' + ph );
  radBut = eval('document.' + frm + '.' + rad);
  newPhone = eval('document.' + frm + '.' + newPh);
  
  if (phone.value == '') { alert('please enter a phone number'); phone.focus(); return false; }
  var validChars = "0123456789";
  var newStr = ''; var newStr2 = '';
  for (var i =0; i <= phone.value.length -1; i++) {
    if (validChars.indexOf(phone.value.charAt(i)) != -1) {
      newStr = newStr + phone.value.charAt(i);
      //alert(newStr + ' - ' + newStr.length);
    }
  }
  if (newStr.length != 10) { 
    alert('You did not enter a valid phone number; \n A phone number must have only 10 digits.');
    phone.select(); phone.focus(); return false;
  }
  else if (newStr.charAt(0) == 0) { 
    alert('You did not enter a valid phone number; \n A phone number can not start with 0.');
    phone.select(); phone.focus(); return false;
  }
  else {
    if (radBut[0].checked) {
      newStr2 = newStr.charAt(0) + newStr.charAt(1) + newStr.charAt(2) + '.' + newStr.charAt(3) + newStr.charAt(4) + newStr.charAt(5) + '.' + newStr.charAt(6) + newStr.charAt(7) + newStr.charAt(8) + newStr.charAt(9);
      newPhone.value = newStr2;
    }
    else if (radBut[1].checked) {
      newStr2 = '(' + newStr.charAt(0) + newStr.charAt(1) + newStr.charAt(2) + ')' + newStr.charAt(3) + newStr.charAt(4) + newStr.charAt(5) + '-' + newStr.charAt(6) + newStr.charAt(7) + newStr.charAt(8) + newStr.charAt(9);
      newPhone.value = newStr2;
    }
    else if (radBut[2].checked) {
      newStr2 = '(' + newStr.charAt(0) + newStr.charAt(1) + newStr.charAt(2) + ') ' + newStr.charAt(3) + newStr.charAt(4) + newStr.charAt(5) + '-' + newStr.charAt(6) + newStr.charAt(7) + newStr.charAt(8) + newStr.charAt(9);
      newPhone.value = newStr2;
    }
    else if (radBut[3].checked) {
      newStr2 = newStr.charAt(0) + newStr.charAt(1) + newStr.charAt(2) + '-' + newStr.charAt(3) + newStr.charAt(4) + newStr.charAt(5) + '-' + newStr.charAt(6) + newStr.charAt(7) + newStr.charAt(8) + newStr.charAt(9);
      newPhone.value = newStr2;
    }
    else if (radBut[4].checked) {
      newStr2 = newStr.charAt(0) + newStr.charAt(1) + newStr.charAt(2) + ' ' + newStr.charAt(3) + newStr.charAt(4) + newStr.charAt(5) + ' ' + newStr.charAt(6) + newStr.charAt(7) + newStr.charAt(8) + newStr.charAt(9);
      newPhone.value = newStr2;
    }
    else { newPhone.value = newStr; }
  }
}

function footer(page) {
  var ftrTxt = '<table width="750" border="0" cellpadding="0" cellspacing="0">';
  ftrTxt = ftrTxt + '<tr>';
  ftrTxt = ftrTxt + '<td valign="top" align="center">';
  ftrTxt = ftrTxt + '<div align="center" style="width:565px;" class="ftr">';
  if (page == '1.4') { /* contact */
    ftrTxt = ftrTxt + '<strong><a href="index.html" class="ftrNav">Home</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<span class="ftrNavSel">Contact</span>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="news.html" class="ftrNav">News</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="sitemap.html" class="ftrNav">Site Map</a></strong>';
  } else if (page == '1.3') { /* news */
    ftrTxt = ftrTxt + '<strong><a href="index.html" class="ftrNav">Home</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="contact.html" class="ftrNav">Contact</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<span class="ftrNavSel">News</span>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="sitemap.html" class="ftrNav">Site Map</a></strong>';
  } else if (page == '6') { /* site map */
    ftrTxt = ftrTxt + '<strong><a href="index.html" class="ftrNav">Home</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="contact.html" class="ftrNav">Contact</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="news.html" class="ftrNav">News</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<span class="ftrNavSel">Site Map</span></strong>';
  } else if (page != '0') { /* regular */
    ftrTxt = ftrTxt + '<strong><a href="index.html" class="ftrNav">Home</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="contact.html" class="ftrNav">Contact</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="news.html" class="ftrNav">News</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="sitemap.html" class="ftrNav">Site Map</a></strong>';
  } else { /* no home */
    ftrTxt = ftrTxt + '<strong><a href="contact.html" class="ftrNav">Contact</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="news.html" class="ftrNav">News</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="sitemap.html" class="ftrNav">Site Map</a></strong>';
  }
  if (!nn4x) {
    ftrTxt = ftrTxt + '<br />';
  }
  ftrTxt = ftrTxt + '<img src="images/spacer.gif" width="1" height="5" alt="" border="0" />';
  ftrTxt = ftrTxt + '<table width="565" border="0" cellpadding="0" cellspacing="0">';
  ftrTxt = ftrTxt + '<tr bgcolor="#1D3956">';
  ftrTxt = ftrTxt + '<td valign="top" align="left" width="750" height="1"><img src="images/spacer.gif"" width="565" height="1" alt="" border="0" /></td>';
  ftrTxt = ftrTxt + '</tr>';
  ftrTxt = ftrTxt + '</table>';
  ftrTxt = ftrTxt + '<img src="images/spacer.gif" width="1" height="5" alt="" border="0" /><br />';
  ftrTxt = ftrTxt + '<span class="ftr">Copyright &copy; 2003 Celcorp. All rights reserved.&nbsp;</span></div><br />';
  ftrTxt = ftrTxt + '</td>';
  ftrTxt = ftrTxt + '</tr>';
  ftrTxt = ftrTxt + '</table>';

  return ftrTxt;
}
