function validatecatsearch(type) {
/***************************************************************************/
/* Special Req's :- None                                                   */
/* Related Files :- None                                                   */
/* Purpose       :- Check data has been entered correctly                  */
/* Version       :- 1.00                                                   */
/* Author        :- Trevor McDermott                                       */
/* Date          :- 11/05/2003                                             */
/***************************************************************************/

var strthisformis

if (type == 'emptyorfull') {
  strthisformis = "frmadvcatsearch"
}

if (document.forms[strthisformis].cbocategory.value.length < 3) { 
 alert('Please select a category');
 document.forms[strthisformis].cbocategory.focus();
 return;
}

/* form is validated ok */
/* document.forms[strthisformis].submit()  */
document.location="imageresults.asp?category=" + document.forms[strthisformis].cbocategory.value
return;
}

/***************************************************************************/	
/* end of validatesearch.js                                                */
/***************************************************************************/

function validatesubcatsearch(type) {
/***************************************************************************/
/* Special Req's :- None                                                   */
/* Related Files :- None                                                   */
/* Purpose       :- Check data has been entered correctly                  */
/* Version       :- 1.00                                                   */
/* Author        :- Trevor McDermott                                       */
/* Date          :- 11/05/2003                                             */
/***************************************************************************/

var strthisformis

if (type == 'emptyorfull') {
  strthisformis = "frmadvcatsearch"
}

if (document.forms[strthisformis].cbocategory.value.length < 3) { 
 alert('Please select a category');
 document.forms[strthisformis].cbocategory.focus();
 return;
}

if (document.forms[strthisformis].cbosubcategory.value.length < 3) { 
 alert('Please select a category');
 document.forms[strthisformis].cbosubcategory.focus();
 return;
}

/* form is validated ok */
/* document.forms[strthisformis].submit()  */
document.location="imageresults.asp?category=" + document.forms[strthisformis].cbocategory.value + "&subcategory=" + document.forms[strthisformis].cbosubcategory.value
return;
}

/***************************************************************************/	
/* end of validatesearch.js                                                */
/***************************************************************************/


function validaterefcatsearch(type) {
/***************************************************************************/
/* Special Req's :- None                                                   */
/* Related Files :- None                                                   */
/* Purpose       :- Check data has been entered correctly                  */
/* Version       :- 1.00                                                   */
/* Author        :- Trevor McDermott                                       */
/* Date          :- 11/05/2003                                             */
/***************************************************************************/
/* Desc of Mod   :-                                                        */
/* Modified By   :-                                                        */
/* Date          :-                                                        */
/***************************************************************************/

var strthisformis

var horizontal
var vertical
var panoramic
var square
var propertyrelease
var modelrelease
var showcaptions
var imagesperpage

if (type == 'emptyorfull') {
  strthisformis = "frmadvcatsearch"
}

if (document.forms[strthisformis].cbocategory.value.length < 1) { 
 alert('Please select a photographer');
 document.forms[strthisformis].cbophotographer.focus();
 return;
}

if (document.forms[strthisformis].txtrefsearchterm.value.indexOf("'") > 0) { 
 alert('Please do not enter apostrophes in your refined search');
 document.forms[strthisformis].txtrefsearchterm.focus();
 return;
}

if (document.forms[strthisformis].txtrefsearchterm.value.indexOf("\"") > 0) { 
 alert('Please do not enter speech marks in your refined search');
 document.forms[strthisformis].txtrefsearchterm.focus();
 return;
}

if (! isvalidsearchstring(document.forms[strthisformis].txtrefsearchterm.value)) { 
 alert('Please only use letters numbers spaces and hyphens in your refined search');
 document.forms[strthisformis].txtrefsearchterm.focus();
 return;
}

if (document.forms[strthisformis].cbxhorizontal.checked){
         horizontal = 'yes'
}
else horizontal = "no"

if (document.forms[strthisformis].cbxvertical.checked){
         vertical = 'yes'
}
else vertical = "no"

if (document.forms[strthisformis].cbxpanoramic.checked){
         panoramic = 'yes'
}
else panoramic = "no"

if (document.forms[strthisformis].cbxsquare.checked){
         square = 'yes'
}
else square = "no"

if (document.forms[strthisformis].cbxpropertyrelease.checked){
         propertyrelease = 'yes'
}
else propertyrelease = "no"

if (document.forms[strthisformis].cbxmodelrelease.checked){
         modelrelease = 'yes'
}
else modelrelease = "no"

if (document.forms[strthisformis].cbxshowcaptions.checked){
         showcaptions = 'yes'
}
else showcaptions = "no" 

for (var i = 0; i < document.forms[strthisformis].imagesperpage.length; i++){
      if (document.forms[strthisformis].imagesperpage[i].checked){
         imagesperpage = document.forms[strthisformis].imagesperpage[i].value
			break
      }
   }

/* form is validated ok */
/* document.forms[strthisformis].submit()  */
document.location="imageresults.asp?category=" + document.forms[strthisformis].cbocategory.value + "&subcategory=" + document.forms[strthisformis].cbosubcategory.value + "&txtrefsearchterm=" + document.forms[strthisformis].txtrefsearchterm.value + "&horizontal=" + horizontal + "&vertical=" + vertical + "&panoramic=" + panoramic + "&square=" + square + "&propertyrelease=" + propertyrelease + "&modelrelease=" + modelrelease + "&showcaptions=" + showcaptions  + "&imagesperpage=" + imagesperpage
return;
}

/***************************************************************************/	
/* end of validatesearch.js                                                */
/***************************************************************************/


// isvalidsearchstring (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is English letters 
// (A .. Z, a..z) and numbers only.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function isvalidsearchstring (s) {   

	 var i;

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

/*		  alert(c)
		  alert( !(isLetter(c) || isDigit(c) || isSpace(c) || isHyphen(c) )) */
		  
        if (! (isLetter(c) || isDigit(c) || isSpace(c) || isHyphen(c) ))
        return false;
    }

    // All characters are numbers or letters.
    return true;
}

// Returns true if character c is a letter or digit.


// Returns true if character c is an English letter 
// (A .. Z, a..z).
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isSpace (c)
{   return ((c == " "))
}

function isHyphen (c)
{   return ((c == "-"))
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}
