//function togles between two images names [imageName].[extension] and [imageName]_active.[extension] to do a mouse over effect
function toggleOverImage(theElement, bolInitialStatusActive) {
  if(!bolInitialStatusActive) {
    if(theElement.src.indexOf('_active.') > 0) {
      theElement.src = theElement.src.substring(0, theElement.src.indexOf('_active.')) + theElement.src.substring(theElement.src.length - 4, theElement.src.length);
    } else {
      theElement.src = theElement.src.substring(0, theElement.src.lastIndexOf('.')) + '_active' + theElement.src.substring(theElement.src.length - 4, theElement.src.length);
    }
  }
}


function activateTab(strTabActive, strTabGroup){
  
  //hide all tabs from tab group
  var arrTabGroup = strTabGroup.split(', ');
  
  for (var i=0; i<arrTabGroup.length; i+=1) {
    document.getElementById('tabbox_' + arrTabGroup[i]).style.display = "none";    
    document.getElementById('tab_' + arrTabGroup[i]).className = "";
  }
  
  //show active tab
  document.getElementById('tabbox_' + strTabActive).style.display = "block";
  document.getElementById('tab_' + strTabActive).className = "active";
  
  return false;
}


function setFocusToField(strField){
  if(document.getElementById(strField)) document.getElementById(strField).focus();
}

function extSearchReset() {
  //document.getElementById('SearchPhotoInput').value = document.getElementById('SearchPhotoInput').title;
  //document.getElementById('SearchPhotoInputExt').value = document.getElementById('SearchPhotoInputExt').title;

  document.getElementById('SearchPhotoID').value = "";
  document.getElementById('SearchPhotoFilename').value = "";
  document.getElementById('SearchPhotoUserName').value = "";

  document.getElementById('SearchPhotoFormatSquare').checked = false;
  document.getElementById('SearchPhotoFormatPortrait').checked = false;
  document.getElementById('SearchPhotoFormatLandscape').checked = false;
  document.getElementById('SearchPhotoFormatPanorama').checked = false;

  document.getElementById('SearchPhotoWidth').value = document.getElementById('SearchPhotoWidth').title;
  document.getElementById('SearchPhotoHeight').value = document.getElementById('SearchPhotoHeight').title;
  document.getElementById('SearchPhotoResUnit').selectedIndex = 0;

  $$('.dpi').each(function(item) {
    item.style.color = '#CDCED0';
    $(item.htmlFor).checked = false;
    $(item.htmlFor).disabled = true;
  });

  document.getElementById('SearchPhotoColormodeColor').checked = false;
  document.getElementById('SearchPhotoColormodeBlackAndWhite').checked = false;

  document.getElementById('SearchPhotoExtendedLicence').checked = false;

  if(document.getElementById('catselectId').value != ""){
    document.getElementById('catselectId').value = "";
    _cs.setSelection("");
  }

  cs1_delete_color();

}


function kmSmRemoveSelectedPhotos() {
  //count selected photos
  var intPhotosSelected = 0

  $$('.PhotoFormCheckbox').each(function(item) {
      if (item.checked) {
        intPhotosSelected += 1;
      }
  });

  if (intPhotosSelected == 0) {
    alert("No photos selected.");

  }	else if (confirm("Remove " + intPhotosSelected + " photo(s) from search result?")) {
		document.getElementById('PhotoForm').action = 'keywordmanager.asp?m=photoremovekeyworddo&search=' + getQueryVariable('search') + '&p=' + getQueryVariable('p');
    document.getElementById('PhotoForm').submit();
	}

}

