/*
News ticker plugin (BBC news style)
Bryan Gullan,2007-2010
version 2.2
updated 2010-04-04
Documentation at http://www.makemineatriple.com/news-ticker-documentation/
Demo at http://www.makemineatriple.com/jquery/?newsTicker
Use and distrubute freely with this header intact.
*/

(function($) {
	
	var name='newsTicker';
	
	function runTicker(settings) {
		
		tickerData = $(settings.newsList).data('newsTicker');
		
		if(tickerData.currentItem > tickerData.newsItemCounter){
			// if we've looped to beyond the last item in the list, start over
			tickerData.currentItem = 0;
		}
		else if (tickerData.currentItem < 0) {
			// if we've looped back before the first item, move to the last one
			tickerData.currentItem = tickerData.newsItemCounter;
		}
		
		if(tickerData.currentPosition == 0) {
			if(tickerData.newsLinks[tickerData.currentItem].length > 0) {
				$(tickerData.newsList).empty().append('<li><a href="'+ tickerData.newsLinks[tickerData.currentItem] +'"></a></li>');
			}
			else {
				$(tickerData.newsList).empty().append('<li></li>');
			}
		}
		
		//only start the ticker itself if it's defined as animating: otherwise it's paused or under manual advance
		if (tickerData.animating) {
			
			if( tickerData.currentPosition % 2 == 0) {
					var placeHolder = tickerData.placeHolder1;
			}
			else {
				var placeHolder = tickerData.placeHolder2;
			}
			
			if( tickerData.currentPosition < tickerData.newsItems[tickerData.currentItem].length) {
				// we haven't completed ticking out the current item
				
				var tickerText = tickerData.newsItems[tickerData.currentItem].substring(0,tickerData.currentPosition);
				if(tickerData.newsLinks[tickerData.currentItem].length > 0) {
					$(tickerData.newsList + ' li a').text(tickerText + placeHolder);
				}
				else {
					$(tickerData.newsList + ' li').text(tickerText + placeHolder);
				}
				tickerData.currentPosition ++;
				setTimeout(function(){runTicker(settings); settings = null;},tickerData.tickerRate);
			}
			
			else {
				// we're on the last letter of the current item
				
				if(tickerData.newsLinks[tickerData.currentItem].length > 0) {
					$(tickerData.newsList + ' li a').text(tickerData.newsItems[tickerData.currentItem]);
				}
				else {
					$(tickerData.newsList + ' li').text(tickerData.newsItems[tickerData.currentItem]);
				}
				
				setTimeout(function(){
					if (tickerData.animating) {
						tickerData.currentPosition = 0;
						tickerData.currentItem ++;
						runTicker(settings); settings = null;
					}
				},tickerData.loopDelay);
				
			}
		}
		
		else {// settings.animating == false 
			
			// display the full text of the current item
			var tickerText = tickerData.newsItems[tickerData.currentItem];
			
			if(tickerData.newsLinks[tickerData.currentItem].length > 0) {
				$(tickerData.newsList + ' li a').text(tickerText);
			}
			else {
				$(tickerData.newsList + ' li').text(tickerText);
			}
					
		}
		
	}

	
	// Core plugin setup and config
	jQuery.fn[name] = function(options) {
 
	    // Add or overwrite options onto defaults
	    var settings = jQuery.extend({}, jQuery.fn.newsTicker.defaults, options);
	 
        var newsItems = new Array();
		var newsLinks = new Array();
		var newsItemCounter = 0;
		
		// Hide the static list items
		$(settings.newsList + ' li').hide();
		
		// Store the items and links in arrays for output
		$(settings.newsList + ' li').each(function(){
			if($(this).children('a').length) {
				newsItems[newsItemCounter] = $(this).children('a').text();
				newsLinks[newsItemCounter] = $(this).children('a').attr('href');
			}
			else {
				newsItems[newsItemCounter] = $(this).text();
				newsLinks[newsItemCounter] = '';
			}
			newsItemCounter ++;
		});
        
        var tickerElement = $(settings.newsList); // for quick reference below
        
        tickerElement.data(name, {
        	newsList: settings.newsList,
			tickerRate: settings.tickerRate,
			startDelay: settings.startDelay,
			loopDelay: settings.loopDelay,
			placeHolder1: settings.placeHolder1,
			placeHolder2: settings.placeHolder2,
			controls: settings.controls,
			ownControls: settings.ownControls,
			stopOnHover: settings.stopOnHover,
            newsItems: newsItems,
			newsLinks: newsLinks,
			newsItemCounter: newsItemCounter - 1, // -1 because we've incremented even after the last item (above)
			currentItem: 0,
			currentPosition: 0,
			firstRun:1
        })
        .bind({
			stop: function(event) {
				// show remainder of the current item immediately
		    	tickerData = tickerElement.data(name);
		    	if (tickerData.animating) { // only stop if not already stopped
            		tickerData.animating = false;
               	}
		  	},
		  	play: function(event) {
		  		// show 1st item with startdelay
		    	tickerData = tickerElement.data(name);
		    	if (!tickerData.animating) { // if already animating, don't start animating again
	            	tickerData.animating = true;
	            	setTimeout(function(){runTicker(tickerData); tickerData = null;},tickerData.startDelay);
	            }
		  	},
		  	resume: function(event) {
		  		// start from next item, with no delay
		    	tickerData = tickerElement.data(name);
		    	if (!tickerData.animating) { // if already animating, don't start animating again
	            	tickerData.animating = true;
	            	// set the character position as 0 to ensure on resume we start at the right point
					tickerData.currentPosition = 0;
	            	tickerData.currentItem ++;
	            	runTicker(tickerData); // no delay when resuming.
		        }
		  	},
		  	next: function(event) {
		  		// show whole of next item
		  		tickerData = tickerElement.data(name);
		  		// stop (which sets as non-animating), and call runticker
		  		$(tickerData.newsList).trigger("stop");
		  		// set the character position as 0 to ensure on resume we start at the right point
				tickerData.currentPosition = 0;
	            tickerData.currentItem ++;
	            runTicker(tickerData);
		  	},
		  	previous: function(event) {
				// show whole of previous item
				tickerData = tickerElement.data(name);
		  		// stop (which sets as non-animating), and call runticker
		  		$(tickerData.newsList).trigger("stop");
		  		// set the character position as 0 to ensure on resume we start at the right point
				tickerData.currentPosition = 0;
	            tickerData.currentItem --;
	            runTicker(tickerData);
			}
		}); 	
		if (settings.stopOnHover) {
	    	tickerElement.bind({			    	
			  	mouseover: function(event) {
			  		tickerData = tickerElement.data(name);
			    	if (tickerData.animating) { // stop if not already stopped
				  		$(tickerData.newsList).trigger("stop");
				  		if (tickerData.controls) { // ensure that the ticker can be resumed if controls are enabled
				  			$('.stop').hide();
			        		$('.resume').show();
				  		}
			  		}
			  	}
			});
    	}
    	
    	tickerData = tickerElement.data(name);
    	
    	// set up control buttons if the option is on
		if (tickerData.controls || tickerData.ownControls) {
			if (!tickerData.ownControls) {
				$('<ul class="ticker-controls"><li class="play"><a href="#play">&nbsp;</a></li><li class="resume"><a href="#resume">&nbsp;</a></li><li class="stop"><a href="#stop">&nbsp;</a></li><li class="previous"><a href="#previous">&nbsp;</a></li><li class="next"><a href="#next">&nbsp;</a></li></ul>').insertAfter($(tickerData.newsList));
			}
			$('.play').hide();
		    $('.resume').hide();
			
		    $('.play').click(function(event){
		        $(tickerData.newsList).trigger("play");
		        $('.play').hide();
		        $('.resume').hide();
		        $('.stop').show();
		        event.preventDefault();
		    });
		    $('.resume').click(function(event){
		        $(tickerData.newsList).trigger("resume");
		        $('.play').hide();
		        $('.resume').hide();
		        $('.stop').show();
		        event.preventDefault();
		    });
			$('.stop').click(function(event){
		        $(tickerData.newsList).trigger("stop");
		        $('.stop').hide();
		        $('.resume').show();
		        event.preventDefault();
		    });
		    $('.previous').click(function(event){
		        $(tickerData.newsList).trigger("previous");
		        $('.stop').hide();
			    $('.resume').show();
		        event.preventDefault();
		    });
		    $('.next').click(function(event){
		        $(tickerData.newsList).trigger("next");
		        $('.stop').hide();
			    $('.resume').show();
		        event.preventDefault();
		    });

	    };
    	
    	// tell it to play
    	$(tickerData.newsList).trigger("play");
	};

	// News ticker defaults 
	jQuery.fn[name].defaults = {
	    newsList: "#news",
		tickerRate: 80,
		startDelay: 100,
		loopDelay: 3000,
		placeHolder1: " |",
		placeHolder2: "_",
		controls: true,
		ownControls: false,
		stopOnHover: true
	}

})(jQuery);

