// browser type

function getBrowserType() {
   // returns browserType:
   // N3 = Nescape Navigator >3
   // M4 = Mircosoft IExplorer >4
   // NN = browser unknown

   var browserVer=parseInt(navigator.appVersion);
   var browserType=navigator.appName;
   var browser = "NN";

   if (browserType == "Netscape" && browserVer >= 3) browser = "N3";
   if ((browserType.indexOf("Microsoft") != -1) && browserVer >= 4 ) browser = "M4";
   return browser;

}


function isMacIe() {
   // returns browserType:
   // N3 = Nescape Navigator >3
   // M4 = Mircosoft IExplorer >4
   // NN = browser unknown


   var is = false;

   if (navigator.userAgent.indexOf("Mac") != -1) {
      if (navigator.appName.indexOf("Microsoft") != -1) {

         is = true;
      }
   }
   return is;
}


// archive search ////////////////////////////////////////////////////////

function changeKeywords2() {


   kw1 = document.searchForm.keyword1.value;

   while(document.searchForm.keyword2.length > 0) {
      deleteSelectList();
   }

   addOption(0, "// Select Keywords II");
   for( i=0; i < keywords[kw1].length; i++) {
      addOption(keywords[kw1][i]["id"], keywords[kw1][i]["label"]);

   }

}

function addOption(value, text) {
   newOption = new Option(text,value,false,false);
   document.searchForm.keyword2.options[document.searchForm.keyword2.options.length] = newOption;
}

function deleteSelectList() {

   len = document.searchForm.keyword2.length;
   for(i=0; i < len ; i++) {
      //lert(i);
      document.searchForm.keyword2.options[i] = null;
   }

}



// popup functions ////////////////////////////////////////////////////////

function popupArchiveTree(location, width, height) {

   offsetTop = 280;

   if(window.screenLeft) {

      LeftPosition = window.screenLeft;
      TopPosition = window.screenTop + offsetTop;

   } else {

      LeftPosition = 0;
      TopPosition =  offsetTop;

   }


   ref = window.open(location, 'stefanmaycomtree', "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,width="+width+",height="+height+",top="+TopPosition+",left="+LeftPosition);

   ref.focus();
   return ref;

}

var popupnum = 0;

