// ----------------------------------------------- AJAX MAIN Stuff --------------------------------------------------------------------------

function togglePatterDetails(id)
{
	var arrow = document.getElementById('detail_arrow_' + id);
	if(arrow.src.indexOf('arrow_right') > 0)
	{
		arrow.src = 'images/arrow_down.gif';
		document.getElementById('detail_view_' + id).style.display = "";
	}
	else
	{
		arrow.src = 'images/arrow_right.gif';
		document.getElementById('detail_view_' + id).style.display = "none";
	}
}

function setCCPrice()
{
	var amount = dojo.byId("cc_amount").value;
	var product = dojo.byId("cc_product").value;
   dojo.io.bind({
    url: 'ajax/getPrice.php?amount='+amount+'&productId='+product,
    load: function(type, data){ dojo.byId('cc_price').innerHTML = data; },
    encoding: "utf-8",
    mimetype: "text/plain"
   });
}

function switchToSSL(params)
{
	if(location.protocol == "https:")
	{
		return true;
	}
	else
	{
		location.href = ssl_root + location.pathname + '?action=' + params;
		return false;
	}
}

var widgetIsLoading = new Array();

function gaTrack(params)
{
	var trackString = params;
	var finalTrackString = trackString.replace(/\&/g, "/");

	if((finalTrackString == '/action=login_state') || (finalTrackString == '/action=basket_Info'))
	{
		; //ignore
	}
	else
	{
		//console.debug(finalTrackString);

		try { pageTracker._trackPageview(finalTrackString); } catch(err) {}
		// google analytics
	}
}

function reloadFrame(SID, params, widgetId, lm)
{
   if (!lm || lm == '') lm = '...';
   var contentPane = dojo.widget.byId(widgetId);
   var requestName = "req_"+widgetId;
   
   // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) { requestName = new XMLHttpRequest(); }     
   // branch for IE/Windows ActiveX version
    else if (window.ActiveXObject) {  requestName = new ActiveXObject('Microsoft.XMLHTTP') }
    
   if(requestName && (!widgetIsLoading[widgetId])) 
   {
   	  widgetIsLoading[widgetId] = true;
      requestName.onreadystatechange = function ()
										{
											 if (requestName.readyState == 4)
											 {
												  // only if 'OK'
												  if (requestName.status == 200) {
												  dojo.widget.byId(widgetId).setContent(requestName.responseText);
												 // document.body.style.cursor='default';
											  }
											  else
											  {
												  ; // alert('There was a problem retrieving the XML data: ' + requestName.responseText);
											  }
										 	  widgetIsLoading[widgetId] = false;
										}
       };
       requestName.open('POST', 'ajax/searchDispatcher.php?SID='+SID+'&frame='+widgetId+params, true);
       requestName.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
       requestName.send(params);
    	
		gaTrack(params);

		if(params != '&action=actionhome&tab=home')
		{
			bT = true;
		}
    }
}

// Konrad Tab Nav
function ajaxGetContent(SID, actionname, contentName, navTabId){
 // todo: change tab class to active 
 // request ajax 
   switch (navTabId){
   	  case 'home':{
        enableHomeNav();
        break;
      }
      case 'orderCard':{
		enableOrderCard();
        break;
      }
      case 'gallery':{
        enableGallery();
      	break;
      }
      case 'questionHelp':{
        enableHelp();
        break;
      }
      case 'myFlexcard':{
        enableMyFlexcard()
   		break;
    }
   	default:{ enableHomeNav();}
  }
    /*navTab = document.getElementById(navTabId);
   navTab.className = 'tabActive';*/
   //dojo.lfx.html.fadeOut(contentName,40).play();
   
   loadmessage = getLoadMessage();
   
   historyCount++;
   dhtmlHistory.add(historyCount,'&action='+actionname+'&tab='+navTabId);
   
   dojo.lang.setTimeout( function() { reloadFrame(SID, '&action='+actionname, contentName, loadmessage) }, 1 );
   dojo.lang.setTimeout( function() { dojo.lfx.html.fadeIn(contentName,40).play()}, 8);
} 

function reloadContentWithoutFade(SID, params, loadmessage)
{
  if(loadmessage == 'loadmessage'){
	 loadmessage = getLoadMessage();
  }
  
  historyCount++;
  dhtmlHistory.add(historyCount, '&action='+params);
  
  dojo.lang.setTimeout( function() { reloadFrame(SID, '&action='+params, 'content', loadmessage) }, 1 );
  reloadLoginState(SID);
}

