﻿/**
 *  common.js
 *  Elegance Framework - VNW.Web
 *
 *  (c) 2005 - 2008 2G B.V. All rights reserved.
 *  The computer program(s) is the proprietary information of the original authors. 
 *  and provided under the relevant License Agreement containing restrictions 
 *  on use and disclosure. Use is subject to the License Agreement.
 *
 *  No part of this package may be reproduced and/or published by print, 
 *  photoprint, microfilm, audiotape, electronically, mechanically or any other means, 
 *  or stored in an information retrieval system, without prior permission from 2G B.V. www.2g-it.nl.
 * 
 *  @original authors: jwvdiermen
 */

String.prototype.replaceAll = function (sOriginal, sDestination) 
{
	var sReturn = this;
	
	//couldn't find a replaceAll function in the js API, so here it goes:
	while (sReturn.indexOf(sOriginal) >= 0) 
	{
    	sReturn = sReturn.replace(sOriginal, sDestination);
	}
	
	return sReturn;
}//replaceAll

function headerTdMouseover(oSourceObject)
{
	addStyleClass(oSourceObject, 'headerTd_mouseover');
}//headerTdMouseover

function headerTdMouseOut(oSourceObject)
{
	removeStyleClass(oSourceObject, 'headerTd_mouseover');
}//headerTdMouseOut

function middlePanelMouseover(oSourceObject)
{
	addStyleClass(oSourceObject, 'middle_content_mouseover');
}//middlePanelMouseover

function middlePanelMouseOut(oSourceObject)
{
	removeStyleClass(oSourceObject, 'middle_content_mouseover');
}//middlePanelMouseOut

function addStyleClass(oSourceObject, sClass)
{
	var sTemp = oSourceObject.className;
	if (sTemp.indexOf(sClass) == -1)
	{
		sTemp += (' ' + sClass);
	}
	oSourceObject.className = sTemp;
}//addStyleClass

function removeStyleClass(oSourceObject, sClass)
{
	var sTemp = oSourceObject.className;
	sTemp = sTemp.replaceAll((' ' + sClass), '');
	
	oSourceObject.className = sTemp;
}//removeStyleClass

function cursorMouseOver(oTD)
{
	if (oTD.style.backgroundColor != '#d2ac76')
	{
		oTD.bActivated = true;
		oTD.style.backgroundColor = '#d2ac76';
		oTD.children[0].style.color = '#1f1f1f';
	}
	else
	{
		oTD.bActivated = false;
	}
}//cursorMouseOver

function cursorMouseOut(oTD)
{
	if (oTD.bActivated == true)
	{
		oTD.bActivated = false;
		oTD.style.backgroundColor = '#1f1f1f';
		oTD.children[0].style.color = '#d2ac76';
	}
}//cursorMouseOut

function sendForm ()
{
	if (__ID("txtName").value == "")
	{
		alert("Naam is verplicht.");
		__ID("txtName").focus();
	}
	else if (__ID("txtEmail").value == "")
	{
		alert("E-mailadres is verplicht.");
		if (__ID("txtEmail").value == "")
		{
			__ID("txtEmail").focus();
		}
	}
	else
	{
		//Enough form data, submit it.
		document.CONTACT_FORM.submit();
	}
}//sendForm

function __ID (sID)
{
	return document.getElementById(sID);
}//__ID



function selectText(oSourceObject)
{
	if (oSourceObject.value == "zoek product")
	{
		oSourceObject.value = "";
	}
	oSourceObject.createTextRange().select();
	
	try
	{
		oSourceObject.focus();
	}
	catch (eFailedToSetFocus) { /* IGNORE */ }
}//selectText

function keydown_performSearch(oEvent)
{
	var eKey = -1;
	if (typeof(oEvent) == "undefined")
	{
		//IE
		eKey = event.keyCode;
	}
	else
	{
		//Firefox...
		eKey = oEvent.keyCode;
	}
	//var eKey = event.keyCode;
	if (eKey == 13)
	{
		performSearch();
	}
}//keydown_performSearch

function performSearch()
{
	var oSearchBox = document.getElementById("txtSearch");
	var sValue = oSearchBox.value;
	if (sValue != "" && sValue != " " && sValue != "zoek product")
	{
		sValue = sValue.replaceAll(" ", "_S_");
		var sURL = sUrlPrefix + 'search/' + sValue + '/0_1.html';
		window.location = sURL;
	}
}//performSearch

function PrintAanbieding(sImageLocation)
{
	var html = '<html><head><title>'+document.title+'</title></head><body><img style="width: 623px;" src="' + sImageLocation + '" alt="" title="" /></body></html>';
	
	var printWin = window.open("","");
	if(printWin)
	{
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		printWin.print();
	}
	else
	{
		alert('Uw internet browser blokkeert pop-up schermen, waardoor het niet mogelijk is dat deze aanbieding uitgeprint kan worden.');
	}
}


/** 
 * START Webshop methods
 */

function sendRelationForm ()
{
	if (__ID("txtName").value == "")
	{
		alert("Naam is verplicht.");
		__ID("txtName").focus();
	}
	else if (__ID("txtAddress").value == "")
	{
		alert("Adres is verplicht.");
		__ID("txtAddress").focus();
	}
	else if (__ID("txtPostalcode").value == "")
	{
		alert("Postcode is verplicht.");
		__ID("txtPostalcode").focus();
	}
	else if (__ID("txtCity").value == "")
	{
		alert("Plaats is verplicht.");
		__ID("txtCity").focus();
	}	
	else if (__ID("txtEmail").value == "")
	{
		alert("E-mailadres is verplicht.");
		__ID("txtEmail").focus();
	}
	else
	{
		//Enough form data, submit it.
		var sUrl = sUrlPrefix + "webshop/" + sCartId + "/submitcart/-1/-1/nostalgischwonen_webshop.html";
		//window.location.href = sUrl;
		//Set_Cookie( 'show_payment_button', 'true', '', '/', '', '' );
		document.SHOP_FORM.submit();
		//document.BuckarooForm.submit();
	}
}//sendRelationForm
 
function UpdateShoppingCartQuantity(oQuantityElement, sItemId)
{
	var sUrl = sUrlPrefix + "webshop/" + sCartId + "/updateitem/" + sItemId + "/" + oQuantityElement.value + "/nostalgischwonen_webshop.html";
	window.location.href = sUrl;
}

function RemoveShoppingCartQuantity(sItemId)
{
	var bContinue = confirm("Weet u zeker dat u het artikel wilt verwijderen uit de winkelwagen?");
	if (bContinue == true)
	{
		var sUrl = sUrlPrefix + "webshop/" + sCartId + "/removeitem/" + sItemId + "/-1/nostalgischwonen_webshop.html";
		window.location.href = sUrl;
	}
}


function Set_Cookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( name ) {

var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}

function Delete_Cookie( name, path, domain ) 
{
	var d = new Date();
    document.cookie = name+"=1;expires=" + d.toGMTString() + ";" + ";";	
}

/**
 *	END Webshop methods
 */
