var checkFormSettingsMessage='Mindestes ein Formularelement wurde mit einem nicht zulässigen Wert besetzt. Bitte überprüfen Sie Ihre Eingaben.';

function confirmDelete(what,url_redir) {
  var msg = "Möchten Sie den Eintrag wirklich löschen?\n\nBitte beachten Sie dabei, dass mit dem Löschvorgang\neventuell verknüpfte Daten aus anderen Tabellen\nverloren gehen können.";
  if (what>"") msg = "Möchten Sie den Eintrag '"+what+"' wirklich löschen?\n\nBitte beachten Sie dabei, dass mit dem Löschvorgang\neventuell verknüpfte Daten aus anderen Tabellen\nverloren gehen können.";
  var conf = confirm(msg);
  if (conf) {
    window.location.href = url_redir;
  }
}


function checkFormDefaultSettings(frmobj) {
  /**
   * this function checks if form elements are not set to proper values (in other words sset to specific preset values)
   * the function takes an array of listbox element names and their default value
   *
   * e.g. checkFormDefaultSettings(this,'IDImage',0,'IDType','none')
   *
   * in the example above the function returns false if
   * - the form element named 'IDImage' is set to 0
   * and the form element named 'IDType' is set to 'none'
   *
   *
   */
  if (arguments.length < 3) return false;

  var elements = new Object();
  for (i=1;i<arguments.length;i+=2) {
    elements[arguments[i]] = arguments[i+1];
  }

  var frmel;
  var ok = true;
  for (i=0;i<frmobj.elements.length;i++) {
    frmel = frmobj.elements[i];
//    if (elements[frmel.name] > '') {
      if (frmel.type == 'select-one' && frmel.options[frmel.selectedIndex].value == elements[frmel.name]) ok = false;
      if (frmel.type == 'text' && frmel.value == elements[frmel.name]) ok = false;
      if (frmel.type == 'checkbox' && frmel.value == elements[frmel.name]) ok = false;
//    }
  }
  if (!ok) {
    alert (checkFormSettingsMessage);
    return false;
  }
  return true;
}


function openPopup(url,title) {
  if (title=='variables') var newin = window.open(url,title,"height=500,width=530,left=100,top=50,status=no,toolbar=no,menubar=no,scrollbars=yes",true);
  if (title=='campaigns') var newin = window.open(url,title,"height=600,width=620,left=50,top=50,status=no,toolbar=no,menubar=no,scrollbars=yes,location=no,resizable=yes",true);
  if (title=='sitemap')   var newin = window.open(url,title,"height=500,width=760,left=20,top=20,status=no,toolbar=no,menubar=no,scrollbars=yes,location=no,resizable=yes",true);
  newin.focus();


}

function previewObject(elementid) {
  var listobj = document.getElementsByName(elementid)[0];
  listvalue = listobj.options[listobj.selectedIndex].value;
  if (elementid=='IDCustomer') var popup = window.open('preview_customer.php?id='+listvalue,'Customer','height=300,width=300');
  popup.focus();
}

function previewData(elementid,arguments) {
  if (elementid=='IDTextblock') var popup = window.open('/admin/scripts/preview_textblock.php?'+arguments,'Textblock','height=300,width=500,resizable');
  if (elementid=='IDContentblock') var popup = window.open('/admin/scripts/preview_contentblock.php?'+arguments,'Textblock','height=400,width=500,resizable');
  popup.focus();
}


function setTopItemArrow() {
  if (document.getElementById) {
    var obj = document.getElementById('topitem');
    obj.src='/images/arrow_right_active.png';
  }
}

var origin_overlay_image;

	function showImg(img) {
    origin_overlay_image = document.mapoverlay.src;
	  document.mapoverlay.src = '/images/maps/'+img+'.gif';
//		document.mapoverlay.style.display = 'block';
	}
	function hideImg() {
		document.mapoverlay.src = origin_overlay_image;
	}

	function selectCountry(img) {
		document.countryoverlay.src = '/images/maps/'+img+'.gif';
		document.countryoverlay.style.display = 'block';
		showContact();
	}

	function showContact() {
	  var obj = document.getElementById('showcontact');
	  obj.innerHTML = "das ist mein Text"
	  obj.style.display = 'block';
	}

  function hideContact() {
	  var obj = document.getElementById('showcontact');
	  obj.style.display = 'none';
	}

