//Webpage class
function clsWebpage ()

{
 this.IdHeaderDiv='WebpageHeader';
 this.AjaxConnection = new AJAXConnection('1');
  this.HeaderMenuElement=null;

 //----------------------------------------------------------
 this.SetHeaderBgImage = function (pImgUrl)
 //----------------------------------------------------------
    {
     var ElementHeader=document.getElementById(this.IdHeaderDiv);
     ElementHeader.style.backgroundImage=pImgUrl;
    }
 //----------------------------------------------------------
 this.ChangeLanguage = function (pNewLang)
 //----------------------------------------------------------
    {
    
    }
 //----------------------------------------------------------
 this.ShowMenu = function ()
 //----------------------------------------------------------
 {
   //this.HeaderMenuElement= new menu (this.HeaderMenuItems, this.HeaderMenuPositions);

 }
}

var ThisPage = new clsWebpage ();

var OrgbackgroundColor;
var Orgcolor;
var CurrentFocused;
var myWidth = 0, myHeight = 0;

var GxmlHttpReq = false;
var Browser="";

// Determine browser Mozilla/Safari
if (window.XMLHttpRequest) 
    {
    Browser="Mozilla";
    GxmlHttpReq = new XMLHttpRequest();
    //if (GxmlHttpReq.overrideMimeType) {
    //    GxmlHttpReq.overrideMimeType('text/html');       
    //    }
    }
else 
	if (window.ActiveXObject) 
  	{ // IE         
    try {GxmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
    	   Browser="Msxml2.XMLHTTP";
    	  }
    catch (e)
       {
       try {GxmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
       	    Browser="Microsoft.XMLHTTP";
       	   } 
       catch (e) {Browser="Geen";}
       }     
     } 
DetermineSize ();
var enddate = new Date("December 31, 2060");
document.cookie = "screenresolution="+ myWidth +"x"+ myHeight + ";expires=" + enddate.toGMTString();


//=====================================================
  function DetermineSize() {
//=====================================================
  
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
    }
  else
    if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
      //IE 6+ in 'standards compliant mode'
      myWidth = document.documentElement.clientWidth;
      myHeight = document.documentElement.clientHeight;
      }
    else
      if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
        }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
}

//=====================================================
// AJAXConnection class                           
//=====================================================
function AJAXConnection(name)
    {    
    this.className = 'AJAXConnection';
    this.name = name;
    
    this.xmlhttpPost = function (strURL, functionObj)
        {
    	var xmlHttpReq = false;
        var self = this;
        self.xmlHttpReq=GxmlHttpReq;
        
        if (!self.xmlHttpReq) 
            {
            alert('ERROR AJAX:( Cannot create an XMLHTTP instance');
            return false;
            }    
        
        self.xmlHttpReq.open('GET', strURL, false);
        self.xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        self.xmlHttpReq.onreadystatechange = function()
           { 
            //_callBackFunction(self.xmlHttpReq, functionObj); 
            
            if (self.xmlHttpReq.readyState == 4) 
              {
              if (self.xmlHttpReq.status == 200) 
                 {                
                  functionObj.callBackFunction(self.xmlHttpReq);
                 }
              else
            	   {
                 alert('ERROR: AJAX request status = ' + http_request.status);
                 }
              }
           }
        self.xmlHttpReq.send('');        
        }
      }

//=====================================================
// AJAX ShowAlert class                           
//=====================================================
function ShowAlertCallBack() 
  {	
  this.className = 'ShowAlertCallBack';
  this.callBackFunction = function(http_request )
     {
      str = http_request.responseText;
      alert(str);
     }
  }

//=====================================================
// AJAX ChangeInnerHtml class                           
//=====================================================
function ChangeInnerHtmlCallBack(pElementId) 
  {	
  this.className = 'ChangeInnerHtmlCallBack';
  this.ElementId = pElementId;
  this.callBackFunction = function(http_request )
     {
      str = http_request.responseText;
      //alert(Browser + this.ElementId);
      document.getElementById(this.ElementId).innerHTML = str; 
     }
  }
  
/** A AlertTemplate class */
function FieldValidatorCallBack() 
  {	
  this.className = 'FieldValidatorCallBack';
  this.callBackFunction = function(http_request )
     {
      str = http_request.responseText;
      //alert(Browser + str);

      try {
      	 var xmlDoc=document.implementation.createDocument("","",null);
         xmlDoc.async="false";
         xmlDoc.load("str");
        }
      catch (Error)
        { var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
          xmlDoc.async="false"
          xmlDoc.loadXML(str);
        }
      var x = xmlDoc.getElementsByTagName('Validation');
      //alert (x[0].childNodes.length);
      Result=0;
      ErrText='';
      FieldName='';
      for (j=0;j<x[0].childNodes.length;j++)
	      {
	    	FName = x[0].childNodes[j].nodeName;
	    	try {	    		
	    	  fc=x[0].childNodes[j].firstChild;	   
	    	  if (FName=="Result") Result=fc.nodeValue;
	    	  if (FName=="ErrTxt") ErrText=fc.nodeValue;	    	  
	    	  if (ErrText=="") ErrText = "No description";
	    	  if (FName=="Field") FieldName=fc.nodeValue;
	    	  }
	    	catch (err)
	    	  {ErrText='Error (1) : ' + err.description;
	    	   Result=1;    
          }	 
          
		    }
		 if (Result!= 0)
		      {
	        alert (ErrText);

	        try { var Elem = document.getElementById(FieldName);
        	      Elem.focus ();
	        	  }
	        catch (err)
	            {alert ('Error (2) : ' + err.description);
              }
	        }
     }    
  }
  
function Validate (pFieldName, pTable, pDbName, pAction, pSid)
 {
  var Elem = document.getElementById(pFieldName);
 
  // Initialize connections
  var ajaxFieldValidator = new AJAXConnection('FieldValidator');
  // Initialize templates 
  var FieldValidator=new FieldValidatorCallBack();
	// Show alertTest.txt file in alert window
  ajaxFieldValidator.xmlhttpPost('/mutto/base/Ajax/Validate.php?field=' + pFieldName +
                                 '&tbl=' + pTable +
                                 '&dbn=' + pDbName +
                                 '&act=' + pAction +
                                 '&sid=' + pSid +
                                 '&value=' + Elem.value , FieldValidator);     

 }
  
function SetFocus (Name)
  { CurrentFocused = Name;
  }
  
function BtnOver(pElement)
{
	
var Elem = document.getElementById(pElement);
if (Elem.currentStyle)
  {OrgbackgroundColor = Elem.currentStyle.backgroundColor;
   Orgcolor = Elem.currentStyle.color;
  }
else
  {OrgbackgroundColor = Elem.style.backgroundColor;
   Orgcolor = Elem.style.color;}

Elem.style.background="Gray";
Elem.style.color="yellow";
Elem.style.cursor='pointer'
}

function BtnOut(pElement)
{
var Elem = document.getElementById(pElement);
Elem.style.background = OrgbackgroundColor;
Elem.style.color      = Orgcolor;
}

function GoToURL(pURL)
{document.location= pURL;}

function FormSubmit (pFormId)

{var Elem = document.getElementById(pFormId);
 Elem.submit ();
}

function mHideElement (pId)
{ var oel = document.getElementById (pId);
      oel.style.display = "none"; /* hide the div with id divcontainer */
  }

function mShowElement (pId)
{ var oel = document.getElementById (pId);
      oel.style.display = ""; /* Show the div with id divcontainer */
  }

