// VAL OR NIL

// returns true if a variable exists and does not have a value that is null
if (TVGS) TVGS.set = function (variable)
{
	
	if (variable === null || typeof variable == 'undefined') return false;
	else return true;

}


// returns true if a variable exists and does not have a value that is null
if (TVGS) TVGS.val = function (variable)
{
	
	if (variable === null || typeof variable == 'undefined') return false;
	else return true;

}

// returns true if a variable does not exist or has a value that is null
if (TVGS) TVGS.nil = function (variable)
{
	
	if (variable === null || typeof variable == 'undefined') return true;
	else return false;

}

// returns true if a variable has an integer value of zero or higher
// note: used to check for numeric array keys
if (TVGS) TVGS.key = function (variable)
{

	if (parseInt(variable) == variable && (variable * 1) >= 0) return true;
	else return false;

}

//alert(TVGS.key(4));


// prints a value to the innerhtml of the element with id "tvgs_output", unless specified otherwise
// note: method can be "append" or "replace"
// note: setting element_id sends the output to another element
if (TVGS) TVGS.print = function (output, method, element_id)
{
	// set output element id
	if (element_id == null) element_id = 'tvgs_output';
	
	// get output element
	var tvgs_output = document.getElementById(element_id);
	
	if (TVGS.val(tvgs_output))
	{
		// make into string
		output = output + '';
		
		// update output element
		if (method == 'append' || method == null)
		{
			tvgs_output.innerHTML += output;
		}
		else if (method == 'replace')
		{
			tvgs_output.innerHTML = output;
		}
	}
	else
	{
		alert('Scriptician was unable to print to screen! The target HTML element with ID attribute "' + element_id + '" does not exist on the page.');
	}
}





// stretch background image
if (TVGS) TVGS.stretch_main_bg_image = function(img_id)
{

	// get info
	if (!document.getElementById(img_id)) return;
	
	var image = document.getElementById(img_id);
	
	var image_div = document.getElementById(img_id + '_div');
	
	if (image.nodeName != 'IMG' && image.style.position != 'absolute') return;
	
	var image_width = image.width;
	var image_height = image.height;
	
	
	
	if (window.innerWidth && window.innerHeight)
	{
		var viewport_width = window.innerWidth;
		var viewport_height = window.innerHeight;
	}
	else
	{
		var viewport_width = document.body.clientWidth;
		var viewport_height = document.body.clientHeight;
	}
	
	var renderport = document.getElementsByTagName("BODY")[0];
	
	if (renderport.offsetWidth > viewport_width) viewport_width = renderport.offsetWidth;
	if (renderport.offsetHeight > viewport_height) viewport_height = renderport.offsetHeight;
	
	
	
	
	// alert('viewport is ' + viewport.offsetWidth + 'pixels high x ' + viewport.offsetHeight + 'pixels wide');
	
	
	//calc new image size and offset
	
	// get image aspect
	var image_aspect = image_width / image_height;
	
	// get viewport aspect
	var viewport_aspect = viewport_width / viewport_height;
	
	if (image_aspect < viewport_aspect) // viewport is flatter, stretch image to viewport width
	{
		
		var upscale_factor = viewport_width / image_width;
		
		var new_image_width = viewport_width;
		var new_image_height = Math.ceil(image_height * upscale_factor);
		var new_image_top = Math.round((viewport_height - new_image_height) / 2);
		
		image.style.width = new_image_width + 'px';
		image.style.height = new_image_height + 'px';
		image.style.top = new_image_top + 'px';
		
		// use clip to get rid of scrollbars
		// note: uses clip property: "clip: rect(10px, 40px, 100px, 5px);"
		// note: clip style usage: top (y1clip), right (from left) (x2clip), bottom (from top) (y2clip), left (x1clip)
		
		
		//image.style.clip = 'rect(0px, ' + new_image_width + 'px, ' + (new_image_top + viewport_height) + 'px, 0px)';
		
		//image_div.style.width = viewport_width + 'px';
		//image_div.style.height = viewport_height + 'px';
	
	}
	else // image is flatter, stretch image to viewport height
	{
	
		var upscale_factor = viewport_height / image_height;
		
		var new_image_width = Math.ceil(image_width * upscale_factor);
		var new_image_height = viewport_height;
		var new_image_left = Math.round((viewport_width - new_image_width) / 2);
	
		image.style.width = new_image_width + 'px';
		image.style.height = new_image_height + 'px';
		image.style.left = new_image_left + 'px';
		
		//image.style.clip = 'rect(0px, ' + new_image_width + 'px, ' + (new_image_top + viewport_height) + 'px, 0px)';
		
		
	}

	image_div.style.width = (viewport_width - 25) + 'px';
	image_div.style.height = (viewport_height - 25) + 'px';
		

}