function custDlcUpdate(elmt, strCurrency, dblRate) {
  if (!document.getElementById) return;

  //we round everything to full euro always. just looks better.

  var intCredit = parseInt(elmt.value);

  if (isNaN(intCredit) || intCredit < 100 || intCredit > 1000) {
    document.getElementById('custDlcPrice').innerHTML = '-';
    document.getElementById('custDlcDiscount').innerHTML = '-';

  }else{
    var intLowCredit = 100;
    var intLowDiscount = 10;

    var intHighCredit = 1000;
    var intHighDiscount = 20;

    //calculate anb round discount
    var dblRel = (intHighDiscount - intLowDiscount) / (intHighCredit - intLowCredit);
    var dblDiscount = dblRel * intCredit + intHighDiscount - dblRel * intHighCredit;
    dblDiscount = Math.round(dblDiscount);
    
    
    //caculate discount amount and final price    
    var dblPriceDiscount = (dblDiscount / 100) * intCredit;
    var dblPrice = (intCredit - dblPriceDiscount);
    
    
    //exchange currency if not euro
    if(strCurrency == 'Dollar') {
      dblPrice = dblPrice * dblRate;
      dblPriceDiscount = dblPriceDiscount * dblRate;
    }    
    
    //round final price and discount    
    dblPrice = Math.round(dblPrice);
    dblPriceDiscount = Math.round(dblPriceDiscount);
    

    //format currency
    dblPrice = new String(dblPrice);
    dblPriceDiscount = new String(dblPriceDiscount);
    dblDiscount = new String(dblDiscount);    

    if(dblPrice.indexOf('.') < 0) { dblPrice += '.00'; }
    if(dblPrice.indexOf('.') == (dblPrice.length - 2)) { dblPrice += '0'; }
    
    if(dblPriceDiscount.indexOf('.') < 0) { dblPriceDiscount += '.00'; }
    if(dblPriceDiscount.indexOf('.') == (dblPriceDiscount.length - 2)) { dblPriceDiscount += '0'; }

    if(strCurrency == 'Euro') {
      dblPrice.replace('.', ',');
      dblPriceDiscount.replace('.', ',');

      dblPrice = dblPrice + ' ' + '€';
      dblPriceDiscount = dblPriceDiscount + ' ' + '€';
      dblDiscount = dblPriceDiscount + ' (' + dblDiscount + '%)';

    } else if(strCurrency == 'Dollar') {
      dblPrice = dblPrice + ' ' + '$';
      dblPriceDiscount = dblPriceDiscount + ' ' + '$';      
      dblDiscount = dblPriceDiscount + ' (' + dblDiscount + '%)';

    } else {
      //unsupported currency
      dblPrice = '-';
      dblDiscount = '-';
    }

    document.getElementById('custDlcPrice').innerHTML = dblPrice;
    document.getElementById('custDlcDiscount').innerHTML = dblDiscount;
  }
}


function licSelect() {
  if (!document.getElementById) return;

  $$('.licenceSize').each(function(item) {
      if (item.getElementsByTagName('input')[0].checked) {
        item.className = 'licenceSize licenceSizeActive clearfix';
      }else{
        item.className = 'licenceSize clearfix';
      }
  });
}

function extLicSelect(elmt) {
  if (!document.getElementById) return;

  if (elmt.checked) {
    elmt.parentNode.className = 'extendedLicence extendedLicenceActive';
  }else{
    elmt.parentNode.className = 'extendedLicence';
  }
}

function licSelectionInit() {
  if (!document.getElementById) return;

  $$('.licenceSize').each(function(item) {
    if (item.getElementsByTagName('input')[0].checked) {
      item.className = 'licenceSize licenceSizeActive clearfix';
    }else{
      item.className = 'licenceSize clearfix';
    }
  });

  $$('.extendedLicence').each(function(item) {
    if (item.childNodes[1].checked) {
      item.className = 'extendedLicence extendedLicenceActive';
      ToggleBlock('ExtendedLicence');
      document.getElementById('ExtendedLicenceOn').style.display = "block";
      document.getElementById('ExtendedLicenceOff').style.display = "none";
    }else{
      item.className = 'extendedLicence';
    }
  });
}

function CounrySelectionInit(objList) {
  if (!document.getElementById) return;

	objList = document.getElementById(objList)
  objList.onchange = function(){CountrySelectionOnClick(this.options[this.selectedIndex]);}
  objList.onkeypress = function(){CountrySelectionOnClick(this.options[this.selectedIndex]);}

  for (var i = 0; i < objList.options.length; i++) {
    if (objList.options[i].selected) {
      objList.options[i].parentNode.style.backgroundImage = objList.options[i].style.backgroundImage;
    }
  }
}

