var sHost = this.location.host;



// Check what browser the client uses.

var agt = navigator.userAgent.toLowerCase();

var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) 

				&& (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)

				&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));

var is_opera = (agt.indexOf('opera')!=-1);

var is_ie = (agt.indexOf('msie')!=-1) && !is_opera ;



function disableEnterKey(){

	if (window.event.keyCode == 13) window.event.keyCode = 0;

}



// This function blocks the use of PRINT-SCREEN

function setClipBoardData(){

	setInterval("window.clipboardData.setData('text','')",20);

}

//function blockError(){

//	window.location.reload(true);

//	return true;

//}

//window.onerror = blockError;



function ChangeMenu(item){

	document.getElementById('fMenu').iMenu_id.value = item;

	document.getElementById('fMenu').submit();

}



function ChangeMenuPage(sFieldName, sType, iMenu_id, iMenu_detail_order, sQueryString) {

	iPage = document.getElementById(sFieldName).value;

	window.location = "http://" + sHost + "/" + sType + "/" + iMenu_id + "/" + iMenu_detail_order + "/page/" + iPage + ".html" + sQueryString;

}



function ChangePage(iMenu_id,iMenu_detail_order){

	document.getElementById('fMenu').iMenu_id.value = iMenu_id;

	document.getElementById('fMenu').iMenu_detail_order.value = iMenu_detail_order;

	document.getElementById('fMenu').submit();

}



function toggleLargeFont(bLargeFont) {

	document.getElementById('fMenu').bLargeFont.value = bLargeFont;

	document.getElementById('fMenu').submit();

}



function OnTop(){

	window.focus();

}



// Function opens a new window with a specified url.

function openNewWindow(URLtoOpen, windowName, windowFeatures){ 

	newWindow = window.open(URLtoOpen, windowName, windowFeatures); 

	//newWindow.moveTo((screen.height-250)/2,(screen.width-400)/2)

}



// =================== begin: Select box functions. =================== //

function MoveUp(combo_name)

{

	var combo=document.getElementById(combo_name);

	i=combo.selectedIndex;

	if (i>0)

	{

		swap(combo,i,i-1);

		combo.options[i-1].selected=true;

		combo.options[i].selected=false;

	}

}



function MoveDown(combo_name)

{

	var combo=document.getElementById(combo_name);

	i=combo.selectedIndex;



	if (i<combo.length-1 && i>-1)

	{

		swap(combo,i+1,i);

		combo.options[i+1].selected=true;

		combo.options[i].selected=false;

	}

}



//this function is used to swap between elements

function swap(combo,index1, index2)

{

	var savedValue=combo.options[index1].value;

	var savedText=combo.options[index1].text;



	combo.options[index1].value=combo.options[index2].value;

	combo.options[index1].text=combo.options[index2].text;



	combo.options[index2].value=savedValue;

	combo.options[index2].text=savedText;

}



function MoveToTop(combo_name)

{

	var combo=document.getElementById(combo_name);

	i=combo.selectedIndex;

	

	for (;i>0;i--)

	{

		swap(combo,i,i-1);

		combo.options[i-1].selected=true;

		combo.options[i].selected=false;

	}

}



function MoveToBottom(combo_name)

{

	var combo=document.getElementById(combo_name);

	i=combo.selectedIndex;

	

	if (i>-1)

	{

		for (;i<combo.length-1;i++)

		{

			swap(combo,i+1,i);

			combo.options[i+1].selected=true;

			combo.options[i].selected=false;

		}

	}

}



//moves options from one selection box (combo box) to another

//removes the all selected options from one combo box and adds them to the second combo box

function MoveElements(FromComboName,ToComboName)

{

	var FromCombo=document.getElementById(FromComboName);

	var ToCombo=document.getElementById(ToComboName);



	var to_remove_counter=0; //number of options that were removed (num selected options)



	//move selected options to right select box (to)

	for (var i=0;i<FromCombo.options.length;i++)

	{

		if (FromCombo.options[i].selected==true)

		{

			var addtext=FromCombo.options[i].text;

			var addvalue=FromCombo.options[i].value;

			ToCombo.options[ToCombo.options.length]=new Option(addtext,addvalue);

			FromCombo.options[i].selected=false;

			++to_remove_counter;

		}

		else

		{

			FromCombo.options[i-to_remove_counter].selected=false;

			FromCombo.options[i-to_remove_counter].text=FromCombo.options[i].text;

			FromCombo.options[i-to_remove_counter].value=FromCombo.options[i].value;

		}

	}



	//now cleanup the last remaining options 

	var numToLeave=FromCombo.options.length-to_remove_counter;

	for (i=FromCombo.options.length-1;i>=numToLeave;i--) 

	{ 

		FromCombo.options[i]=null;

	}

}