function reloadContent(SID, params, loadmessage)
{
   historyCount++;
   dhtmlHistory.add(historyCount, '&action='+params);
   
   loadmessage = '';
   reloadFrame(SID, '&action='+params, 'content', loadmessage);
}

function reloadTeaser(SID, params, loadmessage, teaser){
   //dojo.lfx.html.fadeOut(teaser,250).play();      
   //dojo.lang.setTimeout( function() { reloadFrame(SID, '&action='+params, teaser, loadmessage) }, 201 );
   //dojo.lang.setTimeout( function() { dojo.lfx.html.fadeIn(teaser,240).play()}, 300 );
}

function reloadCC(SID, action, message)
{
   dojo.lfx.html.fadeOut('cc',400).play();
   dojo.lang.setTimeout( function() { reloadFrame(SID, '&action='+action, 'cc', message )}, 401 );
   dojo.lang.setTimeout( function() { dojo.lfx.html.fadeIn('cc',400).play()}, 801 );
}


// ----------------------------------------------- DOJO Stuff --------------------------------------------------------------------------

function saveDeliveryDialogData(SID)
{
   dojo.io.bind({
       load: function(type, evaldObj){ reloadContent(SID, 'login&showData=true', 'Lade Anzahlauswahl...') },
       error: errorHandler,
       formNode: document.getElementById( "deliveryEditForm" ),
       encoding: "utf-8",
       mimetype: "text/html"
   });
}

function deleteDeliveryAddress(SID, id)
{
   dojo.io.bind({
    url: 'ajax/clientDispatcher.php?deleteDeliveryAddress=true&id='+id+'&SID='+SID,
    load: function(type, evaldObj){ reloadContent(SID, 'login&showData=true', 'Lade Anzahlauswahl...')    },
    encoding: "utf-8",
    mimetype: "text/html"
   });   
}

function setCCAmount(SID, formname, reloadContent)
{
   dojo.io.bind({
       load: function(type, evaldObj){ reloadCC(SID, 'showanzahl'); },
       error: errorHandler,
       formNode: document.getElementById( formname ),
       mimetype: "text/html"
   }); 
   if (document.forms["productForm"]) gotoProduct(SID, 'showcards');
}   
function setCCSides(SID, formname)
{
   dojo.io.bind({
       load: function(type, evaldObj){ reloadCC(SID, 'showsides'); },
       error: errorHandler,
       formNode: document.getElementById( formname ),
       mimetype: "text/html"
   }); 
   if (document.forms["productForm"]) gotoProduct(SID, 'showcards');
}   

function setCCProduct(SID)
{
   dojo.io.bind({
       load: function(type, evaldObj){ reloadCC(SID, 'showcards'); },
       error: errorHandler,
       formNode: document.getElementById( "productForm" ),
       mimetype: "text/html"
   });   
   window.scrollTo(0,0);
}   
function setCCCorrection(SID, formname)
{
   dojo.io.bind({
       load: function(type, evaldObj){ reloadCC(SID, 'showcorr'); },
       error: errorHandler,
       formNode: document.getElementById( formname ),
       mimetype: "text/html"
   });
}   
function setCCDataCheck(SID, formname)
{
   dojo.io.bind({
       load: function(type, evaldObj){ reloadCC(SID, 'showdatacheck'); },
       error: errorHandler,
       formNode: document.getElementById( formname ),
       mimetype: "text/html"
   });
}   

function reloadProductList(SID)
{
   dojo.io.bind({
       load: function(type, evaldObj){ gotoProduct(SID, 'showcards') },
       error: errorHandler,
       formNode: document.getElementById( "amountForm" ),
       encoding: "utf-8",
       mimetype: "text/html"
   }); 
   reloadCC(SID);   
}

function setCCPattern(SID, action)
{
   dojo.io.bind({
    url: 'ajax/ccFormDispatcher.php?setPattern=true&'+action,
    load: function(type, evaldObj){ reloadCC(SID, 'chosepattern') },
    encoding: "utf-8",
    mimetype: "text/html"
   }); 
}   

function addToBasket(SID)
{
   dojo.io.bind({
    url: 'ajax/basketFormDispatcher.php?action=addtobasket&todo=ccinsert',
    load: function(type, evaldObj){ reloadFrame(SID, '', 'basket_small', ' ' ); }, 
    encoding: "utf-8",
    mimetype: "text/html"
   });    
   loadBasket(SID);
}   

function addSpecimenToBasket(SID)
{
   dojo.io.bind({
       load: function(type, evaldObj){ reloadFrame(SID, '', 'basket_small', ' ' );   },
       error: errorHandler,
       formNode: document.getElementById( "specimenForm" ),
       encoding: "utf-8",
       mimetype: "text/html"
   });
   loadBasket(SID);
}   