function CountrySelectionOnClick(e){
  //e.parentNode.setAttribute('style', e.parentNode.getAttribute('style') + e.getAttribute('style')); fahne wurde beim ersten klick nicht angezeigt. erst beim zweiten
  e.parentNode.setAttribute('style', e.getAttribute('style'));
  e.parentNode.style.backgroundRepeat = 'no-repeat';
  e.parentNode.style.backgroundPosition = '2px 50%';
  e.parentNode.style.padding = '0 0 0 22px';
  //if (e.text == '') e.parentNode.style.backgroundImage = 'none'; ist nicht mehr nötig als das erste oben entfernt wurde
}


function LanguageSelectionInit(objList) {
  if (!document.getElementById) return;
  if (!document.getElementById(objList)) return;

  objList = document.getElementById(objList)
  objList.onchange = function(){LanguageSelectionOnClick(this.options[this.selectedIndex]);}
  objList.onkeypress = function(){LanguageSelectionOnClick(this.options[this.selectedIndex]);}

  for (var i = 0; i < objList.options.length; i++) {
    if (objList.options[i].selected) {
      objList.options[i].parentNode.style.backgroundImage = objList.options[i].style.backgroundImage;
    }
  }
}

function LanguageSelectionOnClick(e){
  e.parentNode.setAttribute('style', e.parentNode.getAttribute('style') + e.getAttribute('style'));
  e.parentNode.style.backgroundRepeat = 'no-repeat';
  e.parentNode.style.backgroundPosition = '4px 60%';
  e.parentNode.style.padding = '0 0 0 20px';
  if (e.text == '') e.parentNode.style.backgroundImage = 'none';
}


function htmlspecialchars(text){
  if(typeof(text)=='undefined'||!text.toString){
    return'';
  }
  if(text===false){
    return'0';
  }else if(text===true){
    return'1';
  }
  return text.toString().replace(/&/g,'&amp;').replace(/"/g,'&quot;').replace(/'/g,'&#039;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
}


//fills the contest count down box
function ContestGetCount(theDate, theCountbox) {
  if (!document.getElementById(theCountbox)) return;

	var dateNow = new Date(); //grab current date
	var dateFuture = new Date(theDate); //"Month Day, Year Hour:Minute:Second"
	var amount = dateFuture.getTime() - dateNow.getTime(); //calc milliseconds between dates
	delete dateNow;

	// time is already past
	if(amount < 0){
		document.getElementById(theCountbox).innerHTML="Finish";
	}
	// date is still good
	else{
		days=0;hours=0;mins=0;secs=0;out="";

		amount = Math.floor(amount/1000); //kill the "milliseconds" so just secs

		days=Math.floor(amount/86400);
		amount=amount%86400;

		hours=Math.floor(amount/3600);
		amount=amount%3600;

		mins=Math.floor(amount/60);
		amount=amount%60;

		secs=Math.floor(amount);

//		if(days != 0){out += days +" day"+((days!=1)?"s":"")+", ";}
//		if(days != 0 || hours != 0){out += hours +" hour"+((hours!=1)?"s":"")+", ";}
//		if(days != 0 || hours != 0 || mins != 0){out += mins +" minute"+((mins!=1)?"s":"")+", ";}
//		out += secs +" seconds";

    days = days.toString();
		if (days.length == 1) days = '0' + days

		hours = hours.toString();
		if (hours.length == 1) hours = '0' + hours

		mins = mins.toString();
		if (mins.length == 1) mins = '0' + mins

		secs = secs.toString();
		if (secs.length == 1) secs = '0' + secs

		out = days + ":" + hours + ":" + mins + ":" + secs

		document.getElementById(theCountbox).innerHTML = out;

		setTimeout("ContestGetCount('" + theDate + "', '" + theCountbox + "')", 1000);
	}
}


function ShowSimilarPhotos() {
  var theForm = document.FormSearchByKeywordselection;

  for (i=0,n=theForm.elements.length;i<n;i++) {
    if (theForm.elements[i].name.indexOf('Keyword_') == 0) theForm.elements[i].checked = true;
  }

  theForm.ShowAllSimilar.value = 'True';
  theForm.submit();
}


//returns a random alphanumeric password of specified length
function randomPassword(length)
{
  chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  pass = "";
  for(x=0;x<length;x++)
  {
    i = Math.floor(Math.random() * 62);
    pass += chars.charAt(i);
  }
  return pass;
}


//returns querystring value by name
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
}


