var browser;

function getBrowser(){
	if( browser == null ){
		browser = parent.BrowserDetect.browser;
	}
	return browser;	
}

/* Returns the document's real height */
function getDocumentHeight(){
	var intDocumentHeight = 0;	
	if (self.innerWidth) {
		intDocumentHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientWidth){
		intDocumentHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		intDocumentHeight = document.body.clientHeight;
	}
	return intDocumentHeight;
}

/* Returns the position for a div [0]=x, [1]=y */
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

/* Sets a layer's height to fill the rest of the entire document */
var initialHeight = 0;
function fillVertically( obj, yPos ){
	if( initialHeight == 0 ){
		initialHeight = obj.clientHeight;
	}
	
	if(yPos == -1){
		yPos = findPos(obj)[1]; // Only use this when needed...
	}

	var docHeight = getDocumentHeight();
	var newLayerHeight = (docHeight - yPos);
	if(newLayerHeight < initialHeight){
		obj.style.height = initialHeight + "px";
		//if(getBrowser() != "Explorer")
		  //alert("Fixa för firefox!");
	} else {
		obj.style.height = newLayerHeight + "px";
	}
}

/* Assigns handlers for the onload and onresize events. 
   Note: This can only be used for document within the iFrame */
function assignHandlers(){
	var myFrame = parent.document.getElementById("Body_IFrame");
	if(myFrame){
		window.onload = onloadHandler;
		if(getBrowser()=="Explorer"){
			myFrame.onresize = onresizeHandler;
		}else{
			window.onresize = onresizeHandler;
		}
	}
}

/* Toggles the "automatic" text in a text-box */
function toggleAutoText( o, text ){
	if( o.value.length == 0 ){
		o.value = text;
	} else if( o.value == text ) {
		o.value = "";
	}
}

/* Prints a list of all properties of an object */
function debug( obj ){
	var output = "";
	for(att in obj){
		output += att + " = " + obj[att] + "\n";
	}
	var ni = document.body;
  	var newdiv = document.createElement('div');
  	var divIdName = 'debug';
  	newdiv.setAttribute('id',divIdName);
  	newdiv.innerHTML = "<xmp>" + output + "</xmp>";
  	ni.appendChild(newdiv);
}

function isValidEmail( email ) {
	returnValue = true;
	var parts = new Array();
	parts = email.split( "@" );
	if( ( !email ) || 
		( parts.length > 2 ) ||
		( email.indexOf( "@" ) == -1 ) ||
		( email.indexOf( "." ) == -1 ) ||
		( email.length < 8 ) ) returnValue = false;
	 		return returnValue;
} 	