function deletefrombasket(SID, basketitemId)
{
   dojo.io.bind({
    url: 'ajax/basketFormDispatcher.php?action=deletefrombasket&basketItemId='+basketitemId+'&SID='+SID,
    load: function(type, evaldObj){ reloadFrame(SID, '', 'basket_small', ' ' );    },
    encoding: "utf-8",
    mimetype: "text/html"
   });   
   loadBasket(SID);   
}

function loadBasket(SID)
{
   dojo.lfx.html.fadeOut('contentMain',400).play();
   dojo.lang.setTimeout( function() { reloadFrame(SID, '&action=showbasket', 'contentMain', 'Lade Warenkorb...')}, 401 );   
   dojo.lang.setTimeout( function() { dojo.lfx.html.fadeIn('contentMain',400).play();}, 801 );   
}

function clearCC(SID)
{
   dojo.io.bind({
    url: 'ajax/ccFormDispatcher.php?clearCC=true',
    load: function(type, evaldObj){ reloadCC(SID, '') },
    mimetype: "text/html"
   });
}   

function setCC(SID, param)
{
   dojo.io.bind({
    url: 'ajax/ccFormDispatcher.php?'+param,
    load: function(type, evaldObj){ reloadCC(SID, '') },
    mimetype: "text/html"
   });
} 

function autocompletion(service,id,outputId){
   
   var value = document.getElementById(id).value;
   document.getElementById('outputId').style.display = "block"; 

  dojo.io.bind({
    url: "ajax/searchDispatcher.php?action="+service+"&value="+value,
    synch: false, //default
    load: function(type, data, evt) {
     
    var array_j = data; 
      var str = "";
      for (var i = 0; i < array_j.length; ++i){
         str = str + '<div class="autoCompletion" onclick="javascript:addfield(\'' +array_j[i]+ '\')">'+' '+array_j[i]+'</div>';
      }
      document.getElementById(outputId).innerHTML = str;
   },
    error: function(type, error){ /*alert("Went fishing."); */},
    mimetype: "text/json"
  });
}

function importDataFile(){
	dojo.io.bind
	({
		url: "test.php",
		load: function(type, data, evt)
		{
				alert(data);
		},
		error: function(type, error)
		{
				alert(error.message);
		},
		formNode: document.upload2
	   /* enctype: "multipart/form-data"*/ 
	   /* mimetype: "text/plain"*/
	});
} 

function doRequestSix(SID, formname, widgetId, action, scope, state, params){
   document.getElementById('state').value = state;
   document.getElementById('action').value = action;
   document.getElementById('scope').value = scope;
   
   dojo.io.bind({
        url: 'ajax/searchDispatcher.php?SID='+SID+params,
        load: function(type, evaldObj){
         dojo.widget.byId(widgetId).setContent(evaldObj);
        },
        error: errorHandler,
        formNode: document.getElementById( formname ),
        encoding: "utf-8",
        mimetype: 'text/html'
    }); 
    return false;
}

function setBank_JSON(PLZ_VALUE, bank_field_Id) {
 var bank_field = document.getElementById(bank_field_Id);
 
  var self = this;
  if (PLZ_VALUE.length > 6)
  {
	  dojo.io.bind({
		url: "ajax/searchDispatcher.php?action=getBankName&plz=" + PLZ_VALUE,
		synch: false, //default
		load: function(type, data, evt) {
			 bank_field.innerHTML = data.bankName;
		},
		error: function(type, error){},
		mimetype: "text/json"
	  });
  }
}

function doRequestOptional(SID, formname, widgetId, params){

   dojo.io.bind({
        url: 'ajax/searchDispatcher.php?'+params,
        load: function(type, evaldObj){
         dojo.widget.byId(widgetId).setContent(evaldObj);
        },
        error: errorHandler,
        formNode: document.getElementById( formname ),
        encoding: "utf-8",
        mimetype: 'text/html'
    }); 

	gaTrack(params);
	
    return false;
}

function doRequest(SID, formname, widgetId)
{

	var form = document.getElementById( formname );
    
   dojo.io.bind({
        url: '/ajax/searchDispatcher.php?SID='+SID,
        load: function(type, evaldObj){
        	dojo.widget.byId(widgetId).setContent(evaldObj);
        },
        error: errorHandler,
        formNode: form,
        encoding: "utf-8",
        mimetype: 'text/html'
    }); 

	try
	{
		var str = "/action="+form.action.value+"/scope="+form.scope.value+"/state="+form.state.value;
		gaTrack(str);
	}
	catch(err) {}

    reloadLoginState(SID);

    return false;
}