//returns a random 8 digit alphanumeric string
function GetRandomString() {
  var intLength = 8;
  var strCharList = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"
  var strRandom = "";


  for (i=1; i<=intLength; i++) {
    strRandom = strRandom + strCharList.substr(Math.round(Math.random() * strCharList.length +1), 1);
  }

  return strRandom;
}


//submit form and disable submit button
function FormSubmit(target) {
  var objButton = document.getElementsByName('Submit');
  objButton.disabled = true;
  return true;
}

function SetFormActionAndSubmit(theForm, theAction) {
  theForm.action = theAction;
  theForm.submit();
}

function ChatStartTimer() {
  setTimeout("ChatCheckRefresh()",5000)
}

function ChatCheckRefresh() {
  if(document.ChatForm.Message.value == '') {
   document.location.href = document.location.href;
  }
  setTimeout("ChatCheckRefresh()",5000)
}


//opens the uplaod status window
function ShowUploadStatus(intUploadID) {
  window.open('progressbar.asp?ID=' + intUploadID, 'win' + intUploadID, 'width=500,height=140');
  return true;
}


//preview a image file selected via file selection form element. works in ie only.
function PreviewImg(el) {
	var filename = el.value;
	var Img = new Image();

	Img.src = filename;
	Img.onload = function() {
	  if(this.width >= this.height) {
  	  this.height *= 164 / this.width;
  	  this.width = 164;
  	}else{
  	  this.width *= 164 / this.height;
  	  this.height = 164;
    }

  	document.PhotoPreview.src = this.src;
  	document.PhotoPreview.height = this.height;
  	document.PhotoPreview.width = this.width;
	}

  Img = null;
}


//replaces the html standard file uplaod with a custom one
function myFileUpload(strImagePath) {
	if (!(document.createElement && document.getElementsByTagName)) return;

	//inspired by http://www.quirksmode.org/dom/inputfile.html

	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'inputFileFake';

	var fakeFileUploadInput = fakeFileUpload.appendChild(document.createElement('input'));
	fakeFileUploadInput.className = 'inputFile';

	var image = document.createElement('img');
	image.src= strImagePath + 'btn_selectphoto.gif';
	fakeFileUpload.appendChild(image);

	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].getAttribute('noscript')) continue;
		if (x[i].parentNode.className != 'myFileinput') continue;
		x[i].className = 'inputFileHidden';
		x[i].style.filter = 'alpha(opacity=0.01)'; //added for ie8
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
	}
}


function ShowUploadPreview() {
  var ie = (navigator.userAgent.indexOf('MSIE') > -1) ? 1 : 0;

  if(ie) {
    var myElem = document.getElementById("UploadPreview");
    myElem.style.display = 'block'

    var myElem = document.getElementById("UploadPreviewForm");
    myElem.className = 'boxSubcolumnRight'
  }
}


function AjaxUpdateImageThumb2(strThumbPath, strImageElementID)
{
  new Ajax.Request(strThumbPath,
		{
			method: 'get',
			onSuccess: function(transport)
			{
			  //alert('Found ' + strThumbPath);
			  //	set the thumbnail
  			var e = document.getElementById(strImageElementID);
  			e.src = strThumbPath;

			  return true;
			},
			onFailure: function(transport)
			{
				//alert('Not found ' + strThumbPath);
				setTimeout("AjaxUpdateImageThumb2('" + strThumbPath + "', '" +  strImageElementID + "')", 3000);
				return true;
			}
		});
}