function validateContact (lang_id) {
    var name = document.getElementById('contact_name').value;
    var email = document.getElementById('contact_email').value;
    var address = document.getElementById('contact_address').value;
    var country = document.getElementById('contact_country').value;
    var subject = document.getElementById('contact_subject').value;
    var message = document.getElementById('contact_msg').value;
    var captcha = document.getElementById('contact_captcha').value;

    var error = false;
    if(lang_id == 2){

       var messageTitle = 'Erreur';
       var messageAlert = 'Veuillez saisir:';


        var msgName  = '- votre nom complet.';
        var msgEmail  = '- votre e-mail.';
        var msgSubj  = '- un sujet.';
        var msgMessage  = '- un message.';
        var msgValidEmail  = '- un e-mail valide.';
        var msgCaptcha = '- le code image.';

        var msgWait = 'Veuillez patienter, l\'envoi de votre message est en cours';  

    }else{
        var messageTitle = 'Error';
        var messageAlert = 'Please enter:';


        var msgName  = '- your full name.';
        var msgEmail  = '- your e-mail.';
        var msgSubj  = '- a subject.';
        var msgMessage  = '- a message.';
        var msgValidEmail  = '- a valid e-mail.';
        var msgCaptcha = '- the image code.';

        var msgWait = 'Please wait while your message is being sent';
    }


    if (isEmpty(name)) {
        messageAlert = messageAlert + "<br/>" + msgName;
        error = true;
    }

    if (isEmpty(email)) {
        messageAlert = messageAlert + "<br/>" + msgEmail;
        error = true;
    }

    if(!isEmpty(email) && validateEmail(email)==false){
        messageAlert = messageAlert + "<br/>" + msgValidEmail;
        error = true;
    }

    if (isEmpty(subject)) {
        messageAlert = messageAlert + "<br/>" + msgSubj;
        error = true;
    }

    if (isEmpty(message)) {
        messageAlert = messageAlert + "<br/>" + msgMessage;
        error = true;
    }

    if (captcha == "Copier le code image ici" || captcha == "Copy image code here" || isEmpty(captcha)) {
        messageAlert = messageAlert + "<br/>" + msgCaptcha;
        error = true;
    }
    if(error){

        if(document.getElementById('contact_error')){
            document.getElementById('contact_error').innerHTML = '<p style="padding-left:140px;">'+ messageAlert +'</p>';

        }
        //return false;
    }
    else{
        if(document.getElementById('contact_error')){
            document.getElementById('contact_error').innerHTML = '<p style="text-align:center;">'+ msgWait +'</p>';
        }
        
        if(document.getElementById('contact_copy').checked){
            var copy = true;
        }else{
             var copy = false;
        }
        //return true;
        sendContactmail(name,email,address,country,subject,message,captcha,copy);
    }
}
//fonction pour verifier des champs vides (par Souraksha)
function isEmpty(input){
    if(input == ''){
        return true;
    }else{
        return false;
    }

}

