function openHTMLEditor(purl) {
 popupWin = window.open(purl,'htmleditor','width=720,height=530,scrollbars=yes,resizable=yes')
}

function titleFormSubmit(pbutton) {
   var vformaction = pbutton.value;
   var vyear1 = titleform.p_year1.value;
   var vyear2 = titleform.p_year2.value;
   var verr   = false;

   if (vformaction == 'Go') {
      if ((vyear1.length < 4) || (vyear2.length < 4)) {verr=true;}
      if (isNaN(vyear1) || isNaN(vyear2)) {verr=true;}
      if (((vyear1 % 1)!=0) || ((vyear2 % 1)!=0)) {verr=true;}
   }
   if (verr) {
      alert('Invalid year');
      return false;
   } else {
      titleform.p_formaction.value = vformaction;
      document.titleform.submit();
      return true;
   }
}

function admintitleFormSubmit(pbutton) {
   var vformaction = pbutton.value;
   titleform.p_formaction.value = vformaction;
   document.titleform.submit();
   return true;
}

function getCookieJS( check_name ) {
   var a_all_cookies = document.cookie.split( ';' );
   var a_temp_cookie = '';
   var cookie_name = '';
   var cookie_value = '';
   var b_cookie_found = false;
   
   for ( i = 0; i < a_all_cookies.length; i++ ) {
      a_temp_cookie = a_all_cookies[i].split( '=' );
      cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
      if ( cookie_name == check_name ) {
         b_cookie_found = true;
         if ( a_temp_cookie.length > 1 ) {
            cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
         }
         return cookie_value;
         break;
      }
      a_temp_cookie = null;
      cookie_name = '';
   }
   if ( !b_cookie_found ) {
      return null;
   }
}

function validateDateUS(p_date) {
   var vdate = p_date.split('/');
   var v_mm = "";
   var v_dd = "";
   var v_yy = "";
   
   if ((vdate[0] == "") || (vdate[1] == "") || (vdate[2] == "")) {
      return false;
   }
   
   if (vdate[0].length == 2) { v_mm = vdate[0]; }
   if (vdate[0].length == 1) { v_mm = "0" + vdate[0]; }
   
   if (vdate[1].length == 2) { v_dd = vdate[1]; }
   if (vdate[1].length == 1) { v_dd = "0" + vdate[1]; }
   
   if (vdate[2].length == 4) { v_yy = vdate[2]; }
   if (vdate[2].length == 2) { v_yy = "20" + vdate[2]; }
   
   if (parseInt(v_mm) > 12) {
      return false;
   }
   if (parseInt(v_dd) > 31) {
      return false;
   }
   if (isNaN(v_mm) || isNaN(v_dd) || isNaN(v_yy)) {
      return false;
   }
   if (((v_mm == "04" || v_mm == "06" || v_mm == "09" || v_mm == "11")) && (v_dd > 30)) {
      return false;
   }
   if ((v_mm == "02") && ((v_yy % 4) != 0) && (v_dd > 28)) {
      return false;
   }
   if (v_mm == "02") {
      if (((v_yy % 4) == 0) && (((v_yy % 100) != 0) || ((v_yy % 400) == 0)) && (v_dd > 29)) {
         return false;
      }
      if (((v_yy % 4) == 0) && (((v_yy % 100) == 0) && ((v_yy % 400) != 0)) && (v_dd > 28)) {
         return false;
      }
   }
   return true;
}

function displayImgWidth(pImgID) {
   var iwidth = $("#"+pImgID).attr('width');
   document.write(iwidth);
}

function displayImgHeight(pImgID) {
   var iheight = $("#"+pImgID).attr('height');
   document.write(iheight);
}

function setImgRatio(pImg, pW, pH) {
   var iwidth  = $("#"+pImg).attr('width');
   var iheight = $("#"+pImg).attr('height');
   if (iwidth > pW || iheight > pH) {
      if (iheight != iwidth) {
         if (pH > pW) {
            var vratio  = (iheight/iwidth);
            var neww    = pW;
            var newh    = (pW*vratio);
            if (newh > pH) {
               var vratio = ((newh/pH)-1);
               var vh = (newh - (newh*vratio));
               var vw = (neww - (neww*vratio));
               newh = vh;
               neww = vw;
            }
         } else {
            var vratio  = (iwidth/iheight);
            var newh    = pH;
            var neww    = (pH*vratio);
            if (neww > pW) {
               var vratio = ((neww/pW)-1);
               var vh = (newh - (newh*vratio));
               var vw = (neww - (neww*vratio));
               newh = vh;
               neww = vw;
            }
         }
      } else {
         if (pH > pW) {
            var neww = pW;
            var newh = pW;
         } else {
            var neww = pH;
            var newh = pH;
         }
      }
      $("#"+pImg).attr('width', neww);
      $("#"+pImg).attr('height', newh);
   }
}

function setImgHW(pImg, pW, pH) {
   var iwidth  = $("#"+pImg).attr('width');
   var iheight = $("#"+pImg).attr('height');
   if (pW != '' && pW > 0) {
      if (iwidth >= pW) {
         $("#"+pImg).attr('width', pW);
      }
   }
   if (pH != '' && pH > 0) {
      if (iheight >= pH) {
         $("#"+pImg).attr('height', pH);
      }
   }
}