// rounds a number and returns a string with trailing zero's
// example: rounding 5.4000 to two decimals is returned as "5.40" instead of "5.4"
function tvgs_round_to_string(number, decimals, direction)
{
	
	var decimal_factor = '1';
	var decimal_count = decimals;
	
	while (decimal_count > 0)
	{
		
		decimal_factor = decimal_factor + '0'
	
		decimal_count--;
	
	}
	
	decimal_factor = decimal_factor * 1;
	
	
	
	var numeric = Math.round(number * decimal_factor) / decimal_factor;
	
	var as_string = numeric + '';
	

	var string_length = (Math.round(number) + '').length;
	
	
	var target_length = string_length + 1 + decimals;

	
	while(as_string.length < target_length)
	{
		
		if (as_string.length == string_length)
		{
			as_string = as_string + '.';
		}
		else
		{
			as_string = as_string + '0';
		}
	}
	
	return as_string;

}





// opens url in the specified target: "self", "top", "blank"
function tvgs_open_url(url, target)
{
	
	
	if (target == 'top' || target == '_top')
	{
		
		top.location.href = url;
		
		return;
	
	}
	else if (target == 'blank' || target == '_blank')
	{
		
		window.open(url);
		
		return;
	
	}
	else if (target == null || target == '' || target == 'self' || target == '_self')
	{
		
		//alert('url redirect:' + url);
		window.location.href = url;
		
		return;
	
	}
	else
	{
	
		return;
		
	}
	
}


// looks for the first form node enclosing the submit element, then submits the form
function tvgs_get_enclosing_form_element(nested_submit_element)
{
	
	// set search parameters
	var candidate_element = nested_submit_element.parentNode;


	while(candidate_element)
	{
	
		if (candidate_element.nodeName == 'FORM')
		{
			
			//candidate_element.submit();
			
			
			return candidate_element;
			
		}
		else if (candidate_element.nodeName == 'HTML')
		{
			
			return false;
			
		}
		else
		{
		
			// update search element
			candidate_element = candidate_element.parentNode;

		}
		
	}
	
	
	return false;

}



function background_color_transition(element)
		{
		
			var colors = [];
			colors[0] = '#88007D';
			colors[1] = '#880078';
			colors[2] = '#890073';
			colors[3] = '#8A006C';
			colors[4] = '#8B0065';
			colors[5] = '#8C005E';
			colors[6] = '#8D0056';
			colors[7] = '#8E004F';
			colors[8] = '#8F0047';
			colors[9] = '#900041';
			colors[10] = '#91003B';
			colors[11] = '#910035';
			
			
			
			var steps = colors.length;
			var step = 0;
			
			function color_step()
			{
				
				if (step == steps)
				{
				
					clearInterval(interval_id);
					
					//alert('interval cleared');
					return;
				}
				
				
				
				element.style.backgroundColor = colors[step];
				
				
				step = step + 1;
				//alert(step);
			
			}
			
			
			
			
			//instruction = 'this.style.backgroundColor='';
			
			var interval_id = setInterval(color_step,70);
			
			element.name = interval_id;
			
			//alert(interval_id);
			
		
		
		
		}


	
		function color_pulse(color_list, element, style_attribute, speed)
		{
		/*
		
		 // color list example
			var colors = [];
			colors[0] = '#88007D';
			colors[1] = '#880078';
			colors[2] = '#890073';
			colors[3] = '#8A006C';
			colors[4] = '#8B0065';
			colors[5] = '#8C005E';
			colors[6] = '#8D0056';
			colors[7] = '#8E004F';
			colors[8] = '#8F0047';
			colors[9] = '#900041';
			colors[10] = '#91003B';
			colors[11] = '#910035';
			
			*/
			
			var steps = color_list.length - 1;
			var step = 0;
			var direction = 'up';
			
			function color_step()
			{
				 
					// determine step
				 if (steps > 0)
					{
						
	
									if (step < steps && direction == 'up')
									{
										
										step = step + 1;
										
									
										
										//clearInterval(interval_id);
										
										//alert('interval cleared');
										//return;
									
									}
									else if (step == steps)
									{
										direction = 'down';
										step = step - 1;
										
									}
									else if (step > 0 && direction == 'down')
									{
										
										step = step - 1;
										
									}
									else if (step == 0)
									{
										direction = 'up';
										step = step + 1;
										
									}
				
						}
				
				
				  eval('element.style.' + style_attribute + ' = color_list[step];');
			  	//element.style.style_attribute = colors[step];
				
				
			  
			
			}
			
			
			
			
			//instruction = 'this.style.backgroundColor='';
			
			window.interval_id = setInterval(color_step, speed);
			
			//element.name = interval_id;
			
			//alert(interval_id);
			
		
		
		
		}
		
		
		






