function changeTabs(id) {
        var tabContainers = jQuery(id).children('.tab_content'); // получаем массив контейнеров
        tabContainers.hide().filter(':first').show(); // прячем все, кроме первого 
        // далее обрабатывается клик по вкладке
        jQuery(id).children('ul.tab_nav').children('li').children('a').click(function () {
          tabContainers.hide(); // прячем все табы
          tabContainers.filter(this.hash).show(); // показываем содержимое текущего
          jQuery(id).children('ul.tab_nav').children('li').removeClass('active'); // у всех убираем класс 'selected'
          jQuery(this).parent('li').addClass('active'); // текушей вкладке добавляем класс 'selected'
          return false;
        }).filter(':first').click();
      };


 
var Bright = 'hlight';
var Default= '';



function hl(el, style){el.className = style;}

function notEmpty(elem, err, val) 
{
	var str = elem.value;	
	var k = elem.className;	
	var m = k.indexOf(Bright);  
	if (m != -1) 
	  Default = k.substring(0,m-1)
	else
	  Default = k;
	  
	if(str == null || str.length == 0 || str == val) 	{hl(elem,Default + ' ' + Bright); errorString+=err; return false;}
	else	{hl(elem,Default); return true;}
}
  
  
function validEmail(elem, err)
{
    if(elem.value.length > 0)
	{
		var str = elem.value;
		var splitted = str.match("^(.+)@(.+)$");

	    if(splitted !== null && splitted[1] !== null)
		{
	    	var regexp_user=/^\"?[\w-_\.]*\"?$/;
		    if(splitted[1].match(regexp_user) !== null && splitted[2] !== null)
			{
		    	var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
				var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
				if((splitted[2].match(regexp_domain) !== null) || (splitted[2].match(regexp_ip) !== null))
				{
					hl(elem,Default);
					return true;
				}
			}
		
		}
	}
	hl(elem, Bright);
	errorString+=err;
	return false;
}


function notSelected(elem, err, ind) 
{  
    var str = elem.selectedIndex;

    if(str==ind) 
	{
		hl(elem, Bright);
		errorString+=err; 
		return false;
	}
	else 
	{
		hl(elem,Default);
		return true;
	}
}
 function notChecked(elem, err) 
{
	
  	var str = elem.checked;	
  	var k = elem.className;	
  	var m = k.indexOf(Bright);  
  	if (m != -1) 
  	  Default = k.substring(0,m-1)
  	else
  	  Default = k;
  	  
    if(!str) 
	{
		hl(elem, Default + ' ' + Bright);
		errorString+=err; 
		return false;
	}
	else 
	{
		hl(elem,Default);
		return true;
	}
}
  function notNumeric(elem, err) 
{
	
    var str = elem.value;	
  	var k = elem.className;	
  	var m = k.indexOf(Bright);  
  	if (m != -1) 
  	  Default = k.substring(0,m-1)
  	else
  	  Default = k;
  	  
   if(!((/^[0-9]+[.,][0-9]{1,2}z/.test(str+"z")) || (/^[0-9]+z/.test(str+"z"))) ) 
  	{
  		hl(elem, Default + ' ' + Bright);
  		errorString+=err; 
  		return false;
  	}
  	else 
  	{
  		hl(elem,Default);
  		return true;
  	}
}


 function notChoose(elem, err) 
  { 
    var check=0, k, m;  
    for (var i=0; i < elem.length; i++)
    {       
      k = elem[i].className;	
      m = k.indexOf(Bright);  
      if (m != -1) 
        Default = k.substring(0,m-1)  
      else
        Default = k;  
      if (elem[i].checked) 
       check++; 
    } 
    if (check == 0)    	   
    { for (var i=0; i < elem.length; i++)
        hl(elem[i], Default + ' ' + Bright);      
    	errorString+=err; 
    	return false;
    }
    else 
    { for (var i=0; i < elem.length; i++)
    	 hl(elem[i],Default);
    	return true;
    }
    
  }  

function validateForm(formname)
{
	errorString = "Please fill in following fields:     \n-------------------------------\n";

	var Results = [
	notEmpty(formname.title, 'Title (Miss, Mr, etc) \n', 'Title (Miss, Mr, etc)'),
  notEmpty(formname.full_name, 'Full name \n', 'Full name'),
  notEmpty(formname.address, 'Address \n', 'Address'),
	notEmpty(formname.telephone, 'Telephone number \n', 'Telephone number'),
	notEmpty(formname.email, 'E-mail address \n', 'E-mail Address'),
	validEmail(formname.email, 'E-mail address should be valid \n'),
  notEmpty(formname.amount_pay, 'Amount payable now \n', 'Amount payable now'), 
  notNumeric(formname.amount_pay, 'Amount payable now should be numerical and valid \n'),
  notChecked(formname.act_term_cond, 'Activity terms and conditions \n'),
  notChecked(formname.pol_alc_drugs, 'Policy on alcohol and drugs \n'),
  notChecked(formname.book_term_cond, 'Booking terms and conditions \n'),
  notChecked(formname.authorise_card, 'I authorise my credit card to be charged as per the details above \n'),
  notChecked(formname.confirm_years, 'I confirm that I am 18 years or older \n')
	];
  jQuery(".checkbox").parent("span").next("label").removeClass("hlight");
  jQuery(".checkbox.hlight").parent("span").next("label").addClass("hlight");

	if (Results[0] && Results[1] && Results[2] && Results[3] && Results[4] && Results[5] && Results[6] && Results[7] && Results[8] && Results[9] && Results[10] && Results[11] && Results[12])
	{
		return true;
	}
	else
	{
		alert(errorString);
		return false;
	}
}

