
function Utilities(){};

// ===========================================================================================
// Utilities.dgs().
// ===========================================================================================
Utilities.dgs = function(address, postcode)
{   
    var link = "http://www.degulesider.dk/vbw/kort/resultat.do?partnerID=kortlink&g="+address+"&z="+postcode+"&b=";
    //alert(link); 
    Utilities.pop(link, 800, 600, 1);
}

// ===========================================================================================
// Utilities.qs().
// ===========================================================================================
Utilities.qs = function(param)
{	
	var qsParm = new Array();
	var query = window.location.search.substring(1);
	var parms = query.split( '&' );

	for (var i=0; i<parms.length; i++) 
	{
		var pos = parms[i].indexOf('=');
		if (pos > 0)
		{
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			qsParm[key] = val;
    }
  }
  if( qsParm[ param ] )
		return qsParm[ param ];
	else
		return null;
}

/// ===========================================================================================
// Utilities.pop().
// ===========================================================================================
Utilities.pop = function(url, width, height, resizable)
{	
	var left = Math.round( Math.round( screen.width / 2 ) - Math.round( width / 2 ) );	
	var top = Math.round( Math.round( screen.height / 2 ) - Math.round( height / 2 ) ) - 100;
	window.open( url, "", "width="+width+",height="+height+",left="+left+",top="+top+",resizable="+resizable+",menubar=no,location=no,scrollbars=yes,status=no" );
}

// ===========================================================================================
// Utilities.registerOnLoadEvent().
// ===========================================================================================
Utilities.registerOnLoadEvent = function(func)
{	
	// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
    var oldonload = window.onload;
    if (typeof window.onload != 'function')
    {
        window.onload = func;
    }
    else
	{
		window.onload = function()
		{
		    if( oldonload ) { oldonload(); }
		    func();
	    }
    }
}

// ===========================================================================================
// Utilities.matchHeight().
// ===========================================================================================
Utilities.matchHeight = function(elementIDArray)
{
    if(elementIDArray == null || (elementIDArray.length < 2))
    {
        alert("Utilities.matchHeight: Parameter must be an array of at least two element ids. Current value = '"+elementIDArray+"'.");
        return; 
    }
    
    var elements = new Array();
    
    for(var i=0; i<elementIDArray.length;i++)
        elements.push(document.getElementById(elementIDArray[i]));
   
    // Find max height.
    var maxHeight = 0;
    for(var i=0; i<elements.length;i++)
        if(elements[i].offsetHeight > maxHeight)
            maxHeight = elements[i].offsetHeight;
   
    // Set max height.
    for(var i=0; i<elements.length;i++)
        elements[i].style.height = (maxHeight + "px");
}

// ===========================================================================================
// Utilities.IsNumeric( input ).
// ===========================================================================================

Utilities.IsNumeric = function( validateMe )
{
	var validChars = "0123456789";
	var isNumber = true;
	var currChar;
	
	for ( i = 0; i < validateMe.length && isNumber == true; i++) 
	{ 
		currChar = validateMe.charAt(i); 
		if ( validChars.indexOf( currChar ) == -1) 
		isNumber = false;
	}
	return isNumber;  
}