//******************************************************************************
//	 * Title:        <br>
//	 * Description:  <br>
//	 * Copyright:    Copyright (c) 2004 Lance Software<br>
//	 * Company:      Lance Software<br>
//	 * @author       Florin Suciu<br>
//	 * @version      $Id: util.js,v 1.25 2004/05/15 07:37:45 Administrator Exp $<br>
//	 *
//	 * Date of creation:   28.11.2003<br>
//	 *
//	 * File:         $Source: F:\\sources/filter/travel/config/js/util.js,v $<br>
//	 * Modifier:     $Author: Administrator $<br>
//	 * Revision:     $Revision: 1.25 $<br>
//	 * State:        $State: Exp $<br>
//******************************************************************************

//replaceAll function.
String.prototype.replaceAll=function(s1, s2) {return this.split(s1).join(s2)}

// One object tracks the current modal dialog opened from this window.
// Generate a modal dialog.
//var win=null

function openDialog(url, name, w, h) {

          if (checkFocus()==1) {return 1}
          var left = (screen.availWidth - w) / 2
          var top = (screen.availHeight - h) / 2
          var attr = "left=" + left + ",top=" + top + ",resizable=no,scroll=no,status=no,titlebar=0,width=" + w + ",height=" + h
          // Generate the dialog and make sure it has focus.
          active=0
          win = window.open(url, name, attr)
          win.focus()

}

// Grab all Navigator events that might get through to form elements while
// dialog is open. For Internet Explorer, disable form elements.

function checkFocus() {

  if (window.win)
          { if (window.win.closed) {self.status="ii inchisa";return 0}
               else {self.status=" nu ii inchisa";return 1}
          }
  else { self.status="nu exista"; return 0}
    }

function setFocus() {

  if (window.win)
          { if (window.win.closed) {self.status="ii inchisa";self.focus()}
               else {self.status="nu ii inchisa"; win.focus()}
          }
          else { self.status="nu exista";self.focus()}
    }



/**************************
      END MODAL DIALOG CODE
**************************/

function download(){
           window.open('http://www.lance.ro/download/LanceLicensing/LanceLicensingDemo.exe');
}







function openWindow(action,frameName,widthValue,heightValue){
  openDialog(action, frameName, widthValue, heightValue)
}

function openSearchWindow(action){
     openDialog(action,"search",650,580)

     //showModalDialog(action, "", "dialogHeigh:580px;dialogWidth:650px;center:yes;scroll:no;resizable:no")
}

function doSearchAction()
{
     //alert("ok");
     document.searchForm.action="http://lance.ro/cgi-sys/entropysearch.cgi";
                       
    document.searchForm.submit();
}



function isEmpty(sir)
{
  jj=0;
  for(ii=0;ii<sir.length;ii++)
  {
    if (sir.charAt(ii)==" ")
     {jj++;}
    else
      {break;}
  }
  if (jj==sir.length)
   {return true;}
  else
   {return false;}
}


function check_form(form)
{
 return_boolean = true
 obj = eval(form)
 for(i=0;i<obj.length;i++)
 {
  field_name = obj.elements[i].name;
  if (field_name.indexOf("_ck") != -1)
  { if (isEmpty(obj.elements[i].value))
    {
      obj.elements[i].style.backgroundColor = "red";
      return_boolean = false
    }
    else
    {
      obj.elements[i].style.backgroundColor = "white";
    }
  }
  if (field_name.indexOf("_sp") != -1)
  { 
      obj.elements[i].value=trimAll(obj.elements[i].value);
      return_boolean=true;
  }
  if (field_name.indexOf("_int") != -1) {
    if (!checkInt(obj.elements[i].value))
    {
      obj.elements[i].style.backgroundColor = "lightgreen";
      return_boolean = false
    }
    else
    {
      obj.elements[i].style.backgroundColor = "white";
    }
  }
  if (field_name.indexOf("_eml") != -1) {

    if (!checkEmail(obj.elements[i].value))
      {
        obj.elements[i].style.backgroundColor = "yellow";
        alert("email="+obj.elements[i].value) 
        return_boolean = false

      }
      else
      {
        obj.elements[i].style.backgroundColor = "white";
      }

  }
  if (field_name.indexOf("_phone") != -1) {

    if (!checkPhone(obj.elements[i].value))
      {
        obj.elements[i].style.backgroundColor = "blue";
        return_boolean = false
      }
      else
      {
        obj.elements[i].style.backgroundColor = "white";
      }

  }
  if (field_name.indexOf("_fl") != -1) {

    if (!checkPozitiveFloat(obj.elements[i].value))
      {
	obj.elements[i].style.backgroundColor = "gray";
	return_boolean = false
      }
      else
      {
	obj.elements[i].style.backgroundColor = "white";
      }

  }
 }
return return_boolean;
}

function checkInt(value){
  var intValue;

  if (isEmpty(value)) return true;
  if(isNaN(value)) return false;
  intValue=parseInt(value);
  if(intValue.toString()==value) return true;
  else return false;
  }

function checkPhone(value){
  if (isEmpty(value)) return false;
  value=value.replaceAll('.','');
  value=value.replaceAll('-','');
  if(isNaN(value)) return false;
  else return true; 
} 

function checkPozitiveFloat(value){
if (isEmpty(value)) return true;
if(!checkFloat(value)) return false;
    return (parseFloat(value)>=0);
}

function checkFloat(value){
    if(isNaN(value)) return false;
	return true;
  }

function checkEmail(value)
     {
     // Return false if e-mail field is blank.
     if ((value.indexOf ('@',0) == -1) || (value.indexOf ('.',0) == -1))
        { return false;
        }
     // Return false if e-mail field does not contain a '@' and '.' .
     else
        {
        return true;
        }
   }


   //Check if the specified value contains apostrophe, quotation mark
function checkIsQuote(strVal)
  {
       if ((strVal.indexOf("'") == -1) && (strVal.indexOf('"') == -1))
         {
         return false;
         }
          else
          {
           return true;
          }
  }

function trimAll(sString)
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
}

function leftposition(){
     var left = (screen.availWidth - 800) / 2; 
      if (navigator.appName == "Netscape"){
          return left+26;
     } else if(navigator.appName == "ie"){
         return left;
     } else return left+26;
}

// * ***************************************************************************
// *
// * $Log: util.js,v $
// * Revision 1.25  2004/05/15 07:37:45  Administrator
// * fs
// *
// * ***************************************************************************