function reloadLoginState(SID){
	dojo.lang.setTimeout( function() {    
	   reloadFrame(SID, '&action=login_state', 'login_content', '');
	   reloadFrame(SID, '&action=basket_Info', 'basket_Info', '');
	   }, 1900 );
}

/*[KP]*/
/*Arbeitet nur mit FIREFOX :-(*/
function uploadfile(SID, formname, contentFileUpload){
     alert('go1');
    dojo.io.bind ({
      url: 'ajax/searchDispatcher.php?SID='+SID+'&upload=true',
      handler: function(type, data, evt){
          document.getElementById(contentFileUpload).innerHTML = data;
          },
      content: { fileField: "filename" },
      error: errorHandler,
      mimetype: "text/plain",
      formNode: document.getElementById(formname)
     });
      return false;
}

function setContent(myurl)
{
   dojo.lfx.html.fadeOut('contentBox',400).play();      
   dojo.lang.setTimeout( function() { dojo.io.bind({
       url: myurl,
       load: refreshContent,
       encoding: "utf-8",
       mimetype: "text/html"
   }) }, 401 );
}

function refreshContent( type, data, evt ) {
   dojo.widget.byId('contentBox').setContent(data);
   dojo.lfx.fadeIn('contentBox',300).play();
}


// ----------------------------------------------- AJAX Stuff --------------------------------------------------------------------------

function count_glossar(Id){
   var requestObject = null;
    if (window.XMLHttpRequest) { requestObject = new XMLHttpRequest(); }     
   // branch for IE/Windows ActiveX version
    else if (window.ActiveXObject) {  requestObject = new ActiveXObject('Microsoft.XMLHTTP') }

   if (requestObject) {
       requestObject.open('GET', 'ajax/searchDispatcher.php?action=service_count_glossar&Id='+Id, true);
       requestObject.onreadystatechange = function () {
           if (requestObject.readyState == 4) {
               dump = requestObject.responseText;
           }
       };
       requestObject.send(null);
   }
}

function faq_count_click(Id, cId){
   enableDiv('glossardiv');
   if(document.getElementById(Id).style.display == 'none'){
      enableDiv(Id);
      var requestObject = null;
       if (window.XMLHttpRequest) { requestObject = new XMLHttpRequest(); }     
      // branch for IE/Windows ActiveX version
       else if (window.ActiveXObject) {  requestObject = new ActiveXObject('Microsoft.XMLHTTP') }
   
      if (requestObject) {
          requestObject.open('GET', 'ajax/searchDispatcher.php?action=service_faq_click&Id='+Id+'&cId='+cId, true);
          requestObject.onreadystatechange = function () {
              if (requestObject.readyState == 4) {
                  document.getElementById('glossar').innerHTML = requestObject.responseText;
              /*  alert(dump);*/
              }
          };
          requestObject.send(null);
      }

   }else{
      disableDiv(Id);
   }
}


// ----------------------------------------------- HELPER Stuff --------------------------------------------------------------------------

function test(){
   alert('test');
}

function gotoURL(url)
{
	document.location.href = url;
}


function addfield(value){
   document.getElementById('auto').value = value; 
   document.getElementById('outputId').style.display = "none"; 

}

function open_close(Id){
   if(document.getElementById(Id).style.display == 'none'){
      enableDiv(Id);
   }else{
      disableDiv(Id);
   }
}

function open_close_hinweis(elementId,Id){
    if(document.getElementById(elementId).value == 'other'){
      parent.document.getElementById('frame').height = 450;
       enableDiv(Id);
    }else{
       parent.document.getElementById('frame').height = 350;
       disableDiv(Id); 
    }
}


function check_seleckt_box(theElement){

   var theForm = document.getElementById(theElement);
   var result = false;
   z = 0;
   for(z=0; z < theForm.length;z++){
       if(theForm[z].type == 'checkbox'){
         if(theForm[z].checked == true) result = true;      
       }
   }
   return result;
}

function reOrderVorlagen(SID, formname){
   var result = check_seleckt_box(formname);
   if(result){
        doRequest(SID+'&bestellen=all', 'myVorlagen', 'content');
        enableOrderCard();
   }else{
      alert('aktivieren Sie bitte die Checkboxen');
   }
}


function lightup(object1, opacity){

      object = document.getElementById(object1);
      alert(object);
    if (navigator.appName.indexOf("Netscape")!=-1&&parseInt(navigator.appVersion)>=5)
       object.style.MozOpacity=opacity/100
    else if (navigator.appName.indexOf("Microsoft")!= -1 &&parseInt(navigator.appVersion)>=4)
       object.filters.alpha.opacity=opacity
}



