//----------------------------------------------------------------------------
// Function for hiding content in a input text field 
//----------------------------------------------------------------------------

function OnJSFocus(element_name) {
  var vInput = document.getElementsByName(element_name);
  for(var i=0; i<vInput.length; i++) {
    if(vInput[i].type == 'text' || vInput[i].type == 'password') {
      vInput[i].setAttribute('rel', vInput[i].defaultValue)
      vInput[i].onfocus = function() {
        if(this.value == this.getAttribute('rel')) {
          this.value = '';
        } 
	else return false;
      }
      vInput[i].onblur = function() {
        if(this.value == '') {
          this.value = this.getAttribute('rel');
        } 
        else return false;
      }
      vInput[i].ondblclick = function() {
        this.value = this.getAttribute('rel');
      }
    }
  }
}
//----------------------------------------------------------------------------

function OnInit() {
 OnJSFocus('userid');
 OnJSFocus('pwd');
}
//----------------------------------------------------------------------------

if(document.childNodes) {
  window.onload = OnInit;
}

//----------------------------------------------------------------------------
// Gallery function
//---------------------------------------------------------------------------- 
var base64_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";  
//----------------------------------------------------------------------------
function base64_encode(data) {
  var Return = "";
  var Chr_1, Chr_2, Chr_3;
  var Enc_1, Enc_2, Enc_3, Enc_4;
  var i = 0; 
  do	{
      	  Chr_1 = data.charCodeAt(i++);
      	  Chr_2 = data.charCodeAt(i++);
      	  Chr_3 = data.charCodeAt(i++);
      	  
      	  Enc_1 = Chr_1 >> 2;
      	  Enc_2 = ((Chr_1 & 3) << 4) | (Chr_2 >> 4);
      	  Enc_3 = ((Chr_2 & 15) << 2) | (Chr_3 >> 6);
      	  Enc_4 = Chr_3 & 63;
      	  
	  if(isNaN(Chr_2)) Enc_3 = Enc_4 = 64; 
	  else if(isNaN(Chr_3)) Enc_4 = 64;
	  
	  Return += base64_key.charAt(Enc_1) + base64_key.charAt(Enc_2) + base64_key.charAt(Enc_3) + base64_key.charAt(Enc_4);
   	} 
  while(i < data.length);    
  return Return;
}
//----------------------------------------------------------------------------

function base64_decode(data) { /* Not used in this demo */
  var Return = "";
  var Chr_1, Chr_2, Chr_3;
  var Enc_1, Enc_2, Enc_3, Enc_4;
  var i = 0;
  data = data.replace(/[^A-Za-z0-9\+\/\=]/g, "");  
  do	{
	  Enc_1 = base64_key.indexOf(data.charAt(i++));
	  Enc_2 = base64_key.indexOf(data.charAt(i++));
	  Enc_3 = base64_key.indexOf(data.charAt(i++));
	  Enc_4 = base64_key.indexOf(data.charAt(i++));
	  
	  Chr_1 = (Enc_1 << 2) | (Enc_2 >> 4);
	  Chr_2 = ((Enc_2 & 15) << 4) | (Enc_3 >> 2);
	  Chr_3 = ((Enc_3 & 3) << 6) | Enc_4;
	  
	  Return += String.fromCharCode(Chr_1);
	  
	  if(Enc_3 != 64) Return += String.fromCharCode(Chr_2);
      	  if(Enc_4 != 64) Return += String.fromCharCode(Chr_3);
	}
  while(i < data.length);
  return Return;
}
//----------------------------------------------------------------------------

function loadGallery(id, data, str_width, str_height) {
  document.getElementById('gal_img').src = 'gallery/' + id + 'b.jpg';
  document.getElementById('gal_img').width = str_width;
  document.getElementById('gal_img').height = str_height;
  document.getElementById('gal_data').innerHTML = base64_decode(data);
}
//----------------------------------------------------------------------------

function galleryPopup(FileName, CSSFileName, ImageWidth, ImageHeight, Caption, ScrollBar) {
ClientWidth = ImageWidth + 240;
ClientHeight = ImageHeight + 240;
galWindow = window.open('','galWindow', 'width=' + ClientWidth + ',height=' + ClientHeight + ', scrollbars=' + ScrollBar + ', resizable=yes, left=' + ((window.screen.availWidth - ImageWidth) / 2) + ', top=' + ((window.screen.availHeight - ImageHeight) / 2));
galWindow.document.open();   
galWindow.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n');
galWindow.document.write('<html>\n');
galWindow.document.write('<head>\n');
galWindow.document.write('<meta http-equiv="Content-Type" content="text/html; charset="utf8">\n');
galWindow.document.write('<title>Gallery Preview</title>\n'); 
galWindow.document.write('<link href="res/stylesheet.css" rel="stylesheet" type="text/css">\n');
galWindow.document.write('<link href="css/' + CSSFileName + '" rel="stylesheet" type="text/css">\n');      
galWindow.document.write('</head>\n');
galWindow.document.write('<body class="galleryPopup" onBlur="self.close()">\n');
galWindow.document.write('<p><img class="galleryPopup" src="' + FileName + '" alt="" width="' + ImageWidth + '" height="' + ImageHeight + '"></p>\n');
galWindow.document.write('<p style="padding-top:16px;"><span class="galleryPopup">' + base64_decode(Caption) + '</span></p>\n');
galWindow.document.write('<p style="padding-top:16px; text-align:center;"><a class="galleryPopup" href="javascript:window.close();" title="Close Window">Close Window</a></p>\n');
galWindow.document.write('</body>\n');
galWindow.document.write('</html>');
galWindow.document.close();
galWindow.focus();
}
//---------------------------------------------------------------------------- 
// Gallery function (END)
//----------------------------------------------------------------------------