/* This function switches display of two page elements (one disappears, the other appears... and vice versa) */


function tvgs_element_display_switch_by_id(id1,id2)
{

	// check if elements exist
	if (document.getElementById(id1) && document.getElementById(id2))
	{
	
		// modified to always show one or the other
		// the original (escaped below) made it possible to accidentally show or hide both elements
		
		var el1 = document.getElementById(id1);
		var el2 = document.getElementById(id2);
	
		if ( el1.style.display != 'none' )
		{
			el1.style.display = 'none';
			el2.style.display = '';
		}
		else 
		{
			el1.style.display = '';
			el2.style.display = 'none';
		}
		
		/*
		if ( el2.style.display != '' )
		{
			el2.style.display = '';
		}
		else
		{
			el2.style.display = 'none';
		}
		*/
	
	}
	
}

// tvgs legacy fix
// note: do not use this, always use the new function name
function switchDisplay(id1,id2)
{

	tvgs_element_display_switch_by_id(id1,id2);

}


// set display of elements of listed id's to "none" or ""
function tvgs_display_set(id_list, action)
{
	
	for (var i in id_list)
	{
	
		// check if element exists
		if (document.getElementById(id_list[i]))
		{
		
			var element = document.getElementById(id_list[i]);

			if (action == 'hide' ) element.style.display = 'none';
			
			if (action == 'show' ) element.style.display = '';
	
		}
	
	}
	
}



// shows an element by id
function tvgs_element_show_by_id(id1)
{
	
	// check if element exists
	if (document.getElementById(id1))
	{
	
		
	
		var el1 = document.getElementById(id1);
		
		//if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Popup type 1: status of "' + id1 + '" display is "' + el1.style.display + '".<br>';
		/*
		if ( el1.style.display != 'none' )
		{
				
				return;
				
		}
		else
		{
		*/
			el1.style.display = '';
		
		//}
		
	}
	
}



// hides an element
function tvgs_element_hide(el1)
{
	
	// check if element exists
	if (el1)
	{
	
		
	
		el1.style.display = 'none';
		
		if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'General function: hiding element.<br>';
	
	}
	
}



// shows or hides an element based on its current display state
function tvgs_display_toggle(id1)
{
	
	// check if element exists
	if (document.getElementById(id1))
	{
	
		var el1 = document.getElementById(id1);
		
		
		if (el1.style.display != 'none')
		{
				
			el1.style.display = 'none';
				
		}
		else
		{
	
			el1.style.display = '';
		
		}
		
	}
	
}


// compatibility fix
function tvg_display_toggle(id1,id2)
{

	tvgs_display_toggle(id1,id2);

}




/* for popups, fades the active part */

