/*******************************************************************
* Purpose: Global/common JavaScript functions
* Modified: 2012-01-22 / Tom Schoppema
********************************************************************/

/* Global variables */

var bIsDebugMode = false;
var sHost = "xs4all.nl";
var sUser = "bommel";

// Global variable for Website URL
var sWebsiteURL = "http://www.laranagorda.nl";

/* Functions *******************************************************/

// Check website is framed
function setWebsiteURL()
{
	if ( !bIsDebugMode )
	{
		if ( window.self != window.top || window.location.href.toLowerCase().indexOf(sWebsiteURL ) != 0)
		{
			window.top.location.replace( sWebsiteURL + "/" );
		}
	}
}

function getHtmlElement( sElementID )
{
	var oEl = null;
	
	// NS4
	if ( document.layers && !document.getElementById )
	{
		oEl = document.layers[sElementID];
	}
	// IE4
	else if ( document.all && !document.getElementById )
	{
		oEl = document.all[sElementID];
	}
	else if ( document.getElementById )
	{
		oEl = document.getElementById(sElementID);
	}

	return oEl;
}


function getElementStyleObject( sElementID )
{
	var oStyle = null;
	
	// NS4
	if ( document.layers && !document.getElementById )
	{
		oStyle = document.layers[sElementID];
	}
	// IE4
	else if ( document.all && !document.getElementById )
	{
		oStyle = document.all[sElementID].style;
	}
	else if ( document.getElementById )
	{
		oStyle = document.getElementById(sElementID).style;
	}

	return oStyle;
}

function showHtmlElement( sElementID )
{
	var oStyle = getElementStyleObject( sElementID );
	
	if ( oStyle.display == 'none' )
	{
		oStyle.display = 'block';
	}
	else
	{
		oStyle.display = 'none';
	}
}

function setHtmlElementContent( sElementID, sHtmlText )
{
	getHtmlElement( sElementID).innerHTML = sHtmlText;
}

function addEvent( obj, type, fn )
{
	if ( obj.attachEvent )
	{
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
		obj.attachEvent( 'on'+type, obj[type+fn] );
	}
	else
	{
		obj.addEventListener( type, fn, false );
	}
}
function removeEvent( obj, type, fn )
{
	if ( obj.detachEvent )
	{
		obj.detachEvent( 'on'+type, obj[type+fn] );
		obj[type+fn] = null;
	}
	else
	{
		obj.removeEventListener( type, fn, false );
	}
}

function getWindowHeight()
{
	var myHeight = 0;

	// Non-IE
	if (typeof(window.innerHeight) == 'number')
	{
		myHeight = window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		//IE 6 + in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	}
	else if (document.body && document.body.clientHeight)
	{
		//IE 4 compatible
		myHeight = document.body.clientHeight;
	}
	
	if (myHeight > 900)
	{
		myHeight = 900; // 900 Is height of bg_body.jpg
	}

	return myHeight;
}

// A unit of measure that will be added when setting the position or size of a layer.
function setUnitMeasure()
{
	var sReturn = "";
	// NS4 and Opera
	//if ((document.layers && !document.getElementById) || window.opera)
	if (document.layers && !document.getElementById)
	{
		sReturn = "";
	}
    else
	{
		sReturn = "px";
	}

	return sReturn
}

function reziseHtmlElementHeight(sElementID, iOffsetHeight)
{
	var oStyle = getElementStyleObject(sElementID);
	var iHeight = getWindowHeight() - iOffsetHeight;
	oStyle.height= iHeight.toString(10) + setUnitMeasure(); //'px'
}

// Layer with Clip
function clipTo( sElementID, t, r, b ,l )
{
	oStyle = getElementStyleObject( sElementID );
	px = setUnitMeasure();

	// NS4
    if ( document.layers && !document.getElementById){
        oStyle.clip.top = t;
		oStyle.clip.right = r;
		oStyle.clip.bottom = b;
		oStyle.clip.left = l;
    }
    else {
        oStyle.clip="rect(" + t.toString(10) + px + " " +r.toString(10) + px + " " + b.toString(10) + px + " " + l.toString(10) + px + ")";
    }
}

// Print a content part of a page by opening that piece of content in a new window
function PrintThisPage(sPage) 
{ 
	var sOption="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
	sOption+="resizable=yes,scrollbars=yes,width=750,height=600,left=100,top=25"; 

	var sWinHTML = document.getElementById(sPage).innerHTML; 

	var oWinprint=window.open("","PrintPage",sOption); 
	oWinprint.document.open(); 

	oWinprint.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n");
	oWinprint.document.write("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"nl\" lang=\"nl\">\n");
	oWinprint.document.write("<html>\n"); 
	oWinprint.document.write("<head>\n"); 
	oWinprint.document.write("<title>Tom Schoppema - La Rana Gorda Online</title>\n"); 
	oWinprint.document.write("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />\n"); 
	oWinprint.document.write("<meta http-equiv=\"content-style-type\" content=\"text/css\" />\n"); 
	oWinprint.document.write("<meta name=\"robots\" content=\"noindex, nofollow\" />\n"); 
	oWinprint.document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/includes/stylesheet.css\" />\n"); 
	oWinprint.document.write("<\head>\n");
	oWinprint.document.write("<body style=\"background-image: none; overflow: auto;\" onload=\"document.getElementById('contentprint').style.display='none';\">\n");
	oWinprint.document.write(sWinHTML);          
	oWinprint.document.write("</body>\n</html>\n"); 
	oWinprint.document.close(); 
	oWinprint.focus(); 
}