function OpenPopup(myfilename, mywidth, myheight)
{
   ProduktPopup = window.open(myfilename, "_blank", "width="+mywidth+", height="+myheight+", scrollbars");
   ProduktPopup.focus();
}

function reload(URL1)
{
   parent.location.href=URL1;
}

function checkUncheckAll(theElement) {
    var theForm = theElement.form, z = 0;
    for(z=0; z < theForm.length;z++){
       if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
          theForm[z].checked = theElement.checked;
       } 
   }
}

function open_close_file_upload_box(formId, id){
  value = document.getElementById(formId).value;   
  if(value < 3 ) disableDiv(id);    
  if(value > 2 ) enableDiv(id);    
}

function check_upload(value){
   regex = /[jpg|jpeg|JPG|JPEG|ppt|PPT|PDF|pdf]$/;
   result = regex.test(value);
   if(result == 0){
      alert("FEHLER !!! Falsches Dateitype");
   }
}

function validVat(SID, vatNoElementId){

   var element = document.getElementById(vatNoElementId);
   var myVATNumber = element.value;
   
  //if(checkVATNumber (myVATNumber)) 
  if(true) 
     doRequest(SID, 'rechnungsanschrift', 'content');
  else 
      alert ("Bitte geben Sie einen gültigen 'VAT number' ein z.B. PL8567346215");
}

/*mit fadeIn FadeOUT gibt es manchmal probleme*/
function enableDiv(id){
    
   if(document.getElementById(id).style.display != 'block')
      document.getElementById(id).style.display = 'block';
   if(document.getElementById(id).style.visibility != 'visible')
      document.getElementById(id).style.visibility='visible';

/*   dojo.lfx.html.fadeOut(id,1).play();
   dojo.lfx.html.fadeIn(id,1000).play();   
*/
}

function disableDiv(id){
/*   dojo.lfx.html.fadeIn(id,1).play();   
   dojo.lfx.html.fadeOut(id,300).play();
   dojo.lang.setTimeout( function() {    
       document.getElementById(id).style.display = 'none';
      document.getElementById(id).style.visibility='hidden';
   }, 300 );
*/
   if(document.getElementById(id).style.display != 'none')
       document.getElementById(id).style.display = 'none';
   if(document.getElementById(id).style.visibility != 'hidden')
      document.getElementById(id).style.visibility='hidden';
}


function show_image(id,side){
   
   if(side == 2){
      fadeOutDiv(id+"image1");
      dojo.lang.setTimeout( function() {
         fadeInDiv(id+"image2");
      }, 900 );
   
   
      disableDiv(id+"side2");
      enableDiv(id+"side1");
   }else{
      fadeOutDiv(id+"image2");
      dojo.lang.setTimeout( function() {
         fadeInDiv(id+"image1");
      }, 900 );

   
      disableDiv(id+"side1");
      enableDiv(id+"side2");
   }
}

function fadeOutDiv(id){
   dojo.lfx.html.fadeIn(id,1).play();   
   dojo.lfx.html.fadeOut(id,900).play();
   dojo.lang.setTimeout( function() {    
       document.getElementById(id).style.display = 'none';
      document.getElementById(id).style.visibility='hidden';
   }, 900 );
}

function fadeInDiv(id){

   dojo.lfx.html.fadeOut(id,1).play();
   document.getElementById(id).style.display = 'block';
   document.getElementById(id).style.visibility='visible';

   dojo.lfx.html.fadeIn(id,900).play();   
}

function OpenCloseDiv(id){
   if(document.getElementById(id).style.display == 'none'){
      enableDiv(id);      
      document.getElementById(id+'Label').innerHTML = '&dArr;';
   }else{
      disableDiv(id);
      document.getElementById(id+'Label').innerHTML = '-&gt;';      
   }   
   if(typeof(document.height)!="undefined"){
      parent.document.getElementById('frame').height = document.height;
   }else{
         /*alert(document.body.clientHeight);
         */
   }
}

function showDiv(sourceId,id){
   if((document.getElementById(sourceId).checked) == true){
      enableDiv(id);      
   }else{
      disableDiv(id);      
   }   
}

function setBasket_Info(txt){
//   document.getElementById('basket_Info').innerHTML = txt;
}

function popup_preis(id,SID,doRequest){
	if(!doRequest) doRequest = '';
   handler = window.open('popupDispatcher.php?doRequest='+doRequest+'&action=popuppreise&kartonId='+id+'&SID'+SID+'','','width=680,height=700,scrollbars=yes');
   handler.focus();
}