function switchDisplayFade(id1,id2)
{
	
	// check if elements exist
	if (document.getElementById(id1) && document.getElementById(id2))
	{
	
		// modified to always show one or the other
		// the original (escaped below) made it possible to accidentally show or hide both elements
		
		var el1 = document.getElementById(id1);
		var el2 = document.getElementById(id2);
	
		if ( el1.style.display != 'none' )
		{
			fade_out_element(el1, 10);
			el2.style.display = '';
		}
		else 
		{
			el1.style.display = '';
			fade_out_element(el2, 10);
		}
		
		
		
		
		/*
		if ( el2.style.display != '' )
		{
			el2.style.display = '';
		}
		else
		{
			el2.style.display = 'none';
		}
		*/
	
	}
	
}


function fade_out_element(id, step_size)
{

	// check if elements exist
	if (document.getElementById(id))
	{
	
		var element = document.getElementById(id);
		
	
	
	
	
		// work with 2 counters for different browsers
	
		//var start_opacity = 1;
		//var step_opacity_size = step_size / 100;
		
		var start_filter = 100;
		var step_filter_size = step_size;
		
		
		
		
		// decrease opacity first step
		//start_opacity = start_opacity - step_opacity_size;
		//start_filter = start_filter - step_filter_size;
		
		
		// make style strings first step
		//var step_opacity_string = '0.' + start_filter;
		//var step_filter_string = 'alpha(opacity=' + start_filter + ')';
			
			
		
		function opacity_step()
		{
			
			// decrease opacity
			//start_opacity = start_opacity - step_opacity_size;
			start_filter = start_filter - step_filter_size;
		
			//if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Popup: stepping opacity to ' + step_opacity_string + ' / ' + step_filter_string + '.<br>';	
			
			// intercept end
			if (start_filter <= 0)
			{
				
				// stop fading
				clearInterval(window.fade_out_interval_id);
				window.fade_out_interval_id = 0;
				
				// hide element
				element.style.display = 'none';
				
				// restore opacity
				element.style.opacity = '1';
				element.style.filter = 'alpha(opacity=100)';
			
				//return;
				
			}
			else
			{
			
				// make style strings
				step_opacity_string = '0.' + start_filter;
				step_filter_string = 'alpha(opacity=' + start_filter + ')';
				
				
				// update element
				element.style.opacity = step_opacity_string;
				element.style.filter = step_filter_string;
			
			}
			
		
		}
		
		
		if (!window.fade_out_interval_id || window.fade_out_interval_id == 0)
		{
		
			window.fade_out_interval_id = setInterval(opacity_step, 50);
		
		}
		
		
		
	}
	
	//element.name = interval_id;
	
	//alert(interval_id);

}