function popupWindow(contentURL, windowName, windowWidth, windowHeight)
{
	var x = (screen.width - windowWidth ) / 2; 
	var y = (screen.height  - windowHeight ) / 2; 

	var sFeatures  = 'width=' + windowWidth + ',height=' + windowHeight + ',status=no,toolbar=no,menubar=no,scrollbars=auto,resizable=no,location=no,top='+y+',left='+x+'';

	var objNewWindow = window.open(contentURL, windowName, sFeatures);
	objNewWindow.focus();
	return true;
}

function SetDigitalTime(sTagName)
{
	var oTimer			= null;
	var DigitalClock	= new Date();
	var hours			= DigitalClock.getHours();
	var minutes			= DigitalClock.getMinutes();
	var seconds			= DigitalClock.getSeconds();
	var day				= DigitalClock.getDate();
	var days			= new Array("Zo", "Ma", "Di", "Wo", "Do", "Vr", "Za");
	var months			= new Array("Jan", "Feb", "Mrt", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec");
	var dayofWeek		= days[DigitalClock.getDay()];
    var month			= months[DigitalClock.getMonth()];

	if (hours == 0) hours = 12;
	if (minutes <= 9) minutes = "0" + minutes;
	if (seconds <= 9) seconds = "0" + seconds;

	// Change font size here to your desire.
	digclock = "<span>" + dayofWeek +"&nbsp;"+ day +"&nbsp;"+ month + "&nbsp;" + DigitalClock.getFullYear().toString(10) + "&nbsp;"+ hours +":"+ minutes +":"+ seconds + "</span>";

	window.clearTimeout(oDigitalClockTimer); // clear timeout otherwise each time a new timer object is created
	oDigitalClockTimer = window.setTimeout("SetDigitalTime('"+sTagName+"')", 1000);

	// NS4
	if ( document.layers && !document.getElementById )
	{
		document.layers[sTagName].document.open();
		document.layers[sTagName].document.write(digclock);
		document.layers[sTagName].document.close();
	}
	// IE4
	else if ( document.all && !document.getElementById )
	{
		document.all[sTagName].innerHTML = digclock;

	}
	else if (document.getElementById)
	{
		document.getElementById(sTagName).innerHTML = digclock;
	}
}

// Change style of input or textarea field
function SetCssInputField(oHtmlElement, bIsOnFocus, sEmptyValue, sValue)
{
	if (bIsOnFocus)
	{
		if (sValue.toLowerCase() == sEmptyValue.toLowerCase())
		{
			if ((oHtmlElement.tagName.toLowerCase() == "input" && oHtmlElement.type.toLowerCase() == "text") || oHtmlElement.tagName.toLowerCase() == "textarea")
			{
				oHtmlElement.value = ""
			}
		}
		oHtmlElement.className = "TekstOnFocus";
	}
	else
	{
		if (sValue.toLowerCase() != sEmptyValue.toLowerCase() && sValue.length > 0)
		{
			oHtmlElement.className = "TekstOnBlur";
		}
		else
		{
			if ((oHtmlElement.tagName.toLowerCase() == "input" && oHtmlElement.type.toLowerCase() == "text") || oHtmlElement.tagName.toLowerCase() == "textarea")
			{
				oHtmlElement.value = sEmptyValue;
			}
			oHtmlElement.className = "WatermarkTekst";
		}
	}
}

// Used to prevent spam harvesters from getting the email adresses.
function SendEmail()
{
		window.location.href="mailto:" + sUser + "@"+ sHost + "?subject=La Rana Gorda Online";
}