// Select all items in selectfield.

function SelectAll(combo_name){

	var combo=document.getElementById(combo_name); //get the select

	

	// Set every item to selected.

	for (var i=0;i<combo.options.length;i++){

		combo.options[i].selected=true;

	}

}

// =================== end: Select box functions. =================== //





// ==================== begin: Calendar functions. ====================

function CalendarPage(iMenu_id,sDate){

	document.getElementById('fMenu').iMenu_id.value = iMenu_id;

	document.getElementById('fMenu').sDate.value = sDate;

	document.getElementById('fMenu').submit();

}

// ==================== end: Calendar functions. ====================





// ==================== begin: Poll functions. ====================

function pollResult(iMenu_id,bShow){

	document.getElementById('fMenu').iMenu_id.value = iMenu_id;

	document.getElementById('fMenu').bShowPollResult.value = bShow;

	document.getElementById('fMenu').submit();

}

// ==================== end: Poll functions. ====================





// ==================== begin: News details functions. ====================

function newsDetailPage(iMenu_id,iNews_id){

	document.getElementById('fMenu').iMenu_id.value = iMenu_id;

	document.getElementById('fMenu').iNews_id.value = iNews_id;

	document.getElementById('fMenu').submit();

}

// ==================== end: News details functions. ====================





// ==================== begin: Flexpool functions. ====================

function flexpoolAction(iFlexpool_id,sAction,iDaypart_current,iDaypart){

	document.getElementById('flexpool_result_form').iFlexpool_id.value = iFlexpool_id;

	document.getElementById('flexpool_result_form').iDaypart_current.value = iDaypart_current;

	document.getElementById('flexpool_result_form').iDaypart.value = iDaypart;

	document.getElementById('flexpool_result_form').sAction.value = sAction;

	document.getElementById('flexpool_result_form').submit();

}

// ==================== end: Flexpool functions. ====================





// ==================== begin: Shopping cart functions. ====================

// Add product to cart.

function fCartAdd(iProduct_id,iMenu_id){

	error = false;

	//error = fCartAddValidateOption(item, 2, error); // color

	//error = fCartAddValidateOption(item, 3, error); // size

	//error = fCartAddValidateOption(item, 4, error); // material

	

	if(error){

		return;

	}else{

		document.getElementById(iProduct_id).sAction.value = 'cart_add';

		document.getElementById(iProduct_id).iProduct_id.value = iProduct_id;

		document.getElementById(iProduct_id).iMenu_id.value = iMenu_id;

		document.getElementById(iProduct_id).submit();

	}

}



// Validate options.

function fCartAddValidateOption(item, iIndex, error){

	select = document.getElementById('id[' + item + '][' + iIndex + ']');

	

	if ( select.nodeName.toLowerCase() != 'select' )

		return error;

	

	if ( select.options[select.selectedIndex].value == 0 ) {

		document.getElementById('id[' + item + '][' + iIndex + '][alert]').style.display = '';

		error = true;

	} else {

		document.getElementById('id[' + item + '][' + iIndex + '][alert]').style.display = 'none';

	}

	

	return error;

}



// Add product to cart from list.

function fCartAddList(sFormname, iMenu_id){

	document.getElementById(sFormname).sAction.value = 'cart_order_multi';

	document.getElementById(sFormname).iMenu_id.value = iMenu_id;

	document.getElementById(sFormname).submit();

}



// Remove product from cart.

function fCartDel(item){

	document.getElementById('fCart').iArrayKey.value = item;

	document.getElementById('fCart').sAction.value = 'cart_delete';

	document.getElementById('fCart').submit();

}



// Change content of cart.

function fCartChange(){

	document.getElementById('fCart').sAction.value = 'cart_change';

	document.getElementById('fCart').submit();

}

// ==================== end: Shopping cart functions. ====================





// ==================== end: Product functions. ====================

function fProductDetail(iMenu_id,iProduct_id){

	document.getElementById(iProduct_id).iMenu_id.value = iMenu_id;

	document.getElementById(iProduct_id).iProduct_id.value = iProduct_id;

	document.getElementById(iProduct_id).submit();

}

// ==================== end: Product functions. ====================





// ==================== begin: Upload functions. ====================