// v1 2009-01-09
// shows or hides an image by growing and shrinking
// todo: calculate step trajectory
// note: the image will be really gone from the screen when shrunk, and have its display set to none
// note: step_size defaults to 1 pixel
// note: axis defaults to "both" or "xy" when omitted, and accepts "horizontal", "h", "x", "vertical", "v", "y"
function tvgs_img_pop(img_id, step_size, axis)
{
	
	// check if element exists
	if (document.getElementById(img_id))
	{
	
		var image = document.getElementById(img_id);
		
		// check if its an image
		if (image.nodeName == 'IMG')
		{
			
			// get original height
			if (image.style.height != '')
			{
				var image_height = image.style.height.replace(/px/, '') * 1; // style values are strings
			}
			else
			{
				var image_height = image.height; // properties are integers
			}
			
			
			// get original width
			if (image.style.width != '')
			{
				var image_width = image.style.width.replace(/px/, '') * 1; // style values are strings
			}
			else
			{
				var image_width = image.width; // properties are integers
			}
			
			
			// set pixel step size	
			if (step_size == null || step_size < 1)
			{
				var img_pop_step_size = 1;
			}
			else
			{
				var img_pop_step_size = Math.round(step_size);
			}
			
			
			// set direction
			if (axis == 'horizontal' || axis == 'x') axis = 'h';
			if (axis == 'vertical' || axis == 'y') axis = 'v';
			if (axis == 'both' || axis == 'xy') axis = null;
		

			// set pop parameters
			// grow or shrink is based on visibility
			if (image.style.display != 'none')
			{

				var pop_action = 'shrink';
				
				// shrink from image width
				var adjusted_width = image_width;
				var adjusted_height = image_height;
			
			}
			else
			{

				var pop_action = 'grow';
				
				// grow from 0 pixels
				var adjusted_width = 0;
				var adjusted_height = 0;
				
				// inverted adjustment for growing from axis
				if (axis == 'h') adjusted_height = image_height;
				if (axis == 'v') adjusted_width = image_width;
			
			}

			
			// repeater
			function img_pop_step()
			{
				
				if (pop_action == 'shrink')
				{
					
					// shrink
					if (axis == 'h' || axis == null) adjusted_width = adjusted_width - img_pop_step_size;
					if (axis == 'v' || axis == null) adjusted_height = adjusted_height - img_pop_step_size;
					
					if(adjusted_width < 1 || adjusted_height < 1)
					{

						// hide image and restore size
						image.style.display = 'none';
						image.style.width = image_width + 'px';
						image.style.height = image_height + 'px';
						
						clearInterval(img_pop_interval_id);
						
						return;
					
					}
					else
					{
					
						// shrink width
						image.style.width = adjusted_width + 'px';
						image.style.height = adjusted_height + 'px';
						
					}
					
				}
				else
				{
					
					// grow
					if (axis == 'h' || axis == null) adjusted_width = adjusted_width + img_pop_step_size;
					if (axis == 'v' || axis == null) adjusted_height = adjusted_height + img_pop_step_size;
					
					if (adjusted_width >= image_width) adjusted_width = image_width;
					if (adjusted_height >= image_height) adjusted_height = image_height;
					
					if(adjusted_width == image_width && adjusted_height == image_height)
					{
					
						// end growing
						image.style.width = image_width + 'px';
						image.style.height = image_height + 'px';
						
						clearInterval(img_pop_interval_id);
						
						return;
					
					}
					else
					{
						
						// grow width
						image.style.width = adjusted_width + 'px';
						image.style.height = adjusted_height + 'px';
						
						// make image visible
						if (image.style.display == 'none')
						{
							 image.style.display = '';
						}
						
					}
				
				}
			
			}
			
			
			// start animation
			img_pop_interval_id = setInterval(img_pop_step, 30);
			
		}
		
	}
	
}


function multiToggleDisplay(elements,method,cookie_name)
{
	
	
	var display_method = '';
	
	for (var i in elements)
	{
		
		if (method == 'swap')
		{
		
			if ( elements[i].style.display != 'none' )
			{
			
				elements[i].style.display = 'none';
				
				// sample
				display_method = 'hide';
				
			}
			else 
			{
			
				elements[i].style.display = '';
				
				// sample
				display_method = 'show';
				
			}
			
		}
		else if (method == 'show')
		{
		
			 elements[i].style.display = '';
			 
			 // sample
			 display_method = 'show';
			
		}
		else if (method == 'hide')
		{
		 
			 elements[i].style.display = 'none';
			 
			 // sample
			 display_method = 'hide';
		
		}
		
	}
	
	
	
	if (cookie_name)
	{
		// the last element to be updated has been sampled for resulting display style
		// this is now set in a cookie, with a custom name
    	Set_Cookie( cookie_name, display_method, '', '/', '', '' );
	}
	
	
}





// check for display state of block identifiers and toggle on or off
function setBlockIdentifiers()
{
	
	
	
	if (Get_Cookie('block_identifier'))
	{
		
		
		if ( Get_Cookie('block_identifier') == 'show')
		{	
			
			// apply fetched display state
		  	multiToggleDisplay(tvg_get_elements_by_class('block_identifier', 'interface'), 'show', 'block_identifier');
			
		}
		else
		{	
		
			// assume it's the other way round
			multiToggleDisplay(tvg_get_elements_by_class('block_identifier', 'interface'), 'hide', 'block_identifier');
			
		}
	
	
	}



}

// check for display state of block identifiers and toggle on or off
function setMultiToggleDisplay(cookie_name,elements_class,elements_class_exeption)
{
	
	
	
	if (Get_Cookie(cookie_name))
	{
		
		
		if ( Get_Cookie(cookie_name) == 'show')
		{	
			
			// apply fetched display state
		  	multiToggleDisplay(tvg_get_elements_by_class(elements_class,elements_class_exeption), 'show', cookie_name);
			
		}
		else
		{	
		
			// assume it's the other way round
			multiToggleDisplay(tvg_get_elements_by_class(elements_class,elements_class_exeption), 'hide', cookie_name);
			
		}
	
	
	}



}







