$(document).ready(function(){
	$(".popThumbLink").click(function(){
		$(".popThumbLink img.current").removeClass("current");
		$(".photo img").attr('src',$(this).attr("href"));
		$(this).find("img").addClass("current");
		return false;
	});
});

function getPage(thePage,wt,ht)
{ 
	if(wt=="")wt=300;
	if(ht=="")wt=300;
	leftPos= (screen.width-wt)/2 
	topPos = (screen.height-ht)/2
	rnd = Math.round(1000*Math.random());
	newWin1 = window.open(thePage,'popup'+rnd,'toolbars=no,resizable=yes,scrollbars=yes,left='+leftPos+',top='+topPos+',width='+wt+',height='+ht) 
}

function popImg(thePage,wt,ht){ 
if(!wt)wt=300;
if(!ht)ht=300;
//leftPos= (screen.width-wt)/2 
//topPos = (screen.height-ht)/2 
leftPos=100;
topPos =100;
newWin1 = window.open("/view_image.php?src="+thePage,'aWin2','toolbars=no,resizable=yes,scrollbars=no,status=yes,left='+leftPos+',top='+topPos+',width='+wt+',height='+ht) 
} 


function change_river(id)
{
	prev_id = document.form_river.curent_river.value;
	next_id = id;
	
	document.getElementById('block_1_'+prev_id).style.display = 'none';
	
	document.getElementById('block_1_'+next_id).style.display = 'block';
	
	document.form_river.curent_river.value = next_id;
	
	
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
 }


function check_valid_1(thisform) 
{
	if(thisform.marsrutas.value == "" || thisform.marsrutas.value == "--")
	{
		thisform.marsrutas.focus();
		alert('Pasirinkite maršrutą');
		return false;
	}
	
	if(thisform.zmones.value == "")
	{
		
		thisform.zmones.focus();
		alert('Įveskite žmonių skaičių');
		return false;
	} 
	
	if(IsNumeric(thisform.zmones.value) == false)
	{
		thisform.zmones.focus();
		alert('Įveskite teisingą žmonių skaičių');
		return false;
	}
	
  	if(thisform.baidares.value == "")
	{
		thisform.baidares.focus();
		alert('Įveskite baidarių skaičių');
		return false;
	}
	
	if(IsNumeric(thisform.baidares.value) == false)
	{
		thisform.baidares.focus();
		alert('Įveskite teisingą baidarių skaičių');
		return false;
	}
	
	if(thisform.trukme.value == "")
	{
		thisform.trukme.focus();
		alert('Pasirinkite plaukimo trukmę');
		return false;
	}
	return true;
}

function check_valid_2() 
{
	if (check_valid_1(document.first_step) == false)
	{
		return false;
	}
	
	if(document.rezervuok.date.value == "")
	{
		alert('Pasirinkite datą');
		return false;
	}
	
	if(document.rezervuok.name.value == "")
	{
		document.rezervuok.name.focus();
		alert('Įveskite vardą');
		return false;
	}
	
	if(document.rezervuok.lastname.value == "")
	{
		document.rezervuok.lastname.focus();
		alert('Įveskite pavardę');
		return false;
	} 
	
  	if(document.rezervuok.phone.value == "")
	{
		document.rezervuok.phone.focus();
		alert('Įveskite telefoną');
		return false;
	}

	if(!document.rezervuok.email.value.match(/^(\S+)@(\S+)\.(\S+)/))
	{
		document.rezervuok.email.focus();
		alert('Įveskite teisingą el. paštą');
		return false;
	}
	
	document.rezervuok.patvirtinti.value = 1;
	document.rezervuok.submit();

}

function check_valid_3(thisform)
{
	if(thisform.name.value == "")
	{
		thisform.name.focus();
		alert('Įveskite vardą');
		return false;
	}
	
	if(thisform.lastname.value == "")
	{
		thisform.lastname.focus();
		alert('Įveskite pavardę');
		return false;
	} 
	
  	if(thisform.phone.value == "")
	{
		thisform.phone.focus();
		alert('Įveskite telefoną');
		return false;
	}
	
	if(!thisform.email.value.match(/^(\S+)@(\S+)\.(\S+)/))
	{
		thisform.email.focus();
		alert('Prašome įvesti teisingą el. paštą.');
		return false;
	}
	
	if(thisform.text.value == "")
	{
		thisform.text.focus();
		alert('Įveskite užklausimo tekstą');
		return false;
	}
	return true;
}


function check_valid_4() 
{
	document.rezervuok.patvirtinti.value = 0;
	document.rezervuok.submit();
}


function check_valid_5()
{
	email = document.getElementById("subscribe_email").value;
	if(!email.match(/^(\S+)@(\S+)\.(\S+)/))
	{
		alert('Prašome įvesti teisingą el. paštą.');
	}
	else
	{
		document.getElementById("form_subscribe").submit();
	}
}

function submit_rezervuok(thisform,day)
{
	alert(thisform.date.zmones);
	thisform.date.value = day;
	thisform.submit();
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function change_calendar(action,year,month)
{
	if (action == 'next')
	{
		if (month < 13)
		{
			document.rezervuok.year_show.value = year;
			document.rezervuok.month_show.value = month;
		}
		else
		{
			document.rezervuok.year_show.value = year+1;
			document.rezervuok.month_show.value = 1;	
		}
	}
	else
	{
		if (month == 0)
		{
			document.rezervuok.year_show.value = year-1;
			document.rezervuok.month_show.value = 12;	
		}
		else
		{
			document.rezervuok.year_show.value = year;
			document.rezervuok.month_show.value = month;
		}
	}
}