function popupreload(url, sourceId){
   handler = window.opener.window.open(url+'&kartonId='+sourceId,'','width=680,height=700,scrollbars=yes');
   this.close();
}
function closepopup(){
	self.close();	
}

function onPopup(productId, sourceId,SID, noRequest){
	window.opener.document.getElementById(sourceId+'karton').style.backgroundColor = "#fefefe";
	window.opener.document.getElementById(sourceId+productId).selected=true;
	if(! noRequest)
	{
		window.opener.doRequest(SID, 'zusammenstellenCard'+sourceId, 'content');
	}
	timer_h = self.setTimeout("closepopup()", 1000);
	window.opener.focus(); 
}

function closePopup(){
   // dummy oder was?
}

function enableVAT()
{
   if (document.reg.clientCompany.value.length > 2)
      document.reg.clientVAT.disabled=false;
}

function OpenChristmasPopup()
{
   ProduktPopup = window.open("christmas.php", "_blank", "width=800, height=630, scrollbars=no");
   ProduktPopup.focus();
}

function OpenChristmasPopupForm()
{
   ProduktPopup = window.open("christmas.php?startForm=yes", "_blank", "width=800, height=630, scrollbars=no");
   ProduktPopup.focus();
}

function OrderItemUebernehmen(itemId,SID, formname, widgetId){
   document.getElementById('uebernehmen').value = itemId;
   doRequest(SID, formname, widgetId);
}

function htmlentities(str,typ) {
    if(typeof str=="undefined") str="";
    if(typeof typ!="number") typ=2;
    typ=Math.max(0,Math.min(3,parseInt(typ)));
    var html=new Array();
    html[38]="&amp;"; html[60]="&lt;"; html[62]="&gt;";
    if(typ==1 || typ==3) html[39]="&#039;";
    if(typ==2 || typ==3) html[34]="&quot;";
    for(var i in html) eval("str=str.replace(/"+String.fromCharCode(i)+"/g,\""+html[i]+"\");");
    var entity=new Array(
      "&nbsp;","&iexcl;","&cent;","&pound;","&curren;","&yen;","&brvbar;","&sect;",
      "&uml;","&copy;","&ordf;","&laquo;","&not;","&shy;","&reg;","&macr;",
      "&deg;","&plusmn;","&sup2;","&sup3;","&acute;","&micro;","&para;","&middot;",
      "&cedil;","&sup1;","&ordm;","&raquo;","&frac14;","&frac12;","&frac34;","&iquest;",
      "&Agrave;","&Aacute;","&Acirc;","&Atilde;","&Auml;","&Aring;","&AElig;","&Ccedil;",
      "&Egrave;","&Eacute;","&Ecirc;","&Euml;","&Igrave;","&Iacute;","&Icirc;","&Iuml;",
      "&ETH;","&Ntilde;","&Ograve;","&Oacute;","&Ocirc;","&Otilde;","&Ouml;","&times;",
      "&Oslash;","&Ugrave;","&Uacute;","&Ucirc;","&Uuml;","&Yacute;","&THORN;","&szlig;",
      "&agrave;","&aacute;","&acirc;","&atilde;","&auml;","&aring;","&aelig;","&ccedil;",
      "&egrave;","&eacute;","&ecirc;","&euml;","&igrave;","&iacute;","&icirc;","&iuml;",
      "&eth;","&ntilde;","&ograve;","&oacute;","&ocirc;","&otilde;","&ouml;","&divide;",
      "&oslash;","&ugrave;","&uacute;","&ucirc;","&uuml;","&yacute;","&thorn;","&yuml;"

      );
    for(var i in entity) eval("str=str.replace(/"+String.fromCharCode(i*1+160)+"/g,\""+entity[i]+"\");");
    return str;
}

function goRequestBestellung(SID, formname, widgetId, action, scope){
   document.getElementById('action').value = action;
   document.getElementById('scope').value = scope;
   doRequest(SID, formname, widgetId);
}

function confirmDoRequest(MESSAGE,SID, formname, widgetId){
   result = confirm(MESSAGE);
   if(result == true){
      doRequest(SID, formname, widgetId);      
   }
}

function send_Anfrageformular(SID,sendmessage,content){
   var email = document.getElementById('email').value;
   if(email.length > 0){
      if(!checkMail(email)){
         alert('bitte geben Sie eine gültige E-Mail-Adresse ein!');
         return false;
      }
   }
   return doRequest(SID,sendmessage,content);
}

