var bName = navigator.appName;
if (bName == "Netscape") { 
if (navigator.platform == "Win32") {
document.write('<link rel="stylesheet" href="/stylesheet/ax/feature_pcns.css" type="text/css">');
} else {
document.write('<link rel="stylesheet" href="/stylesheet/ax/feature_mcns.css" type="text/css">');
}
} else {
if (navigator.platform == "Win32") {
document.write('<link rel="stylesheet" href="/stylesheet/ax/feature_pcie.css" type="text/css">');
} else {
document.write('<link rel="stylesheet" href="/stylesheet/ax/feature_mcie.css" type="text/css">');
}
}

function sendcheckMail(item)  { 
  var x = document.all.item(item).value;
  //var x = document.forms[0].email.value;
  var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
  if (filter.test(x)) {
    return true
    }
  else {
    alert('ขออภัยคุณใส่ที่อยู่อีเมล์ผู้รับไม่ถูกต้อง');
    return false
    }
}

function PopWindow(file, width, height, showScroll)
{
	if ( typeof( showScroll ) == 'undefined' )
		showScroll = 'yes';
	
	window.open(file, null, "height=" + height + ",width=" + width +         		
	",toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=" + showScroll)
	//return true;
}

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 EnterForum(id) {
  thewindow = window.open('forum_policy.asp?id='+id, 'forumpolicy', config='toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no,width=450,height=250');
}

function subscribe(){
  thewindow = window.open('newsletter.asp', 'newsletter', config='toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no,width=250,height=170');
}

function getmap(id){
  thewindow = window.open('map.asp?id='+id, 'map', config='toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=no,width=540,height=450');
}

function SendtoFriend() {
  thewindow = window.open('sendtofriend.asp', 's2f', config='toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no,width=250,height=170');
}

function CheckForumPost() {
  var state = true;
  if (Trim(fpost.poster_name.value) == '') {
    alert('กรุณากรอกชื่อ');
    fpost.poster_name.focus();
    state = false;
  } else {
    if (isEmail(fpost.poster_email.value) == false) {
      alert('กรุณากรอกอีเมล์');
      fpost.poster_email.focus();
      state = false;
    } else {
      if (Trim(fpost.message_body.value) == '') {
        alert('คุณยังไม่ได้กรอกข้อความ');
        fpost.message_body.focus();
        state = false;
      }
    }
  }
  return state;
}

function CheckVote() {
  var status = true;
  if (Trim(vform.name.value) == '') {
    status = false;
    alert('กรุณากรอกชื่อ');
    vform.name.focus();
  } else {
    if ((vform.sex[0].checked == false) && (vform.sex[1].checked == false)) {
      status = false;
      alert('กรุณาเลือกเพศ');
      vform.sex[0].focus();
    } else {
      if (Trim(vform.addr.value) == '') {
        status = false;
        alert('กรุณากรอกที่อยู่');
        vform.addr.focus();
      } else {
        if (Trim(vform.province.value) == '') {
          status = false;
          alert('กรุณากรอกจังหวัด');
          vform.province.focus();
        } else {
          if (Trim(vform.zip.value) == '') {
            status = false;
            alert('กรุณากรอกรหัสไปรษณีย์');
            vform.zip.focus();
          } else {
            if (isEmail(Trim(vform.email.value)) == '') {
              status = false;
              alert('กรุณากรอกอีเมล');
              vform.email.focus();
            } else {
              if (Trim(vform.tel.value) == '') {
                status = false;
                alert('กรุณากรอกหมายเลขโทรศัพท์');
                vform.tel.focus();
              }
            }
          }                                
        }
      }
    }
  }
  return status;
}

function isEmail(str) {
// are regular expressions supported?
var supported = 0;
if (window.RegExp) {
  var tempStr = "a";
  var tempReg = new RegExp(tempStr);
  if (tempReg.test(tempStr)) supported = 1;
  }
if (!supported) {
  return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  }
var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
return (!r1.test(str) && r2.test(str));
}

function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}
