/********************************/
/* ser_form						*/
/********************************/

function sjf_mark_switch(sjv_fieldname)
{
	for(i=0; i<document.ser_form.elements[sjv_fieldname].length; i++)
	{
		if (document.ser_form.elements[sjv_fieldname][i].checked == true)
		{
			document.ser_form.elements[sjv_fieldname][i].checked = false;
		}
		else
		{
			document.ser_form.elements[sjv_fieldname][i].checked = true;
		}
	}
}

function sjf_mark_all(sjv_fieldname)
{
	for(i=0; i<document.ser_form.elements[sjv_fieldname].length; i++)
	{
		document.ser_form.elements[sjv_fieldname][i].checked = true;
	}
}

function sjf_mark_none(sjv_fieldname)
{
	for(i=0; i<document.ser_form.elements[sjv_fieldname].length; i++)
	{
		document.ser_form.elements[sjv_fieldname][i].checked = false;
	}
}

function sjf_form_radio_mark(sjv_value)
{
	for(i=0; i<document.ser_form.elements.length; i++)
	{
		if(document.ser_form.elements[i].type == 'radio' && document.ser_form.elements[i].value == sjv_value)
		{
			document.ser_form.elements[i].checked = true;
		}
	}
}

function sjf_change_form_select(sjv_id,sjv_value)
{
	for(i=0; i<document.forms.ser_form.elements[sjv_id].length; i++)
	{
		if(document.forms.ser_form.elements[sjv_id].options[i].value==sjv_value)
		{
			document.forms.ser_form.elements[sjv_id].options[i].selected = true;
			break;
		}
	}
}


/********************************/
/* Divs							*/
/********************************/

function sjf_div_hide(sjv_div_id)
{
	document.getElementById(sjv_div_id).style.display = 'none';
}

function sjf_div_show(sjv_div_id)
{
	document.getElementById(sjv_div_id).style.display = 'block';
}

function sjf_div_visibility_toggle(sjv_div_id)
{
	if(document.getElementById(sjv_div_id).style.display == 'none')
	{
		sjf_div_show(sjv_div_id);
	}
	else
	{
		sjf_div_hide(sjv_div_id);
	}
}

function sjf_oh1_show(sv_form_object_id)
{
	$('sc_oh').innerHTML = sjv_oh_text[sv_form_object_id];
}

function sjf_oh1_clear(sv_form_object_id)
{
	$('sc_oh').innerHTML = '';
}


/********************************/
/* Pop-Up						*/
/********************************/

function sjf_popup(sjv_url,sjv_features,sjv_popup_name) 
{
	if(sjv_popup_name == '')
	{
		sjv_popup_name='ser_popup';
	}
	ser_pop_up_window = window.open(sjv_url, sjv_popup_name, sjv_features);
	ser_pop_up_window.focus();
}

/********************************/
/* Confirm						*/
/********************************/


function sjf_window_confirm(sjv_message, sjv_url)
{
	if(confirm(sjv_message)) location.href = sjv_url;
}


/********************************/
/* Imagelayer					*/
/********************************/


function sjf_il_init(sjv_il_mouse_pos_offset_x, sjv_il_mouse_pos_offset_y)
{
	var sv_il_div_image_loading = 'images/content/lade.gif';
	var sv_il_div_id 			= 'sc_div_image_layer';
	
	var sjv_il_image_layer 	= false;
	var sjv_il_mouseover 	= false;
	
	var sjv_mouse_pos_x = 0;
	var sjv_mouse_pos_y = 0;
	
	window.onload = function()
	{
		if (window.event)
		{ 
			document.onmousemove = function()
			{
				sjf_mouse_position(window.event); 
				sjf_il_track_mouse(window.event);
			}
		}
		else 
		{ 
			document.onmousemove = function(e) 
			{ 
				sjf_mouse_position(e); sjf_il_track_mouse(e); 
			}	
		}
	}
}

function sjf_il_main(sjv_image_url)
{
	if(document.getElementById(sjv_il_div_id)) 
	{
		sjf_il_position(sjv_mouse_pos_x + sjv_il_mouse_pos_offset_x, sjv_mouse_pos_y - sjv_il_mouse_pos_offset_y);
		document.images['sjv_il_div_image_id'].src = sjv_image_url;
		sjf_il_show(sjv_il_div_id);
		sjv_il_image_layer = true;
	}
}