function OpenExifViewer(strURL) {
  winExifViewer = window.open(strURL, 'winExifViewer', 'location=yes,status=yes,toolbar=yes,menubar=yes,scrollbars=yes,width=400,height=530');
  winExifViewer.focus();
}

function OpenSmilies(strURL) {
  winExifViewer = window.open(strURL, 'winSmiles', 'location=yes,status=yes,toolbar=yes,menubar=yes,scrollbars=yes,width=400,height=350');
  winExifViewer.focus();
}

function OpenLightbox(strURL) {
  winLightbox = window.open(strURL, 'winLightbox', 'location=yes,resizable=yes,status=yes,toolbar=yes,menubar=yes,scrollbars=yes,width=640,height=530');
  winLightbox.focus();
}

function OpenChat(strURL, strWindowname) {
  winChat = window.open(strURL, strWindowname, 'location=yes,resizable=yes,status=yes,toolbar=yes,menubar=yes,scrollbars=yes,width=640,height=530');
  winChat.focus();
}

function OpenKeywordViewer(strURL) {
  winKV = window.open(strURL, 'winKV', 'location=yes,status=yes,toolbar=yes,menubar=yes,scrollbars=yes,width=400,height=530');
  winKV.focus();
}

function OpenHelp(strURL) {
  winHelp = window.open(strURL, 'winHelp', 'location=no,resizable=yes,status=yes,toolbar=no,menubar=no,scrollbars=yes,width=640,height=660');
  winHelp.focus();
}

function OpenerLink(strURL) {
  if(parent.opener){
    parent.opener.location.href = strURL;
    parent.opener.focus();
  }else{
    location.href = strURL;
  }
}


//lightbox stuff


// neue checkbox funktionen. die können dann mal in den lightbox scripten ausgetauscht werden
function setCheckboxGroup(strFormID, strGroupPrefix, bolChecked) {
  var theForm = document.getElementById(strFormID);

  for (i=0,n=theForm.elements.length;i<n;i++) {
    if (theForm.elements[i].name.indexOf(strGroupPrefix) == 0) theForm.elements[i].checked = bolChecked;
  }
}

function invertCheckboxGroup(strFormID, strGroupPrefix) {
  var theForm = document.getElementById(strFormID);

  for (i=0,n=theForm.elements.length;i<n;i++) {
    if (theForm.elements[i].name.indexOf(strGroupPrefix) == 0) {
      if (theForm.elements[i].checked == false) {
        theForm.elements[i].checked = true;
      } else {
        theForm.elements[i].checked = false;
      }
    }
  }
}



function SelectAllPhotos() {
  var theForm = document.FormLightboxPhotos;

  for (i=0,n=theForm.elements.length;i<n;i++) {
    if (theForm.elements[i].name.indexOf('chk') == 0) theForm.elements[i].checked = true;
  }
}

function DeSelectAllPhotos() {
  var theForm = document.FormLightboxPhotos;

  for (i=0,n=theForm.elements.length;i<n;i++) {
    if (theForm.elements[i].name.indexOf('chk') == 0) theForm.elements[i].checked = false;
  }
}

function ReversePhotoSelection() {
  var theForm = document.FormLightboxPhotos;

  for (i=0,n=theForm.elements.length;i<n;i++) {
    if (theForm.elements[i].name.indexOf('chk') == 0) {
      if (theForm.elements[i].checked == false) {
        theForm.elements[i].checked = true;
      } else {
        theForm.elements[i].checked = false;
      }
    }
  }
}

function CountSelectedPhotos() {
		var theForm = document.FormLightboxPhotos;
		var selectedPhotos = 0;

		for (i=0,n=theForm.elements.length;i<n;i++) {
      if (theForm.elements[i].name.indexOf('chk') == 0 && theForm.elements[i].checked == true) selectedPhotos++;
    }

		return selectedPhotos;
}