function validAnfrageformular(){
    var name = document.getElementById('posName').value;
    var email = document.getElementById('posEmail').value;
   
   if(name.length < 3 || email.length < 3){
      alert('Bitte geben Sie mindestens Ihren Namen und Ihre E-Mail-Adresse ein.');
      return false;
   }

   return true;
}

function goAnfrageformular(){
   if(validAnfrageformular()){
      var object = document.getElementById('form_upload');
      object.submit();
   }
}

function checkMail(x)
{
   var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
   if (filter.test(x)) return true;
   else return false;
}

function dumpData( type, data, evt ) {
   var msg = "Data dump:\n" + data;
   //alert( msg );
}

function errorHandler( type, error ) {
   //var msg = "Something went horribly wrong ...\n" + error.message;
   //alert( msg );
}   

function openMenuItemQuestionHelp(sid, id){
   menu  = document.getElementById(id);
   menu.style.display = 'block';
   menu.style.cursor =  'pointer';
   if(menu.innerHTML == ''){
         menuItem  = '<div class="menuItem"><a href="?action=login">Anmeldung</a><br></div>';
         menuItem += '<div class="menuItem"> Preis   </div>';
         menuItem += '<div class="menuItem"> Lieferzeit   </div>';
         menuItem += '<div class="menuItem"> Vorlagen hochladen   </div>';
         menuItem += '<div class="menuItem"> Druckqualitaet  </div>';
         menu.innerHTML = menuItem;
   }
}

function openMenuItemGallery(id){
   menu  = document.getElementById(id);
   menu.style.display = 'block';
   menu.style.cursor =  'pointer';
   if(menu.innerHTML == ''){
         menuItem  = '<div class="menuItem"> Alle-Listen   </div>';
         menuItem += '<div class="menuItem"> Kult-Liste   </div>';
         menuItem += '<div class="menuItem"> Nuetzliche Liste   </div>';
         menuItem += '<div class="menuItem"> Neu-Liste   </div>';
         menuItem += '<div class="menuItem"> Top-Download-Liste  </div>';
         menu.innerHTML = menuItem;
   }
}

// konrad sub Nav OrderCard

function openMenuItemOrderCard(id){
   menu  = document.getElementById(id);
   menu.style.display = 'block';
   menu.style.cursor =  'pointer';
   
   if(menu.innerHTML == ''){
      if('menuItem1' == id){
         menuItem  = '<div class="menuItem"> Galerie-Vorlage   </div>';
         menuItem += '<div class="menuItem"> Flexcard-Vorlage   </div>';
         menuItem += '<div class="menuItem"> Eigene Vorlage   </div>';
         menuItem += '<div class="menuItem"> Flexcard-Gestaltung   </div>';
         menu.innerHTML = menuItem;
      }
      if('menuItem2' == id){
         menuItem  = '<div class="menuItem"> Druckvorlagen hochladen  </div>';
         menuItem += '<div class="menuItem"> Auftrag zusammenstellen   </div>';
         menuItem += '<div class="menuItem"> Karton wählen   </div>';
         menuItem += '<div class="menuItem"> Anzahl   </div>';
         menuItem += '<div class="menuItem"> Qualitaetscheck   </div>';
         menuItem += '<div class="menuItem"> Korrekturabzug   </div>';
         menu.innerHTML = menuItem;
      }
      if('menuItem3' == id){
         menuItem  = '<div class="menuItem"> Bestelluebersicht   </div>';
         menuItem += '<div class="menuItem"> Anmeldung   </div>';
         menuItem += '<div class="menuItem"> Rechnungsadresse Lieferanschrift  </div>';
         menuItem += '<div class="menuItem"> versandoptionen</div>';
         menuItem += '<div class="menuItem"> zahlungsweise</div>';
         menuItem += '<div class="menuItem"> alles ok?</div>';
         menuItem += '<div class="menuItem"> Bestellung  Abschliesen?</div>';
         menu.innerHTML = menuItem;
      }
   }
}

function closeMenuItem(id){
   document.getElementById(id).style.display = 'none';
}