function sjf_il_position(x, y)
{
	if(document.getElementById(sjv_il_div_id)) 
	{
		document.getElementById(sjv_il_div_id).style.left	= x + 'px';
		document.getElementById(sjv_il_div_id).style.top	= y + 'px';
	}
}

function sjf_il_show()
{
	if(document.getElementById(sjv_il_div_id)) 
	{
		document.getElementById(sjv_il_div_id).style.display = 'block';
	}
}

function sjf_il_hide() 
{
	if(document.getElementById(sjv_il_div_id)) 
	{
		document.getElementById(sjv_il_div_id).style.display = 'none';
	}
}


function sjf_il_hide_layer()
{
	if(document.getElementById(sjv_il_div_id))
	{
		sjf_il_hide(sjv_il_div_id);
		document.images['sjv_il_div_image_id'].src = sjv_il_div_image_loading;
		sjv_il_image_layer =  false;
	}
}

function sjf_il_get_mouse_x(e) 
{
	if(e)
	{
		return e.pageX;
	}
	else if(window.event.clientX)
	{
		return window.document.body.scrollLeft+window.event.clientX;
	}
}

function sjf_il_get_mouse_y(e)
{
	if(e) 
	{
		return e.pageY;
	} 
	else if(window.event.clientX) 
	{
		return window.document.body.scrollTop+window.event.clientY;
	}
}

function sjf_il_track_mouse() 
{
	if(sjv_il_image_layer) 
	{
    	sjf_il_position(sjv_mouse_pos_x + sjv_il_mouse_pos_offset_x, sjv_mouse_pos_y - sjv_il_mouse_pos_offset_y);
	}
}

