
function echeck(email) {

	var at="@"
	var dot="."
	var lat=email.indexOf(at)
	var lstr=email.length
	var ldot=email.indexOf(dot)
	var error = "error"

	if (email.indexOf(at)==-1){
    	    return error;
	}

	if (email.indexOf(at)==-1 || email.indexOf(at)==0 || email.indexOf(at)==lstr){
	   return error;
	}

	if (email.indexOf(dot)==-1 || email.indexOf(dot)==0 || email.indexOf(dot)==lstr){
	    return error;
	}

	 if (email.indexOf(at,(lat+1))!=-1){
	    return error;
	 }

	 if (email.substring(lat-1,lat)==dot || email.substring(lat+1,lat+2)==dot){
	    return error;
	 }

	 if (email.indexOf(dot,(lat+2))==-1){
	    return error;
	 }

	 if (email.indexOf(" ")!=-1){
	    return error;
	 }

	 return "";
}

function validatePhone(fld) {
    var valide = true;
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');

   if (fld.value == "") {
        valide = false;
    } else if (isNaN(stripped)) {
        valide = false;
    }

    return valide;
}

function validateCityName(fld) {
    var valide = true;
    var stripped = fld.value.replace(/[\''\.\""\-\ \a-zA-Z\ă\Ă\î\Î\ş\Ş\ţ\Ţ\â\Â]/g, '');

   if (stripped != "") {
        valide = false;
    }

    return valide;
}