function validateEmail(email) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var address = email//document.forms[adminForm].elements[email].value;
    if(reg.test(address) == false) {
        //alert('Invalid Email Address');
        //document.forms[adminForm].elements[email].focus();
        return false;
    }
}
//fonction pour envoyer le mail
function sendContactmail(name,email,address,country,subject,message,captcha,copy){

        var queryString = 'ajax_process.php?contact=1';
        var stringData = '&contact_name='+name+
                         '&contact_email='+email+
                         '&contact_address='+address+
                         '&contact_country='+country+
                         '&contact_subject='+subject+
                         '&contact_msg='+message+
                         '&contact_captcha='+captcha;


        if(copy){
            stringData = stringData + '&contact_copy=1';
        }


    jQuery.ajax({
        type: "POST",
        url: queryString,
        data: stringData,
        success: function(msg){
            var response = msg.split('_');

            if (response[1]=='ok'){

                //Clearing fields
                document.getElementById('contact_name').value = '';
                document.getElementById('contact_email').value= '';
                document.getElementById('contact_address').value= '';
                document.getElementById('contact_country').value= '';
                document.getElementById('contact_subject').value= '';
                document.getElementById('contact_msg').value= '';
                document.getElementById('contact_captcha').value= '';
                document.getElementById('contact_copy').checked= false;
                
                //displaying success error
                 if(document.getElementById('contact_error')){
                    document.getElementById('contact_error').style.display = 'block';
                    document.getElementById('contact_error').innerHTML = '<p style="text-align:center;">'+response[0]+'</p>';
                 }
               

            }else{
                if(document.getElementById('contact_error')){
                    document.getElementById('contact_error').style.display = 'block';
                    document.getElementById('contact_error').innerHTML = '<p style="text-align:center;">'+response[0]+'</p>';
                }
                
                return false;
            }
        },
        error: ""
    });


}



