function show_texts(page, subpage, id)
{
	//alert('show texts');
	var link="texts.php?page="+page+"&subpage="+subpage+"&id="+id;
	$.get(link, function(data){
			$("#text_container").html(data);
			$("#text_container").show();
		});	
}

function show_menue(page,subpage)
{
	//alert('show menue');
	//var link="menue.php?request=show&page="+page+"&subpage="+subpage;
	//$.get(link, function(data){
			//$("#menue").html(data);
			//$("#menue").show();
		//});
	var link='static_menue.php?page='+page+'&subpage='+subpage;
	$("#menue").load(link);
}

function show_menue_advanced(page,subpage)
{
	//alert('show menue');
	//var link="menue.php?request=show&page="+page+"&subpage="+subpage;
	//$.get(link, function(data){
			//$("#menue").html(data);
			//$("#menue").show();
		//});
	var link='static_menue.php?page='+page+'&subpage='+subpage+'&noform';
	$("#menue").load(link);
}

function expand_menue(page, active_page)
{
	//alert('expand menue');
	$.each(menue_items, function(index, menueitem)
		{
			if(menueitem!=active_page)
			{
					$("#submenue_"+menueitem).html(data='');
					$("#submenue_"+menueitem).show();
			}
		}
	);
	var link="menue.php?request=expand&page="+page;
	$.get(link, function(data){
			$("#submenue_"+page).html(data);
			$("#submenue_"+page).show();
		});
}

function show_image()
{
	//alert('show image');
	var link="image.php";
	$.get(link, function(data){
			$("#big_image").html(data);
			$("#big_image").show();
		});
}

function show_text_image(id)
{
	//alert('show text image');
	var link="image.php?id="+id;
	$.get(link, function(data){
			$("#big_image").html(data);
			$("#big_image").show();
		});
}

function show_menue_image(menue_id, submenue_id)
{
	//alert('show menue image');
	if(menue_id)
	{
		var link='image.php?menue_id='+menue_id;
	}
	if(submenue_id)
	{
		var link='image.php?submenue_id='+submenue_id;
	}
	$.get(link, function(data){
			$("#big_image").html(data);
			$("#big_image").show();
		});
}

function show_form(form_type, page, subpage)
{
	var link="form.php?type="+form_type+'&page='+page+'&subpage='+subpage;
	$.get(link, function(data){
			$("#form_container").html(data);
			$("#form_container").show();
		});
	//$("#user_input_div").load(link);
}

function send_request(lang, type)
{
	need=Array();
	need2=Array();
	for(i=1;i<=need_init;i++)
	{
		$("#need_span_"+i).hide("slow");
		$("#need_span_"+i).html('');
	}
	for(i=1;i<=need2_init;i++)
	{
		$("#need2_span_"+i).hide("slow");
		$("#need2_span_"+i).html('');
	}
	$("#need_warning").hide("slow");
	$("#need2_warning").hide("slow");
	var valid=validate_request(type);
	if(valid)
	{
		document.user_input_form.submit();
	} else
	{
		 //nevalīdu datu paziņojums
		 if(typeof(need)!='undefined')
		 {
			 var need_count=0;
			 $.each(need, function(i, val)
				{
						value=parseInt(val);
						$("#need_span_"+value).html('*');
						$("#need_span_"+value).show("slow");
						need_count++;
				});
			if(need_count)
			{
				switch(lang)
				{
					case 'lat':
						$("#need_warning").html(data='* Šie lauki jāaizpilda obligāti!');
						break;
					case 'rus':
						$("#need_warning").html(data='* Эти поля являются обязательными!');
						break;
					case 'eng':
						$("#need_warning").html(data='* These fields are mandatory!');
						break;
				}
				$("#need_warning").show("slow");
			}
		}
		if(typeof(need2)!='undefined')
		{
			var need2_count=0;
			$.each(need2, function(i, val)
				{
						value=parseInt(val);
						$("#need2_span_"+value).html('**');
						$("#need2_span_"+value).show("slow");
						need2_count++;
				});
			if(need2_count)
			{
				switch(lang)
				{
					case 'lat':
						$("#need2_warning").html(data='** Viens no šiem laukiem jāaizpilda obligāti!');
						break;
					case 'rus':
						$("#need2_warning").html(data='** Одно из этих полей является обязательным!');
						break;
					case 'eng':
						$("#need2_warning").html(data='** One of these fields are mandatory!');
						break;
				}
				$("#need2_warning").show("slow");
			}
		}
	}
}

