/**
 * This function 
 *
 */
function getFavicon( nav ){
   var browser = new Array();
   var back = null;
   
   browser[0] = "Firefox";
   browser[1] = "Opera";
   browser[2] = "Chrome";
   browser[3] = "Kubuntu";
   browser[4] = "IE";
   browser[5] = "Safari";

   for(var i=0; i<browser.length; i++){
      if( nav.match(browser[i]) == "IE" ){
         back = '<link rel="shortcut icon" href="siteimgs/favicon.ico" />';
      } else{
         back = '<link rel="shortcut icon" href="siteimgs/favicon.jpg" />';
      }
   }

   return back;
}

/**
 *
 */
function setBrowserCSS(path, proname, nav){
   var browser = new Array();
   var back = null;
    
   browser[0] = "Firefox";
   browser[1] = "Opera";
   browser[2] = "Chrome";
   browser[3] = "Kubuntu";
   browser[4] = "IE";
   browser[5] = "Safari";

   for(var i=0; i<browser.length; i++){
       if( nav.match(browser[i]) ){
           back = "<link rel=\"stylesheet\" type=\"text/css\" href=\""+path+"css/"+proname+browser[i]+".css\" />";
       }
   }
  
   return back;
}

/**
 * 
 */
function getModHeight( minusHeight ){
   return screen.availHeight - minusHeight; 
}


/**
 * 
 */
function setModWidth( minWidth ){
   return screen.availWidth - minWidth;
}

/**
 * @param <integer> areaWidth The width (in pixels) of the area
 */
function halign( areaWidth ){
  return ( screen.availWidth - areaWidth ) / 2;
}


           /**
            * 
            */
           function Validator(){
              this.valid = true;
              this.form = null;
              this.elementName = null;
              this.value = null;
              
              this.setValid = function( valid ){
                 this.valid = valid;
              }
              this.getValid = function(){
                 return this.valid;
              }
              this.getForm = function(){
                 return this.form;
              }
              this.setForm = function( form ){
                 this.form = form;
              }
              this.getElementName = function(){
                 return this.elementName;
              }
              this.setElementName = function( elementName ){
                 this.elementName = elementName;
              }
              this.getValue = function(){
                 return this.value;
              }
              this.setValue = function( value ){
                 this.value = value;
              }
              
              this.validate = function(){
                 if( document.getForm().getElementName().getValue() == "" ){
                    window.alert( "Please fill in the box." );
                    this.setValid(false);
                 }
              }
           }
           
           /**
            * This class handles the 'MainBox' events.
            */
           function MainBoxOperator(){
              // this variable shows the opened box number (id).
              this.usedBox = -1;
              
              /**
               * To set the actually used box' id.
               * 
               * @param <Integer> id the id of the selected (clicked) box.
               */
              this.setUsedBox = function( id ){
                 this.usedBox = id;
              }
              
              /**
               * To get the actually used box' id.
               *
               * @param <Integer> id the id of used (opened) box.
               */
              this.getUsedBox = function(){
                 return this.usedBox;
              }
              
              /**
               * To open the main box
               *
               * @param <Integer> id the id of the actually opened box.
               */
              this.openMainBox = function(id){
                 if( getUsedBox() != -1 ){
                    closeMainBox( getUsedBox() );
                 }
                 document.getElementById(id).className =
                     document.getElementById(id).className.replace( /(?:^|\s)smallMains(?!\S)/ , 'bigMains' );
                 document.getElementById("arrowBox" + id).className =
                     document.getElementById("arrowBox" + id).className.replace( /(?:^|\s)(?!\S)/ , 'visibleArrows' );
                 document.getElementById("veilBox" + id).className =
                     document.getElementById("veilBox" + id).className.replace( /(?:^|\s)(?!\S)/ , 'visibleVeilBox' );
                 document.getElementById("picture" + id).className =
                     document.getElementById("picture" + id).className.replace( /(?:^|\s)picture(?!\S)/ , 'bigPicture' );

                 setUsedBox( id );
              }
              
              /**
               * To close the actually opened box.
               *
               * @param <Integer> id the id of the opened box -which will be closed.
               */
              this.closeMainBox = function( id ){
                 document.getElementById(id).className =
                    document.getElementById(id).className.replace( /(?:^|\s)bigMains(?!\S)/ , 'smallMains' );
                 document.getElementById("arrowBox" + id).className =
                    document.getElementById("arrowBox" + id).className.replace( /(?:^|\s)visibleArrows(?!\S)/ , '' );
                 document.getElementById("veilBox" + id).className =
                    document.getElementById("veilBox" + id).className.replace( /(?:^|\s)visibleVeilBox(?!\S)/ , '' );
                 document.getElementById("picture" + id).className =
                    document.getElementById("picture" + id).className.replace( /(?:^|\s)bigPicture(?!\S)/ , 'picture' );
              }
           }
           
           /**
            * This class 
            */
           function DataBaseOperations(){
              this.data = null;
              this.id = -1;
              
              /**
               * To get data from database using GET method.
               *
               * @param <String> fileName the whole path(relative || absolute) of the file which reads from / writes to the database.
               * @param <String> whereTo the id of the division where the gotten data has been put.
               */
              this.getData = function( fileName, whereTo){
                  var xmlhttp;
                  var where = whereTo;
                  if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                     xmlhttp=new XMLHttpRequest();
                  } else {// code for IE6, IE5
                     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                  }
                  xmlhttp.onreadystatechange = function() {
                     if (xmlhttp.readyState==4 && xmlhttp.status==200 && where != null) {
                        document.getElementById( where ).innerHTML=xmlhttp.responseText;
                     }
                  }
                  xmlhttp.open( "GET", fileName, true );
                  xmlhttp.send(null);
                  return xmlhttp.responseText;
              }
              
              /**
               *
               *
               *
               */
              this.setData = function( fileName, data ){
                 var xmlhttp;
                 if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                     xmlhttp=new XMLHttpRequest();
                 } else {// code for IE6, IE5
                     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                 }

                 xmlhttp.onreadystatechange=function() {
                     if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                        //document.getElementById("logo").innerHTML=xmlhttp.responseText;
                     }
                  }

                 xmlhttp.open( "GET", fileName+"?q="+data, true );
                 xmlhttp.send(null);
              }
              
              /**
               *
               *
               */
              this.postData = function( fileName, whereTo ){
                  var xmlhttp;
                  var where = whereTo;
                  //var parameters="name="+namevalue+"&age="+agevalue
                  if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                     xmlhttp=new XMLHttpRequest();
                  } else {// code for IE6, IE5
                     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                  }
                  xmlhttp.onreadystatechange = function() {
                     if (xmlhttp.readyState==4 && xmlhttp.status==200 && where != null) {
                        document.getElementById( where ).innerHTML=xmlhttp.responseText;
                     }
                  }
                  
                  xmlhttp.open("POST", fileName, true);
                  xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                  xmlhttp.send( null );
                  return xmlhttp.responseText;
              }
              
              /**
               *
               *
               */
              this.setPostData = function( fileName, whereTo, datas ){
                  var xmlhttp;
                  var where = whereTo;
                  var parameters="name="+namevalue+"&age="+agevalue
                  if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                     xmlhttp=new XMLHttpRequest();
                  } else {// code for IE6, IE5
                     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                  }
                  xmlhttp.onreadystatechange = function() {
                     if (xmlhttp.readyState==4 && xmlhttp.status==200 && where != null) {
                        document.getElementById( where ).innerHTML=xmlhttp.responseText;
                     }
                  }
                  
                  xmlhttp.open("POST", fileName, true);
                  xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                  xmlhttp.send(parameters);
              }
           }