function popupSizedCentered(location, width, height) {

   popupnum++;
   LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
   TopPosition = (screen.height) ? (screen.height-height)/2 : 0;

   if(window.screenLeft) {

      LeftPosition  = LeftPosition + window.screenLeft

   }

   ref = window.open(location, 'stefanmaycom'+popupnum, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width="+width+",height="+height+",top="+TopPosition+",left="+LeftPosition);

   ref.focus();
   return ref;

}



function popupTerms(location, width, height) {


   LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
   TopPosition = (screen.height) ? (screen.height-height)/2 : 0;

   if(window.screenLeft) {

      LeftPosition  = LeftPosition + window.screenLeft

   }

   ref = window.open(location, 'stefanmaycom', "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,width="+width+",height="+height+",top="+TopPosition+",left="+LeftPosition);

   ref.focus();
   return ref;

}



function changePopup(location, width, height) {

   LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
   TopPosition = (screen.height) ? (screen.height-height)/2 : 0;


   window.width = width;
   window.height = height;
   window.location = location;

   /*
   ref.focus();
   return ref;
   */

}



// layer functions ////////////////////////////////////////////////////////

// init visibility
var vista = new Array();




// search functions

function searchbar() {
   toggleDisplay("searchLayer");
   if(vista["searchLayer"] == 'none') {
      document.getElementById('searchButton').src = 'images/'+lang+'/search_closed_norm.gif';
      //vista["searchLayer"] = 'none';
   } else {
      document.getElementById('searchButton').src = 'images/'+lang+'/search_open_norm.gif';
      //vista["searchLayer"] = 'block';
   }

   setPersistentCookie('smSearchLayer2', vista["searchLayer"]);

}

function searchbarInit() {

   //while(!document.getElementById('searchLayer')) {

   vista["searchLayer"] = getCookie('smSearchLayer2');

   if(vista["searchLayer"] == null) {
      vista["searchLayer"] = 'block';
   }

   document.getElementById('searchLayer').style.display = vista["searchLayer"];
   
   if(vista["searchLayer"] == 'block') {
      document.getElementById('searchButton').src = 'images/'+lang+'/search_open_norm.gif';
      //document.getElementById('searchKeyword1').style.visibility = 'inherit';
      //document.getElementById('searchKeyword2').style.visibility = 'inherit';
      vista["searchLayer"] = 'block';
   } else {
      document.getElementById('searchButton').src = 'images/'+lang+'/search_closed_norm.gif';
      vista["searchLayer"] = 'none';
      //document.getElementById('searchKeyword1').style.visibility = 'visible';
      //document.getElementById('searchKeyword2').style.visibility = 'visible';
   }


   /*
   if(document.getElementById('searchLayer').style.visibility == 'hidden') {
   document.getElementById('searchButton').src = 'images/search_closed.gif';
   }
   */

   //}
}



function nav() {
   //toggleInversDisplay("navplus");
   toggleDisplay("navLayer");
}


function toggleDisplay(id) {

   vista[id] = (document.getElementById(id).style.display == 'none') ? 'block' : 'none';
   document.getElementById(id).style.display = vista[id];

}

function toggleInversDisplay(id) {
   vista[id] = (document.getElementById(id).style.display == 'block') ? 'none' : 'block';
   document.getElementById(id).style.display = vista[id];

}


function quickdrop() {
   /*
   if(isMacIe()) {
   //document.getElementById("quickdropLayer").style.top = 2;
   }
   */


   if(document.getElementById("qdFunction").getAttribute("class") == "statusbarLink") {
        document.getElementById("qdFunction").setAttribute("class", "statusbarLinkCurrent"); 
        document.getElementById("qdFunction").setAttribute("className", "statusbarLinkCurrent"); 
     
   } else {
        document.getElementById("qdFunction").setAttribute("class", "statusbarLink"); 
        document.getElementById("qdFunction").setAttribute("className", "statusbarLink"); 
  
   }

   toggleVisibility("quickdropLayer");
   toggleInversVisibility("searchKeyword");
   //toggleInversVisibility("searchKeyword2");
   if(document.getElementById("pagenav1")) {
      toggleVisibility("pagenav1");
   }
}


function login() {
   if(isMacIe()) {
      //alert(document.getElementById("loginLayer").getAttribute("style"));
   }

   if((document.getElementById("loginFunction").getAttribute("class") == "statusbarLink") ||(document.getElementById("loginFunction").getAttribute("className") == "statusbarLink") ) {
        document.getElementById("loginFunction").setAttribute("class", "statusbarLinkCurrent"); 
        document.getElementById("loginFunction").setAttribute("className", "statusbarLinkCurrent"); 

   } else {
      document.getElementById("loginFunction").setAttribute("class", "statusbarLink"); 
      document.getElementById("loginFunction").setAttribute("className", "statusbarLink"); 

   }

   if(document.getElementById("pagenav1")) {
      toggleVisibility("pagenav1");
   }
   toggleVisibility("loginLayer");

}


function toggleVisibility(id) {

   vista[id] = (document.getElementById(id).style.visibility == 'hidden') ? 'visible' : 'hidden';
   document.getElementById(id).style.visibility = vista[id];



}

function toggleInversVisibility(id) {
   if(document.getElementById(id)) {
      vista[id] = (document.getElementById(id).style.visibility == 'visible' || document.getElementById(id).style.visibility == 'inherit' ) ?  'hidden' : 'visible';
      document.getElementById(id).style.visibility = vista[id];
   }

}

// tree functions ////////////////////////////////////////////////////////

function toggleTree(id) {
   vista = (document.getElementById(id).style.display == 'none') ? 'block' : 'none';
   icon = new Image();

   if(vista == 'none') {
      icon.src = 'images/tree_left_norm.gif';

   } else {
      icon.src = 'images/tree_down_norm.gif';
   }

   iconId = 'icon' + id;
   //alert (iconId);
   document.getElementById(iconId).src = icon.src;
   document.getElementById(id).style.display = vista;


}

// order functions //////////////////////////////////////////////////////////

function orderdetail(id) {
   detailid = "orderdetail" + id;

   toggleDisplay(detailid);

   if(vista[detailid] == 'block') {
      document.getElementById('ordericon'+id).src = 'images/listdetail_open_hi.gif';
      vista[detailid] = false;
   } else {

      document.getElementById('ordericon'+id).src = 'images/listdetail_closed_hi.gif';
      vista[detailid] = true;;
   }
}


var markedElems = Array();

function markOrder(id, event) {
   name = "row"+id
   arrElems = document.getElementsByName(name);

   bgcolors = Array();
   bgcolors['over']    = '#cccccc';
   bgcolors['out']     = '#ffffff';
   bgcolors['click']   = '#cccccc';

   colors = Array();
   colors['over']    = '#000000';
   colors['out']     = '#333333';
   colors['click']   = '#333333'; 




   if(event == 'click') {

      //alert(id);
      if(markedElems[id] == true) {
         //alert("unmark");
         markedElems[id] = false;
      } else {
         //alert("mark");
         markedElems[id] = true;
      }
   } else {

      highlightButton('ordericon'+id, event);

   }


  for(i=0; i<arrElems.length; i++) {
      elem = arrElems[i];

      if(markedElems[id] == true) {
         elem.style.backgroundColor = bgcolors['click'];
         elem.style.color = colors[event];

      } else {

         elem.style.backgroundColor = bgcolors[event];
         elem.style.color = colors[event];

      }

   }



}





function loadOpenerPage(page, id) {

   window.opener.location = "index.php?p=" + page + "&id=" + id;

}

function loadOpenerPageUri(uri) {

   window.opener.location = uri;
   window.close();

}


function loadPageUri(uri) {

   window.location = uri;

}


function reloadOpenerPage() {

   window.opener.location = window.opener.location;

}



// cartbar //////////////////////////////////////////////////////////////

function cartbar() {
   toggleDisplay("cartLayer");

   if(vista["cartLayer"] == 'block') {
      document.getElementById('cartButton').src = 'images/listdetail_open_hi.gif';
      document.getElementById('orderButton1').style.visibility = 'hidden';
      vista["cartLayer"] = 'block';
   } else {
      document.getElementById('cartButton').src = 'images/listdetail_closed_hi.gif';
      document.getElementById('orderButton1').style.visibility = 'visible';
      vista["cartLayer"] = 'none';
   }

   setPersistentCookie('smCartLayer', vista["cartLayer"]);

}

function cartbarInit() {

   vista["cartLayer"] = getCookie('smCartLayer');



   document.getElementById('cartLayer').style.display = vista["cartLayer"];

   if(vista["cartLayer"] == 'block') {
      document.getElementById('cartButton').src = 'images/listdetail_open_norm.gif';
      document.getElementById('orderButton1').style.visibility = 'hidden';
      vista["cartLayer"] = 'block';
   } else {
      document.getElementById('cartButton').src = 'images/listdetail_closed_norm.gif';
      vista["cartLayer"] = 'none';
   }


}



// order /////////////////////////////////////////////////////

function recaluclateCart() {

   //document.getElementById('acceptGtc').style.display = 'none';
   document.getElementById('cartAction').value = 'calculate';
   //document.getElementById('orderformButton').src = './images/en/button_calculate.gif';
   document.getElementById('cartForm').submit();

}


function cartChangeUsage() {

   document.getElementById('cartAction').value = 'show';
   //   alert(document.getElementById('prefusage').value);
   document.getElementById('cartForm').submit();

}




// archive  /////////////////////////////////////////////////////

function archive(photographer, event) {

   //highlightButton('teaserlabel_'+photographer, event);

}



// quickdrop event /////////////////////////////////////////////////////

function qdLightbox() {

   document.quickdropForm.method.value = 'lightbox';
   document.quickdropForm.submit();

}


function qdOneclick() {

   document.quickdropForm.method.value = 'oneclick';
   document.quickdropForm.submit();

}



// form functions ///////////////////////////////////////////////

function selectRadio(elemId, index) {

   document.getElementsByName(elemId)[index].checked = true;


}

function selectCheckbox(elemId) {

   elem = document.getElementById(elemId);
   if(elem.checked == true) {
      elem.checked = false;
   }else {
      elem.checked = true;

   }

}


// highlight functions ////////////////////////////////////////

function highlightPhoto(id, bestof, event) {

   className = document.getElementById('photolabel'+id).className;

   if( event == 'over' ) {
      if ( className.indexOf('Bestof') > 0 ) {
         document.getElementById('photolabel'+id).style.color = 'photonumberBestofHi';
      } else {
         document.getElementById('photolabel'+id).style.color = 'photonumberHi';
      }
   }

   if( event == 'out' ) {
      if ( className.indexOf('Bestof') > 0 ) {
         document.getElementById('photolabel'+id).style.color = 'photonumberBestof';
      } else {
         document.getElementById('photolabel'+id).style.color = 'photonumber';
      }

   }

}


var oldColor = '';
function highlightLinkColor(id, event) {

   elem = document.getElementById(id);

   if(event == 'over') {
      oldColor = elem.style.color;
      elem.style.color = '#444444';
      elem.style.textDecoration = 'underline';
   }

   if(event == 'out') {
      elem.style.color = oldColor;
      elem.style.textDecoration = '';
   }

}



function highlightButton(id, event) {
   
   src = document.getElementById(id).src;

   basename = src.substring(0,src.lastIndexOf('_'));

   //basename = src.substring(src.lastIndexOf('/'));

   if(event == 'over') {
      document.getElementById(id).src = basename + '_hi.gif';
   }

   if(event == 'out') {
      document.getElementById(id).src = basename + '_norm.gif';
   }

}


function highlightButtonName(name, event) {
   
   elems = document.getElementsByName(name);

   for(i=0; i < elems.length; i++) {
      elem = elems[i];
      src = elem.src;

      basename = src.substring(0,src.lastIndexOf('_'));

      //basename = src.substring(src.lastIndexOf('/'));

      if(event == 'over') {
         elem.src = basename + '_hi.gif';
         //alert(document.getElementById(id).src);
      }

      if(event == 'out') {
         elem.src = basename + '_norm.gif';
      }

   }

}


// selectnav ///////////////////////////////////////////////


function selectnav(pagenum) {

   if(selectnavCurrent >0 ) {
      document.getElementById('selectnav'+selectnavCurrent).style.visibility = 'hidden';

   }

   selectnavCurrent = pagenum;
   document.getElementById('selectnav'+pagenum).style.visibility = 'visible';

}


function getClientInfo() {
   
   // save screen resolution
   elems = document.getElementsByName('screenres');
   
   for(i=0; i < elems.length; i++) {
      elems[i].value = screen.width + "x" + screen.height;
   }
   

}


function demarkTextbox(id, bgColor) {
   
   document.getElementById(id).style.backgroundColor = bgColor;
   
   
}