function enableHomeNav(){
    document.getElementById('myFlexcard').className = "nav_off";
    document.getElementById('orderCard').className = "nav_off";
    document.getElementById('gallery').className = "nav_off";
    document.getElementById('questionHelp').className = "nav_off";
    document.getElementById('home_menu').className = "nav_on_home";
}
function disableNav(){
    enableHomeNav();
}
function enableOrderCard(){
   document.getElementById('orderCard').className = 'nav_on';   
   document.getElementById('questionHelp').className = "nav_off";
   document.getElementById('gallery').className = "nav_off";
   document.getElementById('myFlexcard').className = 'nav_off';
   document.getElementById('home_menu').className = "nav_off_home";
}
function enableGallery(){
    document.getElementById('orderCard').className = 'nav_off';
    document.getElementById('gallery').className = 'nav_on';
    document.getElementById('questionHelp').className = "nav_off";
    document.getElementById('myFlexcard').className = 'nav_off';
    document.getElementById('home_menu').className = "nav_off_home";
}
function enableHelp(){
    document.getElementById('orderCard').className = 'nav_off';
    document.getElementById('gallery').className = 'nav_off';
    document.getElementById('questionHelp').className = "nav_on";
    document.getElementById('myFlexcard').className = 'nav_off';
    document.getElementById('home_menu').className = "nav_off_home";
}
function enableMyFlexcard(){
	document.getElementById('myFlexcard').className = 'nav_on';
	document.getElementById('gallery').className = 'nav_off';
	document.getElementById('questionHelp').className = 'nav_off';
	document.getElementById('orderCard').className = 'nav_off';
	document.getElementById('home_menu').className = "nav_off_home";
}


function confirmReloadContent(message,SID, params, loadmessage)
{
  result = confirm(message);
  if(result == true){
	 reloadContentWithoutFade(SID, params, loadmessage);         
  }
}

function getLoadMessage(){
	 loadmessage ='<div class="boxbigwithtop" style="margin-top:30px;">&nbsp;</div>'; 
	 loadmessage = loadmessage+'<div class="boxbigwithcenter" style="height:400px;"align="center">';
	 loadmessage = loadmessage+'Bitte Warten laden';
	 loadmessage = loadmessage+'<div></div>';
	 loadmessage = loadmessage+'<img src="images/ajax-loader.gif" alt="..."/>';
	 loadmessage = loadmessage+'</div><div class="boxbigwithbottom">&nbsp;</div>';
  return loadmessage;
}

function gotoAmount(SID)
{
   reloadContent(SID, 'showanzahl', 'Lade Anzahlauswahl...');
}

function gotoSides(SID)
{
   reloadContent(SID, 'showsides', 'Lade Seitenauswahl...');
}

function gotoProduct(SID)
{
   reloadContent(SID, 'showcards', 'Lade Produktauswahl...');
}

function gotoPattern(SID)
{
   reloadContent(SID, 'chosepattern', 'Lade Vorlagenauswahl...');
}

function gotoCorrection(SID)
{
   reloadContent(SID, 'showcorr', 'Lade Vorlagenauswahl...');
}

function gotoDatacheck(SID)
{
   reloadContent(SID, 'showdatacheck', 'Lade Vorlagenauswahl...');
}

function gotoSpecimenForm(SID)
{
   reloadContent(SID, 'showspecimenform', 'Lade Musterformular...');
}

// ---- ProductView decision ---------------
function showSinglePrice()
{
   document.getElementById('singlePrice').style.display ='block';
   document.getElementById('doublePrice').style.display ='none';
}   
function showDoublePrice()
{
   document.getElementById('singlePrice').style.display ='none';
   document.getElementById('doublePrice').style.display ='block';
}

function changePriceView()
{
   if (document.forms['amountForm'].isTwoSides.value == '1') { showDoublePrice(); }
   else showSinglePrice();
}

function showPassword()
{
   document.getElementById('passwordData').style.display ='block';
}
function hidePassword()
{
   document.getElementById('passwordData').style.display ='none';
}

function showDelivery()
{
   document.getElementById('showDeliveryAddress').style.display ='block';
}
function hideDelivery()
{
   document.getElementById('showDeliveryAddress').style.display ='none';
}

function startDeliveryDialog(SID, id, clientId, address1, address2, address3, countryId, zip, city, isStandard)
{
   document.forms['deliveryEditForm'].deliveryAddressId.value = id;
   document.forms['deliveryEditForm'].deliveryClientId.value = clientId;
   if (address1) document.forms['deliveryEditForm'].clientDelAddress1.value = address1;
   if (address2) document.forms['deliveryEditForm'].clientDelAddress2.value = address2;
   if (address3) document.forms['deliveryEditForm'].clientDelAddress3.value = address3;
   if (countryId) document.forms['deliveryEditForm'].clientDelCountryId.value = countryId;
   if (zip) document.forms['deliveryEditForm'].clientDelZip.value = zip;
   if (city) document.forms['deliveryEditForm'].clientDelCity.value = city;
   if (isStandard == 'y') document.forms['deliveryEditForm'].isStandard.checked = true;
   else document.forms['deliveryEditForm'].isStandard.checked = false;
}