/*

CUSTOM FORM ELEMENTS

Created by Ryan Fait
www.ryanfait.com

The only things you may need to change in this file are the following
variables: checkboxHeight, radioHeight and selectWidth (lines 24, 25, 26)

The numbers you set for checkboxHeight and radioHeight should be one quarter
of the total height of the image want to use for checkboxes and radio
buttons. Both images should contain the four stages of both inputs stacked
on top of each other in this order: unchecked, unchecked-clicked, checked,
checked-clicked.

You may need to adjust your images a bit if there is a slight vertical
movement during the different stages of the button activation.

The value of selectWidth should be the width of your select list image.

Visit http://ryanfait.com/ for more information.

*/

var checkboxHeight = "25";
var radioHeight = "25";
var selectWidth = "190";


/* No need to change anything after this */


document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } .disabled { opacity: 0.5; filter: alpha(opacity=50); }</style>');

var Custom = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		for(a = 0; a < inputs.length; a++) {
			if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") {
				span[a] = document.createElement("span");
				span[a].className = inputs[a].type;

				if(inputs[a].checked == true) {
					if(inputs[a].type == "checkbox") {
						position = "0 -" + (checkboxHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					} else {
						position = "0 -" + (radioHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					}
				}
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.clear;
				if(!inputs[a].getAttribute("disabled")) {
					span[a].onmousedown = Custom.pushed;
					span[a].onmouseup = Custom.check;
				} else {
					span[a].className = span[a].className += " disabled";
				}
			}
		}
		inputs = document.getElementsByTagName("select");
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].className == "styled") {
				option = inputs[a].getElementsByTagName("option");
				active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++) {
					if(option[b].selected == true) {
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = "select";
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				if(!inputs[a].getAttribute("disabled")) {
					inputs[a].onchange = Custom.choose;
				} else {
					inputs[a].previousSibling.className = inputs[a].previousSibling.className += " disabled";
				}
			}
		}
		document.onmouseup = Custom.clear;
	},
	pushed: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
		} else if(element.checked == true && element.type == "radio") {
			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
		} else if(element.checked != true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
		} else {
			this.style.backgroundPosition = "0 -" + radioHeight + "px";
		}
	},
	check: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 0";
			element.checked = false;
		} else {
			if(element.type == "checkbox") {
				this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else {
				this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
				group = this.nextSibling.name;
				inputs = document.getElementsByTagName("input");
				for(a = 0; a < inputs.length; a++) {
					if(inputs[a].name == group && inputs[a] != this.nextSibling) {
						inputs[a].previousSibling.style.backgroundPosition = "0 0";
					}
				}
			}
			element.checked = true;
		}
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
			} else if(inputs[b].type == "radio" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			}
		}
	},
	choose: function() {
		//specific to vin et champagne project - onChange ajax functions are called
                if (this.id == 'site'){
                   redirectSite(this.value);
                }
                option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
			}
		}
	}
}
window.onload = Custom.init;