function chk_newsletter(frmobj) {
  var fail=false;
  var regmail = /^([\w-\.]{2,})\@([\w-]{2,})\.([\w-\.]{2,})$/gi;

  if (!fail && frmobj.Anrede.options[frmobj.Anrede.selectedIndex].value==0) fail=true;
  if (!fail && frmobj.LastName.value=="") fail=true;
  if (!fail && frmobj.FirstName.value=="") fail=true;
  if (!fail && frmobj.Firma.value=="") fail=true;
  if (!fail && regmail.exec(frmobj.EMail.value)==null) fail=true;
  if (!fail && frmobj.IDLanguage.options[frmobj.IDLanguage.selectedIndex].value==0) fail=true;
  if (!fail && frmobj.VDMA_Code.options[frmobj.VDMA_Code.selectedIndex].value==0) fail=true;

  if (fail) {
    alert(checkFormSettingsMessage);
    return false;
  }
  return true;
}


function chk_profile(frmobj) {
  var fail=false;
  var regmail = /^([\w-\.]{2,})\@([\w-]{2,})\.([\w-\.]{2,})$/gi;

  if (!fail && frmobj.IDIndustry.options[frmobj.IDIndustry.selectedIndex].value==-1) fail=true;
  if (!fail && frmobj.Name.value=="") fail=true;
  if (!fail && frmobj.Phone.value=="") fail=true;
  if (!fail && regmail.exec(frmobj.EMail.value)==null) fail=true;
  if (!fail && frmobj.Company.value=="") fail=true;
  if (!fail && frmobj.Address.value=="") fail=true;
  if (!fail && frmobj.ZIPCode.value=="") fail=true;
  if (!fail && frmobj.City.value=="") fail=true;

  if (fail) {
    alert(checkFormSettingsMessage);
    return false;
  }
  return true;
}



function chk_inquiry(frmobj) {
  var fail=false;
  var regmail = /^([\w-\.]{2,})\@([\w-]{2,})\.([\w-\.]{2,})$/gi;

  if (!fail && frmobj.Anrede.options[frmobj.Anrede.selectedIndex].value==0) fail=true;
  if (!fail && frmobj.Issue.options[frmobj.Issue.selectedIndex].value==0) fail=true;
  if (!fail && frmobj.IDCountry.options[frmobj.IDCountry.selectedIndex].value==0) fail=true;
  if (!fail && frmobj.LastName.value=="") fail=true;
  if (!fail && frmobj.FirstName.value=="") fail=true;
  if (!fail && frmobj.Inquiry.value=="") fail=true;
  if (!fail && regmail.exec(frmobj.EMail.value)==null) fail=true;
  if (!fail && frmobj.Company.value=="") fail=true;
  if (!fail && frmobj.Address.value=="") fail=true;
  if (!fail && frmobj.ZIPCode.value=="") fail=true;
  if (!fail && frmobj.City.value=="") fail=true;

  if (fail) {
    alert(checkFormSettingsMessage);
    return false;
  }
  return true;
}

function chk_shoporder(frmobj) {
  var fail=false;
  var regmail = /^([\w-\.]{2,})\@([\w-]{2,})\.([\w-\.]{2,})$/gi;

  if (!fail && frmobj.VDMA_Code.options[frmobj.VDMA_Code.selectedIndex].value==0) fail=true;
  if (!fail && frmobj.Country.value=="") fail=true;
  if (!fail && frmobj.LastName.value=="") fail=true;
  if (!fail && frmobj.FirstName.value=="") fail=true;
  if (!fail && regmail.exec(frmobj.EMail.value)==null) fail=true;
  if (!fail && frmobj.Company.value=="") fail=true;
  if (!fail && frmobj.Address.value=="") fail=true;
  if (!fail && frmobj.ZIPCode.value=="") fail=true;
  if (!fail && frmobj.City.value=="") fail=true;

  if (fail) {
    alert(checkFormSettingsMessage);
    return false;
  }
  return true;
}


function chk_aliaspwd(frmobj) {
  return false;
}