function GetSelectedPhotoIDs() {
  var theForm = document.FormLightboxPhotos;
  var strPhotoIDs = "";

  for (i=0,n=theForm.elements.length;i<n;i++) {
  	if (theForm.elements[i].name.indexOf('chk') == 0 && theForm.elements[i].checked == true) strPhotoIDs += theForm.elements[i].value + ", ";
  }

  if (strPhotoIDs != "") {
     strPhotoIDs = String(strPhotoIDs).substring(0,String(strPhotoIDs).length-2);
  }

  return strPhotoIDs;
}

function DownloadSelectedPhotos(strFormAction) {
  var theForm = document.FormLightboxPhotos;
  var intPhotoCount = CountSelectedPhotos();

  if (intPhotoCount > 0) {
    theForm.SelectedPhotoIDs.value = GetSelectedPhotoIDs();
    theForm.target = window.opener.name;
    theForm.action = strFormAction;
    theForm.submit();
  }
}

function RemoveSelectedPhotos(strFormAction) {
  var theForm = document.FormLightboxPhotos;
  var intPhotoCount = CountSelectedPhotos();

  if (intPhotoCount > 0) {
    theForm.SelectedPhotoIDs.value = GetSelectedPhotoIDs();
    theForm.action = strFormAction;
    theForm.submit();
  }
}

function CopySelectedPhotos(strFormAction) {
  var theForm = document.FormLightboxPhotos;
  var intPhotoCount = CountSelectedPhotos();

  if (intPhotoCount > 0) {
    theForm.SelectedPhotoIDs.value = GetSelectedPhotoIDs();
    theForm.action = strFormAction;
    theForm.submit();
  }
}

function MoveSelectedPhotos(strFormAction) {
  var theForm = document.FormLightboxPhotos;
  var intPhotoCount = CountSelectedPhotos();

  if (intPhotoCount > 0) {
    theForm.SelectedPhotoIDs.value = GetSelectedPhotoIDs();
    theForm.action = strFormAction;
    theForm.submit();
  }
}


function NotificationRemoveSelected(strFormAction) {
  var theForm = document.FormNotification;

  theForm.action = strFormAction;
  theForm.submit();
}

function NotificationMoveSelected(strFormAction) {
  var theForm = document.FormNotification;

  theForm.action = strFormAction;
  theForm.submit();
}

function NotificationMarkSelectedAsRead(strFormAction) {
  var theForm = document.FormNotification;

  theForm.action = strFormAction;
  theForm.submit();
}

function NotificationToggle(theForm) {
  for (i=0,n=theForm.elements.length;i<n;i++) {
    if (theForm.elements[i].name.indexOf('chk') == 0) {
      theForm.elements[i].checked = theForm.ToggleNotifications.checked
    }
  }
}


function trim(str) {
  //return str.replace(/^\s*|\s*$/g,"");
  return String(str).replace(/^\s*|\s*$/g,"");
}

function isEmpty(s) {
	return ((s == null) || (s.length == 0));
}