function sjf_mouse_position(evt)
{
	
	if (evt.pageX || evt.pageY) 	
	{
		sjv_mouse_pos_x = evt.pageX;
		sjv_mouse_pos_y = evt.pageY;
	}
	else if (evt.clientX || evt.clientY) 	
	{
		sjv_mouse_pos_x = evt.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		sjv_mouse_pos_y = evt.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	// posx and posy contain the mouse position relative to the document
}


/********************************/
/* Overlay						*/
/********************************/

function sjf_overlay_show(sjv_div_overlay_id) 
{
	var sjv_pagesize = sjf_pagesize_get();
	document.getElementById(sjv_div_overlay_id).style.top = '0px';
	document.getElementById(sjv_div_overlay_id).style.height = (sjv_pagesize.pageHeight + 'px');
	document.getElementById(sjv_div_overlay_id).style.width = (sjv_pagesize.pageWidth + 'px');
	document.getElementById(sjv_div_overlay_id).style.display = 'block';
}

function sjf_overlay_hide(sjv_div_overlay_id) 
{
	document.getElementById(sjv_div_overlay_id).style.display = 'none';
}


function sjf_div_center(sjv_div_id) 
{
  if ($(sjv_div_id)) {
    divWidth  = Element.getDimensions($(sjv_div_id)).width;
    divHeight = Element.getDimensions($(sjv_div_id)).height;

    var sjv_window_scroll = sjf_scroll_values_get();

    var top = (sjv_window_scroll.height - divHeight)/2 + sjv_window_scroll.top;
    $(sjv_div_id).style.top = top + 'px';

    var left = (sjv_window_scroll.width - divWidth)/2;
    $(sjv_div_id).style.left = left + 'px';
  }
}

function sjf_pagesize_get()
{
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	var pageHeight, pageWidth;
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	return {pageWidth: pageWidth ,pageHeight: pageHeight , windowWidth: windowWidth, windowHeight: windowHeight};
}


function sjf_scroll_values_get() {
  var w = window;
    var T, L, W, H;
    with (w.document) {
      if (w.document.documentElement && documentElement.scrollTop) {
        T = documentElement.scrollTop;
        L = documentElement.scrollLeft;
      } else if (w.document.body) {
        T = body.scrollTop;
        L = body.scrollLeft;
      }
      if (w.innerWidth) {
        W = w.innerWidth;
        H = w.innerHeight;
      } else if (w.document.documentElement && documentElement.clientWidth) {
        W = documentElement.clientWidth;
        H = documentElement.clientHeight;
      } else {
        W = body.offsetWidth;
        H = body.offsetHeight
      }
    }
    return { top: T, left: L, width: W, height: H };
}


/********************************/
/* Ajax							*/
/********************************/

function sjf_ajax_general(sjv_script, sjv_func, sjv_output_div, sjv_data, sjv_phpsession)
{
	$(sjv_output_div).innerHTML = '<img src="https://ssl.serianserver.de/libmedia/images/ajax_loader2.gif">';
	
	MyAjax = new Ajax.Request(sjv_script, 
								{parameters:'func='+sjv_func+'&data='+sjv_data+'&'+sjv_phpsession, 
									onSuccess:function(t) 
									{
										var sjv_a_output = eval('('+t.responseText+')');
										$(sjv_output_div).innerHTML = sjv_a_output['html'];
									},
									onFailure:function(t) 
									{
										$(sjv_output_div).innerHTML = 'error';
									}
								}
							);
}

function sjf_ajax_general_2(sjv_script, sjv_func, sjv_output_div, sjv_data, sjv_phpsession, sjv_loader_image)
{
	if(sjv_loader_image == '2')
	{
		$(sjv_output_div).innerHTML = '<img src="https://ssl.serianserver.de/libmedia/images/ajax_loader2.gif">';
	}
	
	MyAjax = new Ajax.Request(sjv_script, 
								{parameters:'func='+sjv_func+'&data='+sjv_data+'&'+sjv_phpsession, 
									onSuccess:function(t) 
									{
										var sjv_a_output = eval('('+t.responseText+')');
										$(sjv_output_div).innerHTML = sjv_a_output['html'];
									},
									onFailure:function(t) 
									{
										$(sjv_output_div).innerHTML = 'error';
									}
								}
							);
}

function sjv_ajax_form_get_input_values(sjv_form_name)
{
	var returnvalue = '';
	for(var i = 0; i < document.forms[sjv_form_name].elements.length; i++)
	{
		if(document.forms[sjv_form_name].elements[i].type == 'radio' || document.forms[sjv_form_name].elements[i].type == 'checkbox')
		{
			if(document.forms[sjv_form_name].elements[i].checked == false)
			{
				continue;
			}
		}
		sjv_temp_value = document.forms[sjv_form_name].elements[i].value;
		sjv_temp_value = sjv_temp_value.replace(/\n/gi,'_br_');
		sjv_temp_value = sjv_temp_value.replace(/"/gi,'&quot;');
		returnvalue = returnvalue+"%22"+document.forms[sjv_form_name].elements[i].name+"%22:%22"+encodeURIComponent(sjv_temp_value)+"%22,";
	}
	return '%7B%22sv_a_formdata%22:%7B'+returnvalue+'%7D%7D';	
}

function sjf_ajax_overlay_div(sjv_func, sjv_data, sjv_phpsession)
{

	$('sc_div_overlay_box').innerHTML = '';

	MyAjax = new Ajax.Request(sjv_func, 
							  	{parameters:'&data='+sjv_data+'&'+sjv_phpsession, 
											onSuccess:sjf_ajax_overlay_div_output,
											onFailure:function(t) 
											{
												$('sc_div_overlay_box').innerHTML = 'error';
											}
								}
								);
}

function sjf_ajax_overlay_div_output(MyAjax)
{
	sjf_overlay_show('sc_div_overlay');
	sjf_div_center('sc_div_overlay_box');
	
	var sjv_a_output = eval('('+MyAjax.responseText+')');
	
	$('sc_div_overlay_box').style.display 	= 'block';
	$('sc_div_overlay_box').style.position 	= 'absolute';
	$('sc_div_overlay_box').style.width 	= sjv_a_output['width']+'px';
	$('sc_div_overlay_box').style.height	= sjv_a_output['height']+'px';
	
	if(sjv_a_output['margin'] != '')
	{
		$('sc_div_overlay_box').style.margin =  sjv_a_output['margin']+'px';
	}
	$('sc_div_overlay_box').innerHTML = sjv_a_output['html'];
	sjf_div_center('sc_div_overlay_box');
}