function check_book(){
    	var obj = document.getElementById("fb_input");
        var res = true;
        var topPosition;

        document.getElementById("error_msg").style.visibility = 'hidden';

		//from
    	if(obj.from.value=="" || !validateCityName(obj.from)){
    		var bal_from = document.getElementById("bal_from");
    		topPosition = parseInt(bal_from.clientHeight);
    		bal_from.style.top = '-' + topPosition + 'px';
    		opacity('bal_from',0,100,500);

    		res = false;
    	}


        //to
    	if(obj.to.value=="" || !validateCityName(obj.to)){
    		var bal_to = document.getElementById("bal_to");
    		topPosition = parseInt(bal_to.clientHeight);
    		bal_to.style.top = '-' + topPosition + 'px';
            opacity('bal_to',0,100,500);

    		res = false;
    	}



   /*   //firstname
    	if(obj.firstname.value==""){
    		var bal_firstname = document.getElementById("bal_firstname");
    		topPosition = parseInt(bal_firstname.clientHeight)+15;
    		bal_firstname.style.top = '-' + topPosition + 'px';
            opacity('bal_firstname',0,100,500);

    		res = false;
    	}


    	//lastname
    	if(obj.lastname.value==""){
    		var bal_lastname = document.getElementById("bal_lastname");
    		topPosition = parseInt(bal_lastname.clientHeight)-15;
    		bal_lastname.style.top = '-' + topPosition + 'px';
            opacity('bal_lastname',0,100,500);

    		res = false;
    	}   */


		//email
    	if(obj.email.value=="" || echeck(obj.email.value)){
    		var bal_email = document.getElementById("bal_email");
    		topPosition = parseInt(bal_email.clientHeight);
    		bal_email.style.top ='-' + topPosition + 'px';
            opacity('bal_email',0,100,500);

    		res = false;
    	}


    	//phone
    	if((obj.phone.value=="" && obj.mobile.value=="") || !validatePhone(obj.phone)){
    		var bal_phone = document.getElementById("bal_phone");
    		topPosition = parseInt(bal_phone.clientHeight);
    		bal_phone.style.top = '-' + topPosition + 'px';
            opacity('bal_phone',0,100,500);

    		res = false;
    	}

        //mobilephone
    	if(obj.mobile.value!="" && !validatePhone(obj.mobile)){
    		var bal_mobile = document.getElementById("bal_mobile");
    		topPosition = parseInt(bal_mobile.clientHeight);
    		bal_mobile.style.top = '-' + topPosition + 'px';
            opacity('bal_mobile',0,100,500);

    		res = false;
    	}

    	//fax
    	if(obj.fax.value!="" && !validatePhone(obj.fax)){
    		var bal_fax = document.getElementById("bal_fax");
    		topPosition = parseInt(bal_fax.clientHeight)-5;
    		bal_fax.style.top = '-' + topPosition + 'px';
            opacity('bal_fax',0,100,500);

    		res = false;
    	}


        //secure cod
    	if(obj.security_code.value==""){
    		var bal_cod = document.getElementById("bal_cod");
    		topPosition = 48;
    		bal_cod.style.top = topPosition + 'px';
            opacity('bal_cod',0,100,500);

    		res = false;
    	}


     	//date difference
     	var dep_day = parseInt(document.getElementById('id_day0').options[document.getElementById('id_day0').options.selectedIndex].value);
     	var arv_day = parseInt(document.getElementById('id_day1').options[document.getElementById('id_day1').options.selectedIndex].value);

     	var dep_month0 = document.getElementById('id_month0').options[document.getElementById('id_month0').options.selectedIndex].value;
     	var dep_month1 = document.getElementById('id_month1').options[document.getElementById('id_month1').options.selectedIndex].value;

     	var dep_month = parseInt(dep_month0);
     	var arv_month = parseInt(dep_month1);

     	var dep_year = parseInt(dep_month0.substring(dep_month0.indexOf('-')+1,dep_month0.length-1));
     	var arv_year = parseInt(dep_month1.substring(dep_month1.indexOf('-')+1,dep_month1.length-1));


     	var depDate = new Date;
     	var arvDate = new Date;

     	depDate.setDate(dep_day);
		depDate.setMonth(dep_month);
		depDate.setFullYear(dep_year);

		arvDate.setDate(arv_day);
		arvDate.setMonth(arv_month);
		arvDate.setFullYear(arv_year);

		if(depDate > arvDate){
			var bal_depDate = document.getElementById("bal_depDate");
    		topPosition = parseInt(bal_depDate.clientHeight)+200;
    		bal_depDate.style.top = '-' + topPosition + 'px';
            opacity('bal_depDate',0,100,500);
    		res = false;
		}


		//Check if all passangers was indicated
		var nr_pass = document.getElementById("nb_passengers").options[document.getElementById("nb_passengers").options.selectedIndex].value;
		var field_name = '';
        var local_res = true;

		for(i=1;i<=nr_pass;i++){//lastname
            field_name = 'last_name_' + i;
			if(document.getElementById(field_name).value == ""){
				document.getElementById(field_name).className = 'active';
				res = false;
				local_res = false;
			}
			else{
				document.getElementById(field_name).className = 'field';
			}
		}

		for(i=1;i<=nr_pass;i++){//firstname
            field_name = 'first_name_' + i;
			if(document.getElementById(field_name).value == ""){
				document.getElementById(field_name).className = 'active';
				res = false;
				local_res = false;
			}
			else{
				document.getElementById(field_name).className = 'field';
			}
		}

		//ballon
    	if(!local_res){
    		var bal_pass = document.getElementById("bal_pass");
    		topPosition = parseInt(bal_pass.clientHeight)-10;
    		bal_pass.style.top = '+20px';
            opacity('bal_pass',0,100,100);

    		res = false;
    	}


		//Show error message and return the error status
        if(!res) document.getElementById("error_msg").style.visibility = 'visible';
     	return res;
}