//displays a status on the security of a given keyword
function checkPasswordSecurity(target) {
	var TestWords = false;
	var TestNumberOfChars = false;
	var TestUppercaseChars = false;
	var TestLowercaseChars = false;
	var TestDigits = false;
	var TestSpecialChars = false;
	var TestCounter = false;
	var TestWhiteSpaces = false;
	var TestSecondPassword = false;

	var counter = 0;
	strInput = target.value;
	objImage = document.images.PasswordSecurity


	/* Check if length of password is greather then 8 */

	if(strInput.length >= 8) {

		if(!TestNumberOfChars) {		// do it only if the counter is 8, if it's greather, the TestNumberOfChars will be true and the right image is shown

			TestNumberOfChars = true;

		}
	} else {

		TestNumberOfChars = false;

	}


	/* check uppercase Letters */

	if(strInput.match(/[A-Z]/)) {

		TestUppercaseChars = true;

	} else {

		TestUppercaseChars = false;

	}

	/* check lowercase letters */

	if(strInput.match(/[a-z]/)) {

		TestLowercaseChars = true;

	} else {

		TestLowercaseChars = false;

	}


	/* check for digits */

	if(strInput.match(/[0-9]/)) {

		TestDigits = true;

	} else {

		TestDigits = false;

	}


	/* check special chars */

	if(strInput.match(/[^a-zA-Z0-9]/)) {

		TestSpecialChars = true;

	} else {

		TestSpecialChars = false;

	}


	/* Check for whitespaces and ESC-Sequences */

	if(strInput.match(/\s/)) {

		TestWhiteSpaces = true;

	} else {

		TestWhiteSpaces = false;

	}


	if(TestUppercaseChars) { counter++; }
	if(TestLowercaseChars) { counter++; }
	if(TestDigits)         { counter++; }
	if(TestSpecialChars)   { counter++; }
	if(TestWhiteSpaces)   { counter++; }
	if(TestNumberOfChars)   { counter++; }

	if(counter == 0) { objImage.src = "images/pwdsec0.gif"; }
  if(counter == 1) { objImage.src = "images/pwdsec1.gif"; }
  if(counter == 2) { objImage.src = "images/pwdsec2.gif"; }
  if(counter == 3) { objImage.src = "images/pwdsec3.gif"; }
  if(counter == 4) { objImage.src = "images/pwdsec4.gif"; }
  if(counter == 5) { objImage.src = "images/pwdsec5.gif"; }
  if(counter == 6) { objImage.src = "images/pwdsec6.gif"; }

}

function ToggleBlock(obj) {
  if (document.getElementById(obj + 'On').style.display == "none" || document.getElementById(obj + 'On').style.display == "")
  {
    document.getElementById(obj + 'On').style.display = "block";
    document.getElementById(obj + 'Off').style.display = "none";
  }
  else
  {
    document.getElementById(obj + 'On').style.display = "none";
    document.getElementById(obj + 'Off').style.display = "block";
  }
}

function InputSet(obj, text) {
  document.getElementById(obj).value = text
}



/* popup windows */
function NewWindow(mypage, myname, w, h, scroll) {
  winprops = 'height='+h+',width='+w+',scrollbars='+scroll+',resizable=no, top=20, left=20'
  win = window.open(mypage, myname, winprops)
  if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

 var Behaviour = {
    register: function(rules){
      this.rules = rules;
      for(rule in this.rules){
        this.reload(rule);
      }
    },

    reload: function(rule){
      elements = $$(rule);
      for(y=0;y<elements.length;y++){
        this.rules[rule](elements[y]);
      }
    }

  }


/**
 set your behaviour rules here
*/


popuprules = {
  'a.popFaq':function(elmt) {
    elmt.onclick = function() {
      NewWindow(this.href, 'winHelp', '640', '660', 'yes');return false;
    }
  }
};


photosearchrules = {
  'a.toggleExtSearch':function(elmt) {
      elmt.onclick = function() {
  		Effect.Phase('extendedSearch');
  		this.blur();
  		extSearchReset()
  		return false;
  	}
  },

  'input.SetSearchFieldTitle':function(elmt) {
      elmt.onfocus = function() {
      if(this.value == this.title) this.value = '';
  	},
  	elmt.onblur = function() {
      if(this.value == '') this.value = this.title;
  	}
  },

  '#SearchPhotoInput':function(elmt) {
      elmt.onchange = function() {
      if(this.value == '') this.value = this.title;
      document.getElementById('SearchPhotoInputExt').value = this.value;
  	}
  },

  '#SearchPhotoInputExt':function(elmt) {
      elmt.onchange = function() {
      if(this.value == '') this.value = this.title;
      document.getElementById('SearchPhotoInput').value = this.value;
  	}
  },

  'select.PhotoResUnit':function(elmt) {
      elmt.onchange = function() {
          var px = this.value=='px';
          $$('.dpi').each(function(item) {
              item.style.color = px ? '#CDCED0' : '#645D5B';
              $(item.htmlFor).disabled = px;
          });
          var px = this.value=='px';
           $$('.dpi').each(function(item) {
              item.style.color = px ? '#CDCED0' : '#645D5B';
              var cb = $(item.htmlFor);
              cb.disabled = px;
              if (px)
              cb.checked = !px;
          });

  	}
  }
};