function validateFormStudy(formname)
{
	errorString = "Please fill in following fields:     \n-------------------------------\n";

	var Results = [
	notEmpty(formname.title, 'Title (Miss, Mr, etc) \n', 'Title (Miss, Mr, etc)'),
  notEmpty(formname.student_name, 'Name \n', 'Name'),
  notEmpty(formname.address, 'Address in UK \n', 'Address in UK'),
	notEmpty(formname.telephone, 'Telephone number \n', 'Telephone number'),
	notEmpty(formname.email, 'E-mail address \n', 'E-mail Address'),
	validEmail(formname.email, 'E-mail address should be valid \n'),
  notEmpty(formname.date, 'Date of weekend trip \n', 'DATE of Weekend Trip'),
  notChecked(formname.agree_activities, 'You need to agree that you have read and understood the terms and conditions regarding activities \n'),
  notChecked(formname.agree, 'You need to agree that you have read and understood the terms and conditions regarding booking \n') 
	];
  jQuery(".checkbox").parent("span").next("label").removeClass("hlight");
  jQuery(".checkbox").next("label").removeClass("hlight");	
  jQuery(".checkbox.hlight").parent("span").next("label").addClass("hlight");
  jQuery(".checkbox.hlight").next("label").addClass("hlight");

	if (Results[0] && Results[1] && Results[2] && Results[3] && Results[4] && Results[5] && Results[6] && Results[7] && Results[8])
	{
		return true;
	}
	else
	{
		alert(errorString);
		return false;
	}
}

/*
function validateFormStudy(formname)
{
	errorString = "Please fill in following fields:     \n-------------------------------\n";

	var Results = [
	notEmpty(formname.title, 'Title (Miss, Mr, etc) \n', 'Title (Miss, Mr, etc)'),
  notEmpty(formname.student_name, 'Name \n', 'Name'),
  notEmpty(formname.address, 'Address in UK \n', 'Address in UK'),
	notEmpty(formname.telephone, 'Telephone number \n', 'Telephone number'),
	notEmpty(formname.email, 'E-mail address \n', 'E-mail Address'),
	validEmail(formname.email, 'E-mail address should be valid \n'),
  notEmpty(formname.date, 'Date of weekend trip \n', 'DATE of Weekend Trip'),
  notChecked(formname.agree_activities, 'You need to agree that you have read and understood the terms and conditions regarding activities \n'),
  notChecked(formname.agree, 'You need to agree that you have read and understood the terms and conditions regarding booking \n'),
  notChecked(formname.jan_feb, ''),
  notChecked(formname.mar, ''),
  notChecked(formname.april, '') 
	];
  jQuery(".checkbox").parent("span").next("label").removeClass("hlight");
  jQuery(".checkbox").next("label").removeClass("hlight");
  if (jQuery(".checkbox_list .checkbox:checked").length > 0 ) jQuery(".checkbox_list .checkbox.hlight").removeClass("hlight");	
  jQuery(".checkbox.hlight").parent("span").next("label").addClass("hlight");
  jQuery(".checkbox.hlight").next("label").addClass("hlight");

	if (Results[0] && Results[1] && Results[2] && Results[3] && Results[4] && Results[5] && Results[6] && Results[7] && Results[8] && (Results[9] || Results[10] || Results[11]))
	{
		return true;
	}
	else
	{
	  if (!(Results[9] || Results[10] || Results[11]))
	  {errorString+="You need to choose which month you wish to attend: \n"}
		alert(errorString);
		return false;
	}
}

*/

function validateFormCont(formname)
{ 
	errorString = "Please fill in following fields:     \n-------------------------------\n";
	var Results = [
  notEmpty(formname.fullname, 'Your name \n', 'Your name'),
	notEmpty(formname.email, 'Your email \n', 'Your email'),
	validEmail(formname.email, 'Your email should be valid \n'),
  notEmpty(formname.code, 'The captcha code \n', '')
	];
	if (Results[0] && Results[1] && Results[2] && Results[3]) {	return true;}
	else { alert(errorString);	return false;	}
}

function validateFormFeed(formname)
{ 
	errorString = "Please fill in following fields:     \n-------------------------------\n";
	var Results = [
  //notEmpty(formname.fullname, 'Your name \n', 'Your name'),
	//notEmpty(formname.email, 'Your email address \n', 'Your email address'),
//	validEmail(formname.email, 'Your email address should be valid \n'),
  notEmpty(formname.problem, 'Please let us know about any problems you encountered \n', 'Please let us know about any problems you encountered, anything we can do to make our website better – or anything else!')
	];
	if (Results[0] /*&& Results[1] && Results[2]*/) {	return true;}
	else { alert(errorString);	return false;	}
}

function validateFormNews(formname)
{ 
  
	errorString = "Please fill in following fields:     \n-------------------------------\n";
	var Results = [
  notEmpty(formname.fullname, 'First Name \n', 'First Name'),
  notEmpty(formname.surname, 'Surname \n', 'Surname'),
	notEmpty(formname.email, 'Your email address \n', 'Your email address'),
	validEmail(formname.email, 'Your email address should be valid \n'),
	notChecked(formname.adventure, ''),
	notChecked(formname.specoffers, '')
	];
  jQuery(".checkbox").parent("span").next("label").removeClass("hlight");  
  if (jQuery(".checkbox:checked").length > 0 ) 
    jQuery(".checkbox.hlight").removeClass("hlight");	
  jQuery(".checkbox.hlight").parent("span").next("label").addClass("hlight");
	if (Results[0] && Results[1] && Results[2] && Results[3] && (Results[4] || Results[5])) 
    {	return true;}
	else 
    { 
      if (!(Results[4] || Results[5])) {
        errorString+="You need to choose which newsletter you wish to subscribe to \n"
      } 
      alert(errorString);	return false;	
    }
}