function check_book2(){
    	var obj = document.getElementById("fb_input");
        var res = true;
        var topPosition;

        document.getElementById("error_msg").style.visibility = 'hidden';

		//from
    	if(obj.from.value=="" || !validateCityName(obj.from)){
    		var bal_from = document.getElementById("bal_from");
    		topPosition = parseInt(bal_from.clientHeight);
    		bal_from.style.top = '-' + topPosition + 'px';
    		opacity('bal_from',0,100,500);

    		res = false;
    	}


        //to
    	if(obj.to.value=="" || !validateCityName(obj.to)){
    		var bal_to = document.getElementById("bal_to");
    		topPosition = parseInt(bal_to.clientHeight);
    		bal_to.style.top = '-' + topPosition + 'px';
            opacity('bal_to',0,100,500);

    		res = false;
    	}



   /*   //firstname
    	if(obj.firstname.value==""){
    		var bal_firstname = document.getElementById("bal_firstname");
    		topPosition = parseInt(bal_firstname.clientHeight)+15;
    		bal_firstname.style.top = '-' + topPosition + 'px';
            opacity('bal_firstname',0,100,500);

    		res = false;
    	}


    	//lastname
    	if(obj.lastname.value==""){
    		var bal_lastname = document.getElementById("bal_lastname");
    		topPosition = parseInt(bal_lastname.clientHeight)-15;
    		bal_lastname.style.top = '-' + topPosition + 'px';
            opacity('bal_lastname',0,100,500);

    		res = false;
    	}   */


		//email
    	if(obj.email.value=="" || echeck(obj.email.value)){
    		var bal_email = document.getElementById("bal_email");
    		topPosition = parseInt(bal_email.clientHeight);
    		bal_email.style.top ='-' + topPosition + 'px';
            opacity('bal_email',0,100,500);

    		res = false;
    	}


    	//phone
    	if((obj.phone.value=="" && obj.mobile.value=="") || !validatePhone(obj.phone)){
    		var bal_phone = document.getElementById("bal_phone");
    		topPosition = parseInt(bal_phone.clientHeight);
    		bal_phone.style.top = '-' + topPosition + 'px';
            opacity('bal_phone',0,100,500);

    		res = false;
    	}

        //mobilephone
    	if(obj.mobile.value!="" && !validatePhone(obj.mobile)){
    		var bal_mobile = document.getElementById("bal_mobile");
    		topPosition = parseInt(bal_mobile.clientHeight);
    		bal_mobile.style.top = '-' + topPosition + 'px';
            opacity('bal_mobile',0,100,500);

    		res = false;
    	}

    	//fax
    	if(obj.fax.value!="" && !validatePhone(obj.fax)){
    		var bal_fax = document.getElementById("bal_fax");
    		topPosition = parseInt(bal_fax.clientHeight)-5;
    		bal_fax.style.top = '-' + topPosition + 'px';
            opacity('bal_fax',0,100,500);

    		res = false;
    	}


        //secure cod
    	if(obj.security_code.value==""){
    		var bal_cod = document.getElementById("bal_cod");
    		topPosition = 48;
    		bal_cod.style.top = topPosition + 'px';
            opacity('bal_cod',0,100,500);

    		res = false;
    	}


     	/*<!--//date difference
     	var dep_day = parseInt(document.getElementById('id_day0').options[document.getElementById('id_day0').options.selectedIndex].value);
     	var arv_day = parseInt(document.getElementById('id_day1').options[document.getElementById('id_day1').options.selectedIndex].value);

     	var dep_month0 = document.getElementById('id_month0').options[document.getElementById('id_month0').options.selectedIndex].value;
     	var dep_month1 = document.getElementById('id_month1').options[document.getElementById('id_month1').options.selectedIndex].value;

     	var dep_month = parseInt(dep_month0);
     	var arv_month = parseInt(dep_month1);

     	var dep_year = parseInt(dep_month0.substring(dep_month0.indexOf('-')+1,dep_month0.length-1));
     	var arv_year = parseInt(dep_month1.substring(dep_month1.indexOf('-')+1,dep_month1.length-1));


     	var depDate = new Date;
     	var arvDate = new Date;

     	depDate.setDate(dep_day);
		depDate.setMonth(dep_month);
		depDate.setFullYear(dep_year);

		arvDate.setDate(arv_day);
		arvDate.setMonth(arv_month);
		arvDate.setFullYear(arv_year);

		if(depDate > arvDate){
			var bal_depDate = document.getElementById("bal_depDate");
    		topPosition = parseInt(bal_depDate.clientHeight)+200;
    		bal_depDate.style.top = '-' + topPosition + 'px';
            opacity('bal_depDate',0,100,500);
    		res = false;
		}-->*/


		//Check if all passangers was indicated
		/*var nr_pass = document.getElementById("nb_passengers").options[document.getElementById("nb_passengers").options.selectedIndex].value;
		var field_name = '';
        var local_res = true;

		for(i=1;i<=nr_pass;i++){//lastname
            field_name = 'last_name_' + i;
			if(document.getElementById(field_name).value == ""){
				document.getElementById(field_name).className = 'active';
				res = false;
				local_res = false;
			}
			else{
				document.getElementById(field_name).className = 'field';
			}
		}

		for(i=1;i<=nr_pass;i++){//firstname
            field_name = 'first_name_' + i;
			if(document.getElementById(field_name).value == ""){
				document.getElementById(field_name).className = 'active';
				res = false;
				local_res = false;
			}
			else{
				document.getElementById(field_name).className = 'field';
			}
		}

		//ballon
    	if(!local_res){
    		var bal_pass = document.getElementById("bal_pass");
    		topPosition = parseInt(bal_pass.clientHeight)-10;
    		bal_pass.style.top = '+20px';
            opacity('bal_pass',0,100,100);

    		res = false;
    	}
*/

		//Show error message and return the error status
        if(!res) document.getElementById("error_msg").style.visibility = 'visible';
     	return res;
}