function getElementsByClass(searchClass,exeption,node,tag)
{
	
	//alert(searchClass);
	
	var teststring = 'test string test';
	
	//alert(teststring.indexOf('string'));
	
	var classElements = new Array();
	
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
		
	var els = node.getElementsByTagName(tag);
	//var elsLen = els.length;
	
	//var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
	//var j = 0;
	for (var i in els)
	{
		
		//classElements[classElements.length] = els[i].className;
		
		if(els[i].className != '' && is_numeric(i))
		{
			
			var classname_to_check = els[i].className;
			
			//classElements[classElements.length] = i;
			
			//classElements[classElements.length] = classname_to_check.indexOf(searchClass);
		
		
			if ( classname_to_check.indexOf(searchClass) > -1 && classname_to_check.indexOf(exeption) == -1)
			{
				
				classElements[classElements.length] = els[i];
				
			}
		
		
		}	
		
	}
	
	//alert(classElements);
	
	
	
	
	return classElements;
}


function tvg_get_elements_by_class(search_class, exception_class, search_node_id, search_tag)
{
	// feedback
	//var readout = document.getElementById('readout');
	
	
	
	// set up search
	
	if (search_node_id == null)
	{
		var search_node = document;
	}
	else
	{
		var search_node = document.getElementById(search_node_id);
		//readout.innerHTML += ' searchnode used - ';
	}
	
	if (search_tag == null) search_tag = '*';
	
	var all_elements = search_node.getElementsByTagName(search_tag);

	
	
	
	//if (document.getElementById('sm_js_console')) document.getElementById('sm_js_console').innerHTML += 'Class search: ' + search_class + ' <br>';
	
	
	// inspect elements
	
	var selected_elements = [];
	
	var classnames_to_check_string = null;
	
	var classnames_to_check_list = null;
			
	var element_accepted = false;
	
	
	//readout.innerHTML += all_elements.length + ' - ';
	
	//readout.innerHTML += search_class + ' - ';
	
	
	for (var i in all_elements)
	{
		
		// special modified loop element check for getElementsByTagName results in explorer
		// note: the is numeric check will break the results in explorer, if an element has an id attribute, explorer will use that instead of a number! 
		//if (is_numeric(i) || all_elements[i].id)
		//{
	
			
			
			
			//readout.innerHTML += ' scanning: i' + i + ' "' + all_elements[i].nodeName + '"<br>';
			
			if (all_elements[i].className && all_elements[i].className != '')
			{
			
			
			
				
				
				//if (i>600) return;
				
				classnames_to_check_string = all_elements[i].className + '';
				
				//readout.innerHTML += ' getting: i' + i + ' "' + classnames_to_check_string + '"<br>';
				
				//if (classnames_to_check_string.match(/option_total_price/)) readout.innerHTML += ' direct scan: i' + i + ' ';
				
	
				element_accepted = false;
				
				
				
				if (classnames_to_check_string == search_class)
				{
					
					element_accepted = true;
					
					//readout.innerHTML += ' direct hit: i' + i + ' "' + classnames_to_check_string + '"<br>';
							
				}
				else if (classnames_to_check_string.match(/ /))
				{
					
					//readout.innerHTML += ' class scan: i' + i + ' "' + classnames_to_check_string + '"<br>';
					
					classnames_to_check_list = classnames_to_check_string.split(' ');
					
					
					for (var j in classnames_to_check_list)
					{
						
						if (is_numeric(j))
						{
						
							//readout.innerHTML += ' split: j' + j + ' "' + classnames_to_check[j] + '"<br>';
							
							if (classnames_to_check_list[j] == search_class)
							{
							
								element_accepted = true;
								
							}
							
							if (exception_class != null && classnames_to_check_list[j] == exception_class)
							{
								
								// break on exeption class
								element_accepted = false;
								break;
								
							}
						
						}
					
					}
					
					
					
				
				}
				
				
				if (element_accepted == true)
				{
					
					// add to array
					selected_elements.push(all_elements[i]);
					
					
					
				}
		
			}
			
			
			
		//}
	}
	

	//readout.innerHTML += ' - selected "' + selected_elements.length + '"<br>';
	

	return selected_elements;

} // end function tvg_get_elements_by_class





