function checkKey()
{
   if ((window.event.ctrlKey) && (window.event.keyCode==10))
       document.frm.submit();
}
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
function storeCaret ( txtobj ) 
{  
   if (document.all[txtobj].createTextRange) 
       document.all[txtobj].caretPos = document.selection.createRange().duplicate();
}
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
function insertAtCaret (text, txtobj) 
{
   if (document.all[txtobj].createTextRange && document.all[txtobj].caretPos) 
   {
      var caretPos  = document.all[txtobj].caretPos;
      caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + '' : text;
   }
   else
       document.all[txtobj].value  += text;
   
   document.all[txtobj].focus();
}
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
function ins_format(open_tag, close_tag, txtobj )
{
    var format_text = document.selection.createRange().text;
    if (format_text != '')
         insertAtCaret (open_tag + format_text + close_tag, txtobj );
    else alert('Select a portion of text!!!');

}
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
function ins_image()
{
    winImg = window.open ("",
                          "StorageImgWindow",
                          "dependent=yes,toolbar=no,scrollbars=yes,status=no,menubar=no,resizable=yes,width=600,height=400,top=10,left=10");
    winImg.document.location="/Storage/Storage.php";
    winImg.focus();
}


//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
function ins_link()
{
        var linkURL  = prompt("Enter the complete URL for the link you wish to add.", "http://");
    var linkText = document.selection.createRange().text;
    if (linkURL)
    {
        if (linkText == '')
            linkText = prompt("Enter the title of the web page you wish to reference", "");
        if (!linkText)
            linkText = linkURL

        insertAtCaret ("[LINK]" + linkURL + "[/LINK]" + linkText + "[/ENDLINK]");
    }
}


//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------

function ins_smile(SmileCod)
{
  insertAtCaret (SmileCod);
}

//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------

function validateString( userid )
{
        var regexp=/\W/;

        if (regexp.test(userid))
        {
            return false;
        }
        else
        {
            return true;
        }
}
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
function validateNumber( some_number )
{
        var regexp=/\d/;

        if (regexp.test( some_number ))
        {
            return true;
        }
        else
        {
            return false;
        }
}
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
function ltrim(s) {
   var count=0;
   var i = 0;
   var space = " ";
   var newLine="\n";
   var cr = "\r";
   var tab = "\t";
   var sRet;

   if( s == '' )
     return '';
     
   while (
      (s.charAt(i) == space) |
      (s.charAt(i) == newLine) |
      (s.charAt(i) == cr) |
      (s.charAt(i) == tab)){
      count++;
      i++
    }

   if (count > 0)
      sRet = s.substring(count, s.length);
   return(sRet);
}
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------

function rtrim(s) {
   var count=0;
   var i;
   var space = " ";
   var newLine="\n";
   var cr = "\r";
   var tab = "\t";
   var sRet;

   if( s !== ' ' )
     return s;

   i = s.length - 1  
   while (
      (s.charAt(i) == space) |
      (s.charAt(i) == newLine) |
      (s.charAt(i) == cr) |
      (s.charAt(i) == tab)) {
      count++;
      i--
   }
   if (count > 0)
      sRet = s.substring(0, s.length - count);

   return(sRet);
}
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------

function trim(s) {
   return(rtrim(ltrim(s)));
}
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
function demoTicket()
            {
              var rVal;
              rVal = window.showModalDialog( 'demo_ticket.php',null,'DialogHeight:600px;DialogWidth:800px;help:no;status:no' );
              ans_amount = rVal.substring(0, 1);
              ans_time   = rVal.substring( 1, rVal.length - 1 );
              ans_time = 4000 - ans_time;
              rVal = window.showModalDialog( 'demo_results.php?ans_amount=' + ans_amount + '&ans_time=' + ans_time,null,'DialogHeight:600px;DialogWidth:800px;help:no;status:no' );
            }
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------

function validEmail ( email )
{
  var re_email = new RegExp("^\[^@\t< ]+@\[^@.\t]+(\.\[^@.\n> ]+)+$","g");
  if (!re_email.test( email ))
  {
     return false
  }
  else
  {
     return true
  }
}
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------

     function isAlphabeticEng(theField)
 {
       inStr = theField;
        inLen = inStr.length;
           for(var i=0; i<inLen; i++) {
                var ch = inStr.substring(i,i+1)
                if (  (ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) && (ch < "0" || "9" < ch) && ch != " ")
                         return false;
            }
        return true;
}
//-----------------------------validateStringLetters

     function validateStringLetters(theField)
 {
       inStr = theField;
        inLen = inStr.length;
           for(var i=0; i<inLen; i++) {
                var ch = inStr.substring(i,i+1)
                if (  (ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) )
                         return false;
            }
        return true;
}
