﻿/*
  Initialise Namespace
*/

if(typeof(Type) !== 'undefined') {
  Type.registerNamespace("PH.DrawPictures");
}
else {
  PH = function() {}
  PH.TheSmalls = function() {}
}

/*
  Check if the form should be submitted when enter key pressed.
*/
function checkSubmit(e, linkButton) {
  var charCode;
  if(window.event) { 
    charCode = e.keyCode;
  } else if(e.which) {
    charCode = e.which;
  }

  if (charCode==13) {
    __doPostBack(linkButton, '');
    return false;
  } else {
    return true;
  }
}

/*
  Set the rating image to the image specified
*/
function setRating(value) {
  var oImage;
  var sImage;
  oImage = document.getElementById('ratingimg');
  sImage = oImage.src;
  sImage = sImage.substring(0, sImage.length - 5) + value + '.gif';
  oImage.src = sImage;
  return true;
}

/*
  Check if the form should be submitted when enter key pressed.
*/
function checkSearchSubmit(e, sSearchUrl) {

  var charCode;
  if(window.event) { 
    charCode = e.keyCode;
  } else if(e.which) {
    charCode = e.which;
  }

  if (charCode==13) {
    searchSmalls(sSearchUrl);
    return false;
  } else {
    return true;
  }
}

/*
  Appends to the search URL the search terms, and redirects.
*/
function searchSmalls(sSearchUrl) {
  var sTerms = "";
  var oSearchTerms = document.getElementById('oSearchTerms');
  var oSearchComments = document.getElementById('oSearchComments');
 
  for (i=0;i<oSearchTerms.value.length;i++) {
		if (oSearchTerms.value.charAt(i) == " ") sTerms += "+";
		else sTerms += oSearchTerms.value.charAt(i);
	}

  sSearchUrl += "?terms=";
  sSearchUrl += escape(sTerms);

  if (oSearchComments.checked) {
    sSearchUrl += "&comments=1"
  }
  
  window.location.href = sSearchUrl
}

/*
  Sub Menu Mouse Over
*/
function subMenuOver(anchor) {
  anchor.firstChild.src = anchor.firstChild.src.replace(".ashx","Over.ashx");
}

/*
  Sub Menu Mouse Over
*/
function subMenuOut(anchor) {
  anchor.firstChild.src = anchor.firstChild.src.replace("Over.ashx",".ashx");
}

/*
  Validates if file name has valid extension
*/
function fileValidateExtension(file, files) {
  if (files.length == 0 || file.length <= 0) {
    return true;
  }

  var sFileArray = files.toLowerCase().split(",");
  var bFileFound = false;

  var sExtension = file.toLowerCase();
  while (sExtension.indexOf('.') > 0) {
    sExtension = sExtension.substring(sExtension.indexOf('.') + 1);
  }
  
  for (var i=0;i<sFileArray.length;i++) {
    if (sExtension == sFileArray[i]) {
      bFileFound = true;
      break;
    }
  }

  return bFileFound;
}

/*
  Writes a flash object to the container.
*/
PH.TheSmalls.ShowFlash = function(ID, Path, Width, Height) {
  var oContainer = document.getElementById(ID);
  var sOutput = '';

  if(navigator.appName.indexOf("Microsoft") != -1) {
    sOutput = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+Width+'" height="'+Height+'"><param name="movie" value="'+Path+'" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="allowscriptaccess" value="true" /><param name="swliveconnect" value="true" /></object>'
  } else {
    sOutput = '<embed src="'+Path+'" width="'+Width+'" height="'+Height+'" quality="high" wmode="transparent" allowScriptAccess="true" swLiveConnect="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash"></embed>'
  }

  oContainer.innerHTML = sOutput;
}