function redirectSite(site){

   if(site == 'hmt'){
       location =("http://www.hmtechnologies.mu");
   }else if(site == 'hmo'){
       location =("http://www.hmoutsourcing.com");
   }else{
       location =("http://www.harelmallac.com");
   }
   
}

/*************popup**************/
/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$(".button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});

function validateSupport (lang_id) {
    var name = document.getElementById('support_name').value;
    var email = document.getElementById('support_email').value;
    var tel = document.getElementById('support_tel').value;
    var company_name = document.getElementById('support_company_name').value;


    var error = false;
    if(lang_id == 2){

       //var messageTitle = 'Erreur';
       var messageAlert = 'Veuillez saisir:';


        var msgName  = '- votre nom';
        var msgEmail  = '- votre e-mail';
        var msgTel  = '- votre n&deg; t&eacute;l&eacute;phone';
        var msgValidEmail  = '- un e-mail valide';

        var msgWait = 'Veuillez patienter, l\'envoi de votre message est en cours';

    }else{
        //var messageTitle = 'Error';
        var messageAlert = 'Please enter:';


        var msgName  = '- your full name';
        var msgEmail  = '- your e-mail';
        var msgTel  = '- your phone n&deg;';
        var msgValidEmail  = '- a valid e-mail';

        var msgWait = 'Please wait while your message is being sent';
    }


    if (isEmpty(name)) {
        messageAlert = messageAlert + msgName;
        error = true;
    }

    if (isEmpty(email)) {
        messageAlert = messageAlert + msgEmail;
        error = true;
    }

    if(!isEmpty(email) && validateEmail(email)==false){
        messageAlert = messageAlert + msgValidEmail;
        error = true;
    }

    if (isEmpty(tel)) {
        messageAlert = messageAlert +  msgTel;
        error = true;
    }

 
    if(error){

        if(document.getElementById('support_error_tr')){
            document.getElementById('support_error_tr').style.display = 'block';

        }
        if(document.getElementById('support_error')){
            document.getElementById('support_error').innerHTML = '<p style="padding-left:0;">'+ messageAlert +'</p>';

        }
        //return false;
    }
    else{
        if(document.getElementById('support_error_tr')){
            document.getElementById('support_error_tr').style.display = 'block';

        }

        if(document.getElementById('support_error')){
            document.getElementById('support_error').innerHTML = '<p style="text-align:center;">'+msgWait+'</p>';
        }
        //return true;
        sendSupportmail(name,email,tel,company_name);
    }
}
function sendSupportmail(name,email,tel,company_name){
      var queryString = 'ajax_process.php?support=1';
      var stringData = '&support_name='+name+
                       '&support_email='+email+
                       '&support_tel='+tel+
                       '&support_company_name='+company_name;


    jQuery.ajax({
        type: "POST",
        url: queryString,
        data: stringData,
        success: function(msg){
            var response = msg.split('_');

            if (response[1]=='ok'){

                //Clearing fields
                document.getElementById('support_name').value = '';
                document.getElementById('support_email').value= '';
                document.getElementById('support_tel').value= '';
                document.getElementById('support_company_name').value= '';

                //displaying success error
                if(document.getElementById('support_error')){
                    document.getElementById('support_error').style.display = 'block';
                    document.getElementById('support_error').innerHTML = '<p style="text-align:center;">'+response[0]+'</p>';
                }


            }else{
                if(document.getElementById('support_error')){
                    document.getElementById('support_error').style.display = 'block';
                    document.getElementById('support_error').innerHTML = '<p style="text-align:center;">'+response[0]+'</p>';
                }
                return false;
            }
        },
        error: ""
    });
}
function show_popup(name){
    //alert(name);
    close_popup();
    document.getElementById(name).className = 'popupContactShow';
    //centering with css
    centerPopup();
    //load popup
    loadPopup();

}
function close_popup(){
    if(document.getElementById('popupContainer')){
        var div = document.getElementById('popupContainer');
        var oKid = div.firstChild;

        div.className = 'popupContactShow';
        while (oKid){
            oKid.className = 'popupContactHide';
            oKid = oKid.nextSibling;
        }
    }

    return true;
}
function validateCareer(form,lang_id) {
    var name = document.getElementById('career_name').value;
    var other_name = document.getElementById('career_othername').value;
    var email = document.getElementById('career_email').value;
    var tel = document.getElementById('career_tel').value;
    var mob = document.getElementById('career_mob').value;
    var motivation = document.getElementById('career_motiv').value;
    var cv = document.getElementById('career_cv').value;
    var jobId = document.getElementById('career_id').value;
    var captcha = document.getElementById('career_captcha').value;

    var error = false;
    if(lang_id == 2){

       var messageTitle = 'Erreur';
       var messageAlert = 'Veuillez saisir:';


        var msgName  = '- votre nom.';
        var msgOtherName  = '- vos autres noms.';
        var msgEmail  = '- votre e-mail.';
        var msgValidEmail  = '- un e-mail valide.';
        var msgMotiv = '- votre motivation pour ce poste.';
        var msgCV = '- votre cv.';
        var msgGender = '- votre civilit&eacute;.';
        var msgCaptcha = '- le code image.';

        var msgWait = 'Veuillez patienter, l\'envoi de votre application est en cours';

    }else{
        var messageTitle = 'Error';
        var messageAlert = 'Please enter:';


        var msgName  = '- your name.';
        var msgOtherName  = '- your other names.';
        var msgEmail  = '- your e-mail.';
        var msgValidEmail  = '- a valid e-mail.';
        var msgMotiv = '- your motivation for this job.';
        var msgCV = '- your cv.';
        var msgGender = '- your title.';
        var msgCaptcha = '- the image code.';

        var msgWait = 'Please wait while your application is being sent';
    }

    var checked = false;
    var buttons = form.elements.career_title;
    for (var i=0; i<buttons.length; i++)
    {
        if (buttons[i].checked) {
            checked = true;
            var gender = buttons[i].value;
            break;
        }
    }
    if(!checked){
        messageAlert = messageAlert + "<br/>" + msgGender;
        error = true;
    }


    if (isEmpty(name)) {
        messageAlert = messageAlert + "<br/>" + msgName;
        error = true;
    }

    if (isEmpty(other_name)) {
        messageAlert = messageAlert + "<br/>" + msgOtherName;
        error = true;
    }

    if (isEmpty(email)) {
        messageAlert = messageAlert + "<br/>" + msgEmail;
        error = true;
    }

    if(!isEmpty(email) && validateEmail(email)==false){
        messageAlert = messageAlert + "<br/>" + msgValidEmail;
        error = true;
    }

    if (isEmpty(motivation)) {
        messageAlert = messageAlert + "<br/>" + msgMotiv;
        error = true;
    }

    if (isEmpty(cv)) {
        messageAlert = messageAlert + "<br/>" + msgCV;
        error = true;
    }

    if (captcha == "Copier le code image ici" || captcha == "Copy image code here" || isEmpty(captcha)) {
        messageAlert = messageAlert + "<br/>" + msgCaptcha;
        error = true;
    }

    if(error){

        if(document.getElementById('career_error')){
            document.getElementById('career_error').style.display = 'block';
            document.getElementById('career_error').innerHTML = messageAlert;

        }
        //return false;
    }
    else{
        if(document.getElementById('career_error')){
            document.getElementById('career_error').style.display = 'block';
            document.getElementById('career_error').innerHTML = msgWait;
        }

        //return true;
        sendApplication(gender,name,other_name,email,tel,mob,motivation,cv,jobId,captcha);
    }
}
function sendApplication(gender,name,other_name,email,tel,mob,motivation,cv,jobId,captcha){

        var queryString = 'ajax_process.php?career=1&jobID='+jobId;
        var stringData ='&career_title='+gender+
                        '&career_name='+name+
                        '&career_email='+email+
                        '&career_othername='+other_name+
                        '&career_tel='+tel+
                        '&career_mob='+mob+
                        '&career_motiv='+motivation+
                        '&career_cv='+cv+
                        '&career_captcha='+captcha;



    jQuery.ajax({
        type: "POST",
        url: queryString,
        enctype: 'multipart/form-data',
        data: stringData,file: cv,
        success: function(msg){
            var response = msg.split('_');

            if (response[1]=='ok'){

                //Clearing fields
                document.getElementById('career_name').value = '';
                document.getElementById('career_email').value= '';
                document.getElementById('career_othername').value= '';
                document.getElementById('career_tel').value= '';
                document.getElementById('career_mob').value= '';
                document.getElementById('career_motiv').value= '';
                document.getElementById('career_cv').value= '';
                document.getElementById('career_captcha').value= '';
                document.getElementById('upload_status').innerHTML = '';

                //displaying success error
                 if(document.getElementById('career_error')){
                    document.getElementById('career_error').style.display = 'block';
                    document.getElementById('career_error').innerHTML = '<p style="text-align:center;">'+response[0]+'</p>';
                 }


            }else{
                document.getElementById('career_error').style.display = 'block';
                document.getElementById('career_error').innerHTML = '<p style="text-align:center;">'+response[0]+'</p>';

                return false;
            }
        },
        error: ""
    });


}
function ajaxFileUpload()
	{
		//starting setting some animation when the ajax starts and completes
		/*$("#loading")
		.ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
		});*/

		/*
			prepareing ajax file upload
			url: the url of script file handling the uploaded files
                        fileElementId: the file type of input element id and it will be the index of  $_FILES Array()
			dataType: it support json, xml
			secureuri:use secure protocol
			success: call back function when the ajax complete
			error: callback function when the ajax failed

                */
		$.ajaxFileUpload
		(
			{
				url:'ajax_process.php?upload=cv',
				secureuri:false,
				fileElementId:'career_cv',
				dataType: 'json',
				success: function (data, status)
				{
					
                                        if(typeof(data.error) != 'undefined')
					{
						if(data.error != '')
						{
							if(document.getElementById('upload_status')){
                                                            document.getElementById('upload_status').innerHTML = '<img style="height:20px;width:20px;" src="medias/cross.png" /> <font color="red">'+data.error+'</font>';
                                                        }
                                                        if(document.getElementById('career_cv')){
                                                             document.getElementById('career_cv').value = '';
                                                        }
						}else
						{
							if(document.getElementById('upload_status')){
                                                            document.getElementById('upload_status').innerHTML = '<img style="height:20px;width:20px;" src="medias/tick.png" />';
                                                        }
						}
					}
				},
				error: function (data, status, e)
				{
					//alert(e);
				}
			}
		)

		return false;

	}