function chk_productgroup(frmobj) {
  var selopt = frmobj.IDGroup.selectedIndex;
  if (selopt < 0) {
    alert(checkFormSettingsMessage);
    return false;
  }
  return true;
}

function enableDMSearchType(radio) {
  var searchtype = radio.value;
  for (i = 1; i <= 3; i++) {
    var foo = document.getElementById('Search'+i);

//    var foo = eval('document.searchform.search'+i);
    if (searchtype == i) {
      foo.disabled = false;
	  } else {
//      foo.value = '';
      foo.disabled = true;
    }
  }
}

function chk_search(frmobj) {
  var ok = true;
  if (frmobj.srchtxt.value=="") {
    alert (checkFormSettingsMessage)
    return false;
  }
  var ok = false;
  for (i=0;i<frmobj.elements.length;i++) {
    frmel = frmobj.elements[i];
    if (frmel.type == 'checkbox' && frmel.checked == true) ok = true;
  }
  if (!ok) alert (checkFormSettingsMessage);
  return ok;
}

function openfromsitemap(foo) {
  window.opener.top.document.location.href=foo;
  self.close();
}


      function stripeTabByRow(id) {
        var evenColor = arguments[1] ? arguments[1] : "#fff";
        var oddColor = arguments[2] ? arguments[2] : "#eee";
        var table = document.getElementById(id);
        if (!table) return 0;
        var even = false
        var trs = table.getElementsByTagName('tr');
        for (var i = 0; i < trs.length; i++) {
          if (!hasClass(trs[i])) trs[i].style.backgroundColor = even ? evenColor : oddColor;
          /*
          var tds = trs[k].getElementsByTagName('td');
          for (var k = 0; k < tds.length; k++) {
            tds[k].style.backgroundColor = even ? evenColor : oddColor;
          }
          */
          even = !even;
        }
      }

      function stripeTabByClass(id) {
        var evenClass = arguments[1] ? arguments[1] : "even";
        var oddClass = arguments[2] ? arguments[2] : "odd";
        var table = document.getElementById(id);
        if (!table) return 0;
        var even = false;
        var tbodies = table.getElementsByTagName('tbody');
        for (var q = 0; q < tbodies.length; q++) {
          var even = false;
          var trs = tbodies[q].getElementsByTagName('tr');
            for (var i = 0; i < trs.length; i++) {
            if (!hasClass(trs[i])) {
              trs[i].className = even ? evenClass : oddClass;
              even = !even;
            }
          }
        }
      }

      // this function is need to work around
      // a bug in IE related to element attributes
      function hasClass(obj) {
        var result = false;
        if (obj.getAttributeNode("class") != null) {
           result = obj.getAttributeNode("class").value;
        }
        return result;
      }

      function stripe(id) {
        var even = false;
        var evenColor = arguments[1] ? arguments[1] : "#fff";
        var oddColor = arguments[2] ? arguments[2] : "#eee";
        var table = document.getElementById(id);
        if (! table) { return; }
        var trs = table.getElementsByTagName("tr");
        for (var i = 0; i < trs.length; i++) {
    	    if (!hasClass(trs[i]) && ! trs[i].style.backgroundColor) {
            var tds = trs[i].getElementsByTagName("td");
            for (var j = 0; j < tds.length; j++) {
              var mytd = tds[j];
    	        if (! hasClass(mytd) && ! mytd.style.backgroundColor) {
      		      mytd.style.backgroundColor = even ? evenColor : oddColor;
              }
            }
          }
          even =  ! even;
        }
      }



    function show_tippgroup_members(id) {
    		
   		var id = id;
    		
   		new Ajax.Request('/admin/data/system/statistics.php', {
   			method: 'post',
   			asynchronous: false,
   			parameters: 'op=tg&id='+id,
   			onSuccess: function( r ) {
   				$('tg').innerHTML = r.responseText;
   			}
   		});
   	}

    function delete_tippgroup_member(id) {
		
   		var id = id;
    		
   		new Ajax.Request('/admin/data/system/statistics.php', {
   			method: 'post',
   			asynchronous: false,
   			parameters: 'op=tgmdel&id='+id,
   			onSuccess: function( r ) {
   				$('tg').innerHTML = r.responseText;
   			}
   		});
   	}
    
    