var regexZip = /\.zip$/i;

var regexResize = /\.(jpg|jpeg|png|gif|wbmp)$/i;



function uploadChangeFile(inputFile) {

	// Show/hide zip fields

	if ( document.getElementById('uploadFileZip') != null )

	{

		if (regexZip.test(inputFile.value)) {

			document.getElementById('uploadFileZip').style.display = '';

		} else {

			document.getElementById('uploadFileZip').style.display = 'none';

		}

	}



	// Show/hide resize fields

	if ( document.getElementById('uploadFileResize') != null )

	{

		if (regexResize.test(inputFile.value) || (regexZip.test(inputFile.value) && document.getElementsByName('bUpload_extract')[0].checked)) {

			document.getElementById('uploadFileResize').style.display = '';

		} else {

			document.getElementById('uploadFileResize').style.display = 'none';

		}

	}	

}

// ==================== end: Upload functions. ====================





// ==================== begin: Wysiwyg editor functions. ====================

// Function is used to insert the wysiwyg data into a hidden field.

// Function is only called from the save button (inc_action.php).

function saveHtml(formName){

	// Check if wysiwyg formfield is present.

	if(document.getElementById('cms_edit_form').htmlEditField){

		// If present store data in hidden field.

		saveHtmlBody(oEdit1.getHTMLBody(),formName);

	}

}

// ==================== end: Wysiwyg editor functions. ====================





// ==================== begin: submitFrom function. ====================

// Function is use to set the value of "sAction".

function submitFrom(actionValue, formName){

	document.getElementById(formName).sAction.value = actionValue;

	document.getElementById(formName).submit();

}

// ==================== end: submitFrom function. ====================





// ==================== begin: viewImage function. ====================

// Function is use to display an image in a popup.

function viewImage(src, width, height, alt){

	var fraction = 1;

	var scrollbars = 0;

	var url = "/pages/view_image.php?sSrc=" + escape(src) + "&iWidth=" + width + "&iHeight=" + height + "&sAlt=" + alt;

	

	if ( width > (screen.availWidth * fraction) ) {

		width = (screen.availWidth * fraction)

		scrollbars = 1;

	}

	

	if ( height > (screen.availHeight * fraction) ) {

		height = (screen.availHeight * fraction);

		scrollbars = 1;

	}

	

	window.open(url, 'alt', "toolbar=no, location=no, menubar=no, fullscreen=0, resizable=0, channelmode=0, status=no, scrollbars=" + scrollbars + ", width=" + width + ", height=" + height);

}

// ==================== end: viewImage function. ====================





// ==================== begin: limitText function. ====================

// Function is use to display a character countdown.

// limitField = name of field that should be counted.

// limitCount = field inwhich the countdown should be shown.

// limitNum   = Maximum number of characters.

function limitText(limitField, limitCount, limitNum){

	if(document.getElementById(limitField).value.length > limitNum){

		document.getElementById(limitField).value = document.getElementById(limitField).value.substring(0,limitNum);

	}else{

		document.getElementById(limitCount).value = limitNum - document.getElementById(limitField).value.length;

	}

}

// ==================== end: limitText function. ====================





// Fix for IE patch (automatically enables flash etc.)

if(is_ie) {

	window.onload = function() { 

		var objects = document.getElementsByTagName("object"); 

		for(var i = 0; i != objects.length; i++) { 

			objects[i].outerHTML = objects[i].outerHTML; 

		} 

	}

}





// ==================== begin: disableFormField function. ====================

// Function is use to enable/disable formfields.

// obj = name of form field that should be troggled (document.getElementById('fCart').sAction_submit_order).

function disableFormField(obj){

	obj.disabled = !(obj.disabled);

}

// ==================== end: disableFormField function. ====================



// ==================== begin: cookie functions. ====================

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 * 24;

	}

	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 ) {

	if ( Get_Cookie( name ) ) document.cookie = name + "=" +

			( ( path ) ? ";path=" + path : "") +

			( ( domain ) ? ";domain=" + domain : "" ) +

			";expires=Thu, 01-Jan-1970 00:00:01 GMT";

}

// ==================== end: cookie functions. ====================





// ==================== end: E-card functions. ====================

function fShowPic(sError,sSource_error,sSource){

	// If error is true, display default image.

	if(sError == 1){

		sSource = sSource_error;	

	}

	

	//alert(sError+" "+sSource);

	document.getElementById('ecard_img').src = sSource;

	return false;

}

// ==================== end: E-card functions. ====================