function check_book3(){
    	var obj = document.getElementById("fb_input");
        var res = true;
        var topPosition;

        document.getElementById("error_msg").style.visibility = 'hidden';

		//from
    	/*if(obj.from.value=="" || !validateCityName(obj.from)){
    		var bal_from = document.getElementById("bal_from");
    		topPosition = parseInt(bal_from.clientHeight);
    		bal_from.style.top = '-' + topPosition + 'px';
    		opacity('bal_from',0,100,500);

    		res = false;
    	}*/


        //to
    	//if(obj.to.value=="" || !validateCityName(obj.to)){
		if(obj.to.value==""){
    		var bal_to = document.getElementById("bal_to");
    		topPosition = parseInt(bal_to.clientHeight);
    		bal_to.style.top = '-' + topPosition + 'px';
            opacity('bal_to',0,100,500);

    		res = false;
    	}



   /*   //firstname
    	if(obj.firstname.value==""){
    		var bal_firstname = document.getElementById("bal_firstname");
    		topPosition = parseInt(bal_firstname.clientHeight)+15;
    		bal_firstname.style.top = '-' + topPosition + 'px';
            opacity('bal_firstname',0,100,500);

    		res = false;
    	}


    	//lastname
    	if(obj.lastname.value==""){
    		var bal_lastname = document.getElementById("bal_lastname");
    		topPosition = parseInt(bal_lastname.clientHeight)-15;
    		bal_lastname.style.top = '-' + topPosition + 'px';
            opacity('bal_lastname',0,100,500);

    		res = false;
    	}   */


		//email
    	if(obj.email.value=="" || echeck(obj.email.value)){
    		var bal_email = document.getElementById("bal_email");
    		topPosition = parseInt(bal_email.clientHeight);
    		bal_email.style.top ='-' + topPosition + 'px';
            opacity('bal_email',0,100,500);

    		res = false;
    	}


    	//phone
    	if((obj.phone.value=="" && obj.mobile.value=="") || !validatePhone(obj.phone)){
    		var bal_phone = document.getElementById("bal_phone");
    		topPosition = parseInt(bal_phone.clientHeight);
    		bal_phone.style.top = '-' + topPosition + 'px';
            opacity('bal_phone',0,100,500);

    		res = false;
    	}

        //mobilephone
    	if(obj.mobile.value!="" && !validatePhone(obj.mobile)){
    		var bal_mobile = document.getElementById("bal_mobile");
    		topPosition = parseInt(bal_mobile.clientHeight);
    		bal_mobile.style.top = '-' + topPosition + 'px';
            opacity('bal_mobile',0,100,500);

    		res = false;
    	}

    	//fax
    	if(obj.fax.value!="" && !validatePhone(obj.fax)){
    		var bal_fax = document.getElementById("bal_fax");
    		topPosition = parseInt(bal_fax.clientHeight)-5;
    		bal_fax.style.top = '-' + topPosition + 'px';
            opacity('bal_fax',0,100,500);

    		res = false;
    	}


        //secure cod
    	if(obj.security_code.value==""){
    		var bal_cod = document.getElementById("bal_cod");
    		topPosition = 48;
    		bal_cod.style.top = topPosition + 'px';
            opacity('bal_cod',0,100,500);

    		res = false;
    	}


     	//date difference
     	/*var dep_day = parseInt(document.getElementById('id_day0').options[document.getElementById('id_day0').options.selectedIndex].value);
     	var arv_day = parseInt(document.getElementById('id_day1').options[document.getElementById('id_day1').options.selectedIndex].value);

     	var dep_month0 = document.getElementById('id_month0').options[document.getElementById('id_month0').options.selectedIndex].value;
     	var dep_month1 = document.getElementById('id_month1').options[document.getElementById('id_month1').options.selectedIndex].value;

     	var dep_month = parseInt(dep_month0);
     	var arv_month = parseInt(dep_month1);

     	var dep_year = parseInt(dep_month0.substring(dep_month0.indexOf('-')+1,dep_month0.length-1));
     	var arv_year = parseInt(dep_month1.substring(dep_month1.indexOf('-')+1,dep_month1.length-1));


     	var depDate = new Date;
     	var arvDate = new Date;

     	depDate.setDate(dep_day);
		depDate.setMonth(dep_month);
		depDate.setFullYear(dep_year);

		arvDate.setDate(arv_day);
		arvDate.setMonth(arv_month);
		arvDate.setFullYear(arv_year);

		if(depDate > arvDate){
			var bal_depDate = document.getElementById("bal_depDate");
    		topPosition = parseInt(bal_depDate.clientHeight)+200;
    		bal_depDate.style.top = '-' + topPosition + 'px';
            opacity('bal_depDate',0,100,500);
    		res = false;
		}*/


		//Check if all passangers was indicated
		var nr_pass = document.getElementById("nb_passengers").options[document.getElementById("nb_passengers").options.selectedIndex].value;
		var field_name = '';
        var local_res = true;

		/*for(i=1;i<=nr_pass;i++){//lastname
            field_name = 'last_name_' + i;
			if(document.getElementById(field_name).value == ""){
				document.getElementById(field_name).className = 'active';
				res = false;
				local_res = false;
			}
			else{
				document.getElementById(field_name).className = 'field';
			}
		}

		for(i=1;i<=nr_pass;i++){//firstname
            field_name = 'first_name_' + i;
			if(document.getElementById(field_name).value == ""){
				document.getElementById(field_name).className = 'active';
				res = false;
				local_res = false;
			}
			else{
				document.getElementById(field_name).className = 'field';
			}
		}

		//ballon
    	if(!local_res){
    		var bal_pass = document.getElementById("bal_pass");
    		topPosition = parseInt(bal_pass.clientHeight)-10;
    		bal_pass.style.top = '+20px';
            opacity('bal_pass',0,100,100);

    		res = false;
    	}*/


		//Show error message and return the error status
        if(!res) document.getElementById("error_msg").style.visibility = 'visible';
     	return res;
}


function hide_bal(idName){
	if(document.getElementById(idName).style.opacity == 1)
		opacity(idName,100,0,200);
	return true;
}


function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "',1)",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        document.getElementById(id).style.visibility = 'visible';
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "',0)",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id, hide) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";

    if(hide == 1 && opacity == 0)
    	object.visibility = 'hidden';
}
