var insyma = new InsymaUtilities();

function InsymaUtilities()
{
	this.window = new InsymaWindow();
	this.xmlhttp = new InsymaXmlHttp();
	this.queryString = InsymaQueryString();
}


function InsymaWindow()
{
	this.getInnerHeight =  InsymaInnerHeight;
	this.getInnerWidth = InsymaInnerWidth;
	this.getScrollTop = InsymaScrollTop;
	this.getScrollLeft = InsymaScrollLeft;



	// Eigenschaften und Methoden des insyma Window objekt

	function InsymaInnerHeight()
	{
		 var height = 0;
		  if( typeof( window.innerHeight) == 'number' )
		  {
		    //Non-IE
			height = window.innerHeight;
		  }
		  else if( document.documentElement && document.documentElement.clientHeight   )
		  {
		     //IE 6+ in 'standards compliant mode'
		    height = document.documentElement.clientHeight;
		  }
		  else if( document.body && document.body.clientHeight )
		  {
		    //IE 4 compatible
		    height = document.body.clientHeight;
		  }
		return height;
	}

	function InsymaInnerWidth()
	{
		 var width = 0;
		  if( typeof( window.innerWidth ) == 'number' )
		  {
		    //Non-IE
		    width = window.innerWidth;
		  }
		  else if( document.documentElement && document.documentElement.clientWidth  )
		  {
		     //IE 6+ in 'standards compliant mode'
		    width = document.documentElement.clientWidth;
		  }
		  else if( document.body && document.body.clientWidth )
		  {
		    //IE 4 compatible
		    width = document.body.clientWidth;
		  }
		return width;
	}


	function InsymaScrollTop()
	{
		var y;
		if (self.pageYOffset) // all except Explorer
		{
			y = self.pageYOffset;
		}
		else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
		{
			y = document.documentElement.scrollTop;
		}
		else if (document.body) // all other Explorers
		{
			y = document.body.scrollTop;
		}

		return y
	}


	function InsymaScrollLeft()
	{
		var x;
		if (self.pageYOffset) // all except Explorer
		{
			x = self.pageXOffset;
		}
		else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
		{
			x = document.documentElement.scrollLeft;
		}
		else if (document.body) // all other Explorers
		{
			x = document.body.scrollLeft;
		}
		return x
	}
}

function InsymaXmlHttp() {
	var xmlhttp
	try {
		// Mozilla / Safari
		xmlhttp = new XMLHttpRequest();
	}
	catch (e) {
		// IE
		var MSXML_XMLHTTP_PROGIDS = new Array(
                'MSXML2.XMLHTTP.5.0',
                'MSXML2.XMLHTTP.4.0',
                'MSXML2.XMLHTTP.3.0',
                'MSXML2.XMLHTTP',
                'Microsoft.XMLHTTP'
            	);
            	var success = false;
            	for (var i=0;i < MSXML_XMLHTTP_PROGIDS.length && !success; i++) {
                	try {
	                    xmlhttp = new ActiveXObject(MSXML_XMLHTTP_PROGIDS[i]);
	                    success = true;
                } catch (e) {}
            	}
            	if ( !success ) {
               		alert('Cant create XMLHttpRequest - not supported');
            	}
	}
	return xmlhttp
}

function InsymaQueryString()
{
	var queryArray = new Array();
	var query = window.location.search.substring(1);

		 var vars = query.split("&");
		 for (var i=0;i<vars.length;i++) {
			try{
		   		var pair = vars[i].split("=");
		   		var myString = new String(pair[0]);
		   		queryArray[myString] = pair[1];

		   } catch (e) {}
		 }
		  return queryArray;
}

// Formular Test (MUFC 2006)
// Alle Abtestungen geben bei NULL true zurueck
function ValidateEmail(field) {
	if (field.value != ""){
		return(/^([a-zA-Z0-9_\-\&\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/i.test(field.value));
	} else { return(true);}
}

function ValidateDigits(field) {
	field.value = field.value.replace(/\s/g, "");
	return(/^\d*$/i.test(field.value));
}

function ValidateIntegers(field) {
	return(/^[-+]?\d*$/i.test(field.value));
}

function ValidateDecimal(field) {
	return(/^[-+]?[\d+(\.\d{1,2})?]*$/i.test(field.value));
}

function ValidatePhone(field) {
	if (field.value != ""){
		field.value = field.value.replace(/[\(\)\.\'\-,]/g, " ");
		return(/^[+]?\d+[\s]?[\d+]?[\s]?[\d+]?[\s]?[\d+]?[\s]?[\d+]?[\s]?[\d+]?[\s]?$/i.test(field.value));
	} else { return(true);}
}

function ValidateCurrency(field) {
	return(/^[-+]?[\d+(\.\d{0,2})?]*$/i.test(field.value));
}

function ValidateRadio(field,fieldCount) {
	var isOK = false;
	for (i=0;i<fieldCount;i++){
		if (field[i].checked==true){
			isOK = true;
		}
	}
	return(isOK);
}
// SPAM Schutz f�r E-Mail von HAEP eingef�gt durch HAGS 14. Sept. 2007
function mt()
    {
        var atags = document.getElementsByTagName("a");
        var decoded = "";
        for (var i=0; i<atags.length ; i++)
        {  
        
           if (atags[i].href.indexOf("L_") > -1 )
           {
               var link=atags[i].href.substring(atags[i].href.indexOf("L_")+2);
               
               link=link.replace(/__/g, ".").replace(/--/g, "@");
                decoded = decodemt(link);
		
               if(atags[i].innerHTML.indexOf("L_")>-1 && atags[i].innerHTML.indexOf("L_") < 2){
                   atags[i].innerHTML = decoded ;
               }
               if(atags[i].title.indexOf("L_")>-1){
               	atags[i].title=decoded;
               }
               atags[i].href = 'mailto:' + decoded;
           }
        }
    }    
    
    function decodemt(adresse)
    {   
        var result ="";
        var chr 
        for (var i = 0; i < adresse.length; i++) 
        { 
            chr = adresse.charAt(i);
            /*if (chr == "__"){chr = "."}
            if (chr == "}"){chr = "@"}*/
            result = chr + result ;
        }
        return result;
    }
	
function addEvent(elm, evType, fn, useCapture){
	if (elm.addEventListener){
 		elm.addEventListener(evType, fn, useCapture);
 		return true;
 	} else if (elm.attachEvent) {
 		var r = elm.attachEvent('on' + evType, fn);
 		return r;
 	} else {
 		elm['on' + evType] = fn;
 	}
 }
addEvent(window,'load',mt,false);