function is_numeric( mixed_var ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: David
    // +   improved by: taith
    // *     example 1: is_numeric(186.31);
    // *     returns 1: true
    // *     example 2: is_numeric('Kevin van Zonneveld');
    // *     returns 2: false
    // *     example 3: is_numeric('+186.31e2');
    // *     returns 3: true
 
    return !isNaN(mixed_var * 1);
}




/**
*
*  Javascript trim, ltrim, rtrim
*  http://www.webtoolkit.info/
*
**/
/*
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
*/

// prototyped trim!!
String.prototype.trim = function() {  return this.replace(/^\s+|\s+$/g, '');  }




// prototyped regex fixer
String.prototype.regex_string_fix = function() {  return this.replace(/\//g, '\\/');  }


// prototyped style fix for explorer
// note: this makes semicolons in style attributes optional
// note: explorer has capitalized any tags and css definitions when they are read back out with innerhtml, and also removed the ending semicolon in the style attribute
// example: <span style="background-color: red;"> becomes <SPAN style="BACKGROUND-COLOR: red">
String.prototype.regex_string_fix_style_attribute = function() {  return this.replace(/;/g, ';{0,1}');  }



function setFieldValues()
{
	
	if (document.getElementById('basic_search_all_input'))
	{
		
		var field_1 = document.getElementById('basic_search_all_input');
	
		field_1.value = ' Snel zoeken...';
	
	}

}












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" : "" );
}
	 
	
// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}		

// this deletes the cookie when called
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";
}
	
/*
// remember, these are the possible parameters for Set_Cookie:
// name, value, expires, path, domain, secure
Set_Cookie( 'test', 'it works', '', '/', '', '' );
if ( Get_Cookie( 'test' ) ) alert( Get_Cookie('test'));
// and these are the parameters for Delete_Cookie:
// name, path, domain
// make sure you use the same parameters in Set and Delete Cookie.
Delete_Cookie('test', '/', '');
( Get_Cookie( 'test' ) ) ? alert( Get_Cookie('test')) : 
alert( 'it is gone');	
*/




// check for sticky display state of two elements and set their display state
function tvgs_element_display_set_state_sticky_by_id(id1,id2)
{
	
	if ( Get_Cookie(id1) || Get_Cookie(id2) )
	{
	
		var el1 = document.getElementById(id1);
		var el2 = document.getElementById(id2);
	
		if ( Get_Cookie(id1) == 'none')
		{	
			// apply fetched display state
			el1.style.display = 'none';
			el2.style.display = '';	
		}
		else
		{	
			// assume it's the other way round
			el1.style.display = '';
			el2.style.display = 'none';	
		}
	
	}

}


// tvgs legacy fix
// note: do not use this, always use the new function name
function applyStickyDisplayState(id1,id2)
{

	tvgs_element_display_set_state_sticky_by_id(id1,id2);

}



// switch display state of two elements and save settings to cookies
function tvgs_element_display_switch_sticky_by_id(id1,id2)
{
	
	var el1 = document.getElementById(id1);
	var el2 = document.getElementById(id2);

	if ( el1.style.display != 'none' )
	{
		el1.style.display = 'none';
		Set_Cookie( id1, 'none', '', '/', '', '' );
	}
	else 
	{
		el1.style.display = '';
		Set_Cookie( id1, '', '', '/', '', '' );
	}
	
	if ( el2.style.display != '' )
	{
		el2.style.display = '';
		Set_Cookie( id2, '', '', '/', '', '' );
	}
	else
	{
		el2.style.display = 'none';
		Set_Cookie( id2, 'none', '', '/', '', '' );
	}
	
}


// tvgs legacy fix
// note: do not use this, always use the new function name
function switchDisplaySticky(id1,id2)
{

	tvgs_element_display_switch_sticky_by_id(id1,id2);

}
