﻿// Variables
var STANDARD_PARAMS = "status=no,resizable=no,scrollbars=no,status=no,toolbar=no,location=no"

var IMAGE_UPLOAD_NEW_PARAMETERS = "Height=190,Width=420," + STANDARD_PARAMS;
var IMAGE_UPLOAD_EDIT_PARAMETERS = "Height=520,Width=420," + STANDARD_PARAMS;

var GEOCOORDS_TUNING_PARAMETERS = "Height=632,Width=520," + STANDARD_PARAMS;

var BRANCHEN_PARAMETERS = "Height=584,Width=650," + STANDARD_PARAMS;
var STANDORT_PARAMETERS = "Height=584,Width=630," + STANDARD_PARAMS;
var PRODUKT_PARAMETERS = "Height=584,Width=584," + STANDARD_PARAMS;
var ZERTIFIKAT_PARAMETERS = "Height=584,Width=584," + STANDARD_PARAMS;
var THEMEN_PARAMETERS = "Height=584,Width=584," + STANDARD_PARAMS;

var HELP_PARAMETERS = "Height=190,Width=590," + "status=no,resizable=no,scrollbars=yes,status=no,toolbar=no";
var EMAIL_PARAMETERS = "scrollbars=yes,status=no,resizable=no,status=no,toolbar=no,width=400,height=590";

// Popups
function openBranchenPopup(strLocation){            
    window.open(strLocation, "BranchenPopup", BRANCHEN_PARAMETERS); 
}

function openStandortPopup(strLocation) {            
    window.open(strLocation, "StandortPopup", STANDORT_PARAMETERS); 
}

function openProduktPopup(strLocation) {            
    window.open(strLocation, "ProduktPopup", PRODUKT_PARAMETERS); 
}

function openZertifikatsPopup(strLocation) {            
    window.open(strLocation, "ZertifikatsPopup", ZERTIFIKAT_PARAMETERS); 
}

function openThemenPopup(strLocation){
        
    window.open(strLocation, "ThemenPopup", THEMEN_PARAMETERS); 
}

function openImageUploadPopupNew(strLocation){

    window.open(strLocation, "ImageUploaderPopupNew", IMAGE_UPLOAD_NEW_PARAMETERS);
}

function openImageUploadPopupEdit(strLocation){

    window.open(strLocation, "ImageUploaderPopupEdit", IMAGE_UPLOAD_EDIT_PARAMETERS);
}

function openGeoCoordsTuningPopup(strLocation){

    window.open(strLocation, "GeoCoordsTuningPopup", GEOCOORDS_TUNING_PARAMETERS);
}

function openHelpPopup(strLocation){

    window.open(strLocation, "HelpPopup", HELP_PARAMETERS);
}

function openEmailPopup(strLocation){
    window.open(strLocation, "EmailForm", EMAIL_PARAMETERS);
}

// Treeview
function postBackByTreeviewCheckbox()
{
    var o = window.event.srcElement;
    if (o.tagName == "INPUT" && o.type == "checkbox")
    {
       __doPostBack("","");
    } 
}

function popupClose()
{
    if (opener != null) { opener.focus(); }
    window.close();
}

function popupCloseAndPostbackMainPage()
{           
    if(opener!=null && !opener.closed){ 
        opener.focus(); 
    }
    if(opener.postBackOnMainPage){  
        opener.postBackOnMainPage(); //Dominik Amon, 2007-01-02, Check if that method exists! 
    } 
    
    self.close();       
}

// Misc
function defaultAction()
{
    this.focus();
}

function setFormDefaultValues()	
{
    var theForm = document.forms['aspnetForm'];
    if (!theForm) 
    {
        theForm = document.aspnetForm;
    }

    for (var i = 0; i < theForm.elements.length; i++)		
    {    		
        var e = theForm.elements[i];
        
        if (e.type == 'text' && e.value == '')
        {                           
            valueBlur(e);  
        }
    }
}

function clearFormDefaultValues()	
{
    var theForm = document.forms['aspnetForm'];
    if (!theForm) 
    {
        theForm = document.aspnetForm;
    }

    for (var i = 0; i < theForm.elements.length; i++)		
    {    		
        var e = theForm.elements[i];
                
        if (e.type == 'text' && e.value == e.title)
        {
            e.value = '';
        }
    }
}

function valueFocus(e) 
{
    if(e.value == e.title) 
    {
        e.value = '';  
        addRemoveClass(e, 'blur', true);
    }
}

function valueBlur(e) 
{
    if (e.value == '') 
    {
       e.value = e.title; 
       addRemoveClass(e, 'blur', false);
    }
}

function addRemoveClass(e, strClass, bitRemoveOnly) 
{     
   if (e.className)
   {
        var arrList = e.className.split(' ');
        var strClassUpper = strClass.toUpperCase();
                
        for (var i = 0; i < arrList.length; i++)
        {           
           if (arrList[i].toUpperCase() == strClassUpper)
           {              
               arrList.splice(i, 1);               
               i--;
           }
        }     
          
        if (!bitRemoveOnly)
        {           
           arrList[arrList.length] = strClass;           
        }
        
        e.className = arrList.join(' ');
  }   
  else if (!bitRemoveOnly) 
  {
     e.className = strClass;   
  }     
}

// Catch the Key Event
function catchKeyEvent(btnID, event, keyCode)
{
	btn = findObj(btnID);
	if (document.all)
	{
		if (event.keyCode == keyCode)
		{
			event.returnValue=false;
			event.cancel = true;
			btn.click();
		}
	}
	else if (document.getElementById)
	{
		if (event.which == keyCode)
		{
			event.returnValue=false;
			event.cancel = true;
			btn.focus();
			btn.click();
		}
	}
	else if(document.layers)
	{
		if(event.which == keyCode)
		{
			event.returnValue=false;
			event.cancel = true;
			btn.focus();
			btn.click();
		}
	}
}

// Find the Button
function findObj(n, d) 
{ 
	var p,i,x;  
	if(!d) 
		d=document; 
	if((p=n.indexOf("?"))>0 && parent.frames.length) 
	{
		d=parent.frames[n.substring(p+1)].document; 
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) 
		x=d.all[n]; 
	for (i=0;!x&&i<d.forms.length;i++) 
		x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
		x=findObj(n,d.layers[i].document);
	if(!x && d.getElementById) 
		x=d.getElementById(n); 
	return x;
}

// Validation
function DangerousInputValidation(sender, args) 
{                               
    var value = ValidatorGetValue(sender.controltovalidate);
                    
    if (ValidatorTrim(value).length == 0)
        return true;   
             
    var regex = new RegExp("<(.|\n)");
    var matches = regex.exec(value);
                            
    args.IsValid = !(matches != null && matches.length > 0);
}