﻿/////////////////////////////// LOGIN ///////////////////////////////
function CheckLoginForm(objLoginButton, userNameFieldId, passwordFieldId, strDefaultUserNameTxt, strDefaultPasswordTxt)
{
  if(document.getElementById(userNameFieldId) == null)
    return;
  
  if(document.getElementById(passwordFieldId) == null)
    return;
    
  var userName = trim(document.getElementById(userNameFieldId).value);
  var password = trim(document.getElementById(passwordFieldId).value);
  
  var alertTxt = "";
  
  if(userName == strDefaultUserNameTxt || userName == "")
    alertTxt += "U dient uw gebruikersnaam in te vullen\n";
  
  if(password == strDefaultPasswordTxt || password == "")
    alertTxt += "U dient uw wachtwoord in te vullen\n";  
  
  if(alertTxt == "")
  {
    __doPostBack(objLoginButton, "");
    return true;
  }
  else
  {
    alert(alertTxt);
    return false;
  }  
}

function SetDefaultPassWordText(objPasswordField, strDefaultPasswordText)
{
  if(document.getElementById(objPasswordField) != null)
    document.getElementById(objPasswordField).value = strDefaultPasswordText;
}

function clearField(objTextBox, strDefaultText)
{
  if(objTextBox.value == strDefaultText)
    objTextBox.value = ""; 
}

function checkFieldCleared(objTextBox, strDefaultText)
{
  if(trim(objTextBox.value) == "")
    objTextBox.value = strDefaultText;
}

function IsEmail( emailStr) {
  var objRegExp  = /^[a-z]\w*([.\-]\w+)*@[a-z]\w*([.\-]\w+)*\.[a-z]{2,3}$/i;
  return objRegExp.test(emailStr);
}

function trim(inputString) {
   if (typeof inputString != "string") { return inputString; }
   if(inputString == "") {return inputString;}
   
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") {
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) {
   // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue;
}

/////////////////////////////// VALIDATION ///////////////////////////////
function IsNumeric(intStr)
{
    if(intStr == null || intStr == 'undefined')
        return false;

    if (intStr.match(/^[-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?$/))
        return true;
    else
        return false;
}

function IsEmail( emailStr) {
  var objRegExp  = /^[a-z]\w*([.\-]\w+)*@[a-z]\w*([.\-]\w+)*\.[a-z]{2,3}$/i;
  return objRegExp.test(emailStr);
}

/////////////////////////////// GALLERY ///////////////////////////////
var galleryCurrentPhoto = 0;

function ShowGallery()
{
  if(gallery != null)
  {
    if(gallery.images.length > 0)
    {
      document.getElementById('galleryImg').src = "Photos/" /*+ "thumb_"*/ + gallery.images[galleryCurrentPhoto].path;
      document.getElementById('galleryLink').href = "Photos/" + gallery.images[galleryCurrentPhoto].path;
      
      document.getElementById('galleryTotal').innerHTML = gallery.images.length;
    }
    for(gImg = 0; gImg < gallery.images.length; gImg++)
    {
      imageArray.push(new Array("Photos/" + gallery.images[gImg].path, ""));
    }
  }
  else
  {
    document.getElementById('gallery').style.display = "none";
  }
}

function PageGalleryImg(direction)
{
  if(galleryCurrentPhoto == 0 && direction == -1)
    return;
  if(galleryCurrentPhoto == (gallery.images.length - 1) && direction == 1)
    return;

  galleryCurrentPhoto += direction;
  
  document.getElementById('galleryCurrent').innerHTML = (galleryCurrentPhoto + 1);
  document.getElementById('galleryImg').src = "Photos/" /*+ "thumb_"*/ + gallery.images[galleryCurrentPhoto].path;
  document.getElementById('galleryLink').href = "Photos/" + gallery.images[galleryCurrentPhoto].path;
}

