function CheckWindow() {
    if (typeof(NWindow) != 'undefined') {
        NWindow.close();
    }
}

function NewWin(s,w,h) {
    NWindow = window.open(s, 'NWindow','alwaysRaised=yes,dependent=yes,hotkeys=no,personalbar=no,status=no,titlebar=no,menubar=no,toolbar=no,width='+w+',height='+h+',scrollbars=no');
    NWindow.focus();
}

function Trim(s) {
    while (s.charCodeAt(0) == 32 || s.charCodeAt(0) == 13 || s.charCodeAt(0) == 10) {s = s.slice(1)}
    while (s.charCodeAt(s.length - 1) == 32 || s.charCodeAt(s.length - 1) == 13 || s.charCodeAt(s.length - 1) == 10) {s = s.slice(0,s.length - 1)}
    return s;
}

function CheckVals(frm,arrV) {
   var DoIt = true;
   if (arguments[2] > '') {
      var errmsg = arguments[2];
   } else {
      var errmsg = 'You have not completed all the required fields !';
   }
   for (var i=0;i<arrV.length;i++) {
      var Required = false;
      var p = arrV[i].split(':');
      var p1 = p[0];
      var p2 = '';
      var p3 = '';
      var p4 = '';
      if (p.length > 1) {p2 = p[1]}
      if (p.length > 2) {p3 = p[2]}
      if (p.length > 3) {p4 = p[3]}
      var o = eval('document.'+frm.name+'.'+p1);
      var v = Trim(o.value);
      if (p3 == '1') {Required = true}
      if ((Required) && (v <= '')) {DoIt = false}
      if (DoIt) {
         switch (p2.toUpperCase().slice(0,3)) {
         case 'EMA':
            if (v.length > 0) {
               if (v.indexOf('@',0) == -1 || v.indexOf('.',0) == -1) {
                  if (p4 == '') {errmsg = 'You have not entered a valid e-mail address. Please try again!'} else {errmsg = p4}
                  DoIt = false;
               }
            }
            break;
         case 'TEL':
            if (v.length > 0) {
               for (j=0;j<v.length;j++) {
                  var c = v.charAt(j);
                  if (((c >= '0') && (c <= '9')) || (c == ' ') || (c == '+') || (c == '-') || (c == ')') || (c == '(')) {
                  } else {
                     if (p4 == '') {errmsg = 'You have not entered a valid phone number. Please try again!'} else {errmsg = p4}
                     DoIt = false
                  }
               }
            }
            break;
         case 'PRI':
            if (v.length > 0) {
               if (isNaN(v)) {
                  if (p4 == '') {errmsg = 'You have not entered a valid price. Please try again!'} else {errmsg = p4}
                  DoIt = false
               }
            }
            break;
         case 'NUM':
            if (v.length > 0) {
               if (isNaN(v)) {
                  if (p4 == '') {errmsg = 'You have not entered a valid number. Please try again!'} else {errmsg = p4}
                  DoIt = false
               }
            }
            break;
         case 'DAT':
            if (v.length > 0) {
               d = Date.parse(v)
               if (isNaN(d)) {
                  if (p4 == '') {errmsg = 'You have not entered a valid date. Please try again!'} else {errmsg = p4}
                  DoIt = false
               }
            }
            break;
         }
      }
      if (!DoIt) {
         alert(errmsg);
         o.focus();
         o.select();
         return false
      }
   }
   return true;
}

function TextChange(obj, str) {
    if (document.all) {
        document.getElementById(obj).innerText = str;
    } else {
        document.getElementById(obj).textContent = str;
    }
}

function DoHi(ids) {
    document.getElementById(ids).style.backgroundColor='#f3f3f3';

}

function DoLo(ids) {
    document.getElementById(ids).style.backgroundColor='#ffffff';
}