function validate_request(type)
{
	var valid=0;
	switch(type)
	{
		case 'ask':
			var name_surname_valid=0;
			var name_surname=$("#name_surname").val();
			if(name_surname.length)
			{
				name_surname_valid=1;
			} else
			{
				need.push(1);
			}
			var e_mail_valid=0;
			var e_mail=$("#e_mail").val();
			if(e_mail.length)
			{
				e_mail_valid=1;
			} else
			{
				need2.push(1);
			}
			var phone=$("#phone").val();
			var phone_valid=0;
			if(phone.length)
			{
				phone_valid=1;
			}
			var question=$("#question").val();
			var question_valid=0;
			if(question.length)
			{
				question_valid=1;
			}
			var answer_type=$("[name=answer_type]:checked").val();
			switch(answer_type)
			{
				case 'email':
					if(name_surname_valid && e_mail_valid && question_valid)
					{
						valid=1;
					}
					if(!e_mail_valid)
					{
						need.push(3);
					}
					break;
				case 'phone':
					if(name_surname_valid && phone_valid && question_valid)
					{
						valid=1;
					}
					if(!phone_valid)
					{
						need.push(4);
					}
					break;
			}
			break;
		case 'contactus':
			var name_surname_valid=0;
			var name_surname=$("#name_surname").val();
			if(name_surname.length)
			{
				name_surname_valid=1;
			} else
			{
				need.push(1);
			}
			var e_mail_valid=0;
			var e_mail=$("#e_mail").val();
			if(e_mail.length)
			{
				e_mail_valid=1;
			}
			var phone=$("#phone").val();
			var phone_valid=0;
			if(phone.length)
			{
				phone_valid=1;
			} 
			if(!e_mail_valid && !phone_valid)
			{
				need2.push(1);
				need2.push(2);
			}
			var message=$("#message").val();
			var message_valid=0;
			if(message.length)
			{
				message_valid=1;
			} else
			{
				need.push(2);
			}
			if(name_surname_valid && message_valid && (e_mail_valid || phone_valid))
			{
				valid=1;
			}
			break;
		case 'news':
			var uname_valid=0;
			var uname=$("#uname").val();
			if(uname.length)
			{
				uname_valid=1;
			} else
			{
				need.push(1);
			}
			var surname_valid=0;
			var surname=$("#surname").val();
			if(surname.length)
			{
				surname_valid=1;
			} else
			{
				need.push(2);
			}
			var e_mail_valid=0;
			var e_mail=$("#e_mail").val();
			if(e_mail.length)
			{
				e_mail_valid=1;
			} else
			{
				need.push(3);
			}
			var bd_valid=0;
			var bd_day=$("#bd_day").val();
			//alert(bd_day);
			var bd_month=$("#bd_month").val();
			//alert(bd_month);
			var bd_year=$("#bd_year").val();
			//alert(bd_year);
			if(bd_day==0)
			{
				need.push(4);
				//alert('nav day');
			}
			if(bd_month==0)
			{
				need.push(5);
				//alert('nav month');
			}
			if(bd_year==0)
			{
				need.push(6);
				//alert('nav year');
			}
			if((bd_day>0) && (bd_month>0) && (bd_year>0))
			{
				bd_valid=1;
			}
			var agree_valid=0;
			var im_agree=$("#agree").attr('checked');
			if(im_agree)
			{
				agree_valid=1;
			} else
			{
				need.push(7);
			}
			if(uname_valid && surname_valid && e_mail_valid && bd_valid && agree_valid)
			{
				valid=1;
			}
			break;
	}
	return valid;
}

function print_me(page, subpage, id)
{
	link="print_texts.php?page="+page+"&subpage="+subpage+"&id="+id;
	popup(link, 800, 600);
}

 function popup(link, width, height) 
{
	 var iMyWidth;
	 var iMyHeight;
	 var half_width=width/2;
	 var half_height=height/2;
	 //half the screen width minus half the new window width (plus 5 pixel borders).
	 iMyWidth = (window.screen.width/2) - (half_width + 10);
	 //half the screen height minus half the new window height (plus title and status bars).
	 iMyHeight = (window.screen.height/2) - (half_height+ 50);
	 //Open the window.
	 var mare_popup = window.open(link,"mare_popup","status=no,height="+height+",width="+width+",resizable=no,left=" + (iMyWidth+20) + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",toolbar=no,menubar=no,scrollbars=yes,location=no,directories=no");
	 mare_popup.focus();
}

function load_logo()
{
	$("#logo_container").load('logo.php');
}
