a=function(data,mode,module){if(module==null)var module='ajax';var ajax_data=null;if(mode==null||mode!=true)var mode=false;if(window.XMLHttpRequest)xmlhttp=new XMLHttpRequest;else if(window.ActiveXObject)xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");xmlhttp.open('POST','/'+sys_lang+'/'+module+'/',mode);xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){if(xmlhttp.status==200){ajax_data=xmlhttp.responseText;}}};xmlhttp.send(data);return xmlhttp.responseText;};
loadXML=function(txt){try{xmlDoc=new ActiveXObject("Microsoft.XMLDOM");xmlDoc.async="false";xmlDoc.loadXML(txt);return(xmlDoc);}catch(e){try{parser=new DOMParser();xmlDoc=parser.parseFromString(txt,"text/xml");return(xmlDoc);}catch(e){}}return(null)};
trim=function(str, chars) {return ltrim(rtrim(str, chars), chars);};
ltrim=function(str, chars) {chars = chars || "\\s";return str.replace(new RegExp("^[" + chars + "]+", "g"), "");};
rtrim=function(str, chars) {chars = chars || "\\s";return str.replace(new RegExp("[" + chars + "]+$", "g"), "");};
urldecode=function(str){var histogram={},histogram_r={},code=0,str_tmp=[];var ret=str.toString();var replacer=function(search,replace,str){var tmp_arr=[];tmp_arr=str.split(search);return tmp_arr.join(replace);};histogram['!']='%21';histogram['%20']='+';for(replace in histogram){search=histogram[replace];ret=replacer(search,replace,ret);}ret=decodeURIComponent(ret);return ret;};
urlencode=function(str){string=encodeURIComponent(str).replace(/~/g,'%7E');return string.replace(/%20/g,'+');};
isMail=function(str){var filter=/^.+@.+\..{2,3}$/; return filter.test(str)};
opener=function(url,w,h){var l=(screen.width-w)/2;var t=(screen.height-h)/2;window.open(url,'','height='+h+',width='+w+',top='+t+',left='+l+',scrollbars=no,resizable=no,location=no,directories=no,status=no,menubar=no,toolbar=no')};
ga=function(obj,attr){return urldecode(obj.getAttribute(attr))};
array_search=function(needle,haystack,argStrict){var strict=!!argStrict;var key='';for(key in haystack){if((strict&&haystack[key]===needle)||(!strict&&haystack[key]==needle)){return key;}}return false};


$(document).ready(function(){


		$('.email').each(function(){var t=$(this).text().replace('(abols)','@');$(this).text(t).attr('href','mailto:'+t)});
		
		$('.side-menu>ul>li>a').attr("href","#");
		$('.goToNews').attr("href","/"+sys_lang+"/category/news");
		
		$('#screen-name').hide();
		$('.vcard').hide();
		
		//alert(location.hash);

		$("a[rel=galerija]").fancybox();	
		//alert(page);

		if(page == 'home') {
			$('#headerImg').attr('src','/wp-content/header-images/header-1.jpg')
			$('#headerImg').attr('height','165')
			
		} else {
			var randomnumber=Math.floor(Math.random()*headers)
			randomnumber=randomnumber+1
			$('#headerImg').attr('src','/wp-content/header-images/header-'+randomnumber+'.jpg')
			$('#headerImg').attr('height','165')
		}
		
		/* SEND QUESTION FORM ++ */
		
		$('#sendQuestionForm').click(function(e) {
			var classes = $(this).attr('class');
			var isReady = classes.split(' ');
			e.preventDefault();

			if (isReady[2] == 'ready') {
				$('#questionForm').submit();
				//alert("SUBMIT FORM");
			}
		});
		
		$('#resetQuestionForm').click(function(e){
			var answer = confirm("Are you sure?")
			if (answer){
				$("#questionForm")[0].reset();
				
				$('#sendQuestionForm').removeClass('ready'); 
			}
			e.preventDefault();
		});
		
		
		/* SEND QUESTION FORM -- */
		
		
		
		/*
		$('#headerImg').each(function(){
				var $this = $(this);
				$this.stop().animate({
					'opacity':'1.0',
							'height':'160',
							'top':'0px',
							'left':'0px'
				},700);
			});
		*/
		
		$('.list-link').click(function(e) {
			$('.reg-form-block').hide();
			$('.list-link').show();
			var blockId = $(this).attr('rel');
			$('#'+blockId).show();
			$(this).hide();
			e.preventDefault;
		});
		
		$('.closeRegBlock').click(function() {
			var blockId = $(this).attr('rel');
			$('#'+blockId).hide();      
			$('.list-link').show();
		});
		
		$('#sendForm').click(function(e) {
			var classes = $(this).attr('class');
			var isReady = classes.split(' ');
			e.preventDefault();
			if (isReady[2] == 'ready') {
				//alert("SUBMIT FORM");
				$('#regForm').submit();
			}
		});
		
		$('#resetForm').click(function(e){
			var answer = confirm("Are you sure?")
			if (answer){
				$("#regForm")[0].reset();
				callValidator();
			}
			e.preventDefault();
		});
		
		$('select').change(function() {
			var rel = $(this).attr('rel');
			var value = $(this).val();
			$('#'+rel).html(value);
			callValidator();
		});
		
		$('input').keyup(function() {
			callValidator();
		});
		
		$('input[type=radio]').change(function() {
			callValidator();
		});
		
		$('textarea').keyup(function() {
			callValidator();
		});
		
		
		callValidator();
		
		// 1. Personal data save & next	
		$('#savePersonalData').click(function(e){
			var classes = $(this).attr('class');
			var isReady = classes.split(' ');
			e.preventDefault();
			if (isReady[1] == 'ready') {
				$('#personal-data').hide(); // closes personal data block
				$('.list-link').show(); // show links of all blocks
				
				$('.list-link[rel=marital-status]').hide(); // hides next block link
				$('#marital-status').show(); // opens next block
			}
		}); 
		
		
		// 2. Marital data save & next	
		$('#saveMaritalData').click(function(e){
			var classes = $(this).attr('class');
			var isReady = classes.split(' ');
			e.preventDefault();
			if (isReady[1] == 'ready') {
				$('#marital-status').hide(); // closes marital data block
				$('.list-link').show(); // show links of all blocks
				
				$('.list-link[rel=children]').hide(); // hides next block link
				$('#children').show(); // opens next block
			}
		}); 
		
		
		// 3. Children data save & next	
		$('#saveChildData').click(function(e){
			var classes = $(this).attr('class');
			var isReady = classes.split(' ');
			e.preventDefault();
			if (isReady[1] == 'ready') {
				$('#children').hide(); // closes children data block
				$('.list-link').show(); // show links of all blocks
				
				$('.list-link[rel=education]').hide(); // hides next block link
				$('#education').show(); // opens next block
			}
		}); 
		
		
		// 4. Education data save & next	
		$('#saveEducationData').click(function(e){
			var classes = $(this).attr('class');
			var isReady = classes.split(' ');
			e.preventDefault();
			if (isReady[1] == 'ready') {
				$('#education').hide(); // closes children data block
				$('.list-link').show(); // show links of all blocks
				
				$('.list-link[rel=knowledge]').hide(); // hides next block link
				$('#knowledge').show(); // opens next block
			}
		}); 
		
		
		// 5. Language knowledge data save & next	
		$('#saveKnowledgeData').click(function(e){
			var classes = $(this).attr('class');
			var isReady = classes.split(' ');
			e.preventDefault();
			if (isReady[1] == 'ready') {
				$('#knowledge').hide(); // closes knowledge data block
				$('.list-link').show(); // show links of all blocks
				
				$('.list-link[rel=experience]').hide(); // hides next block link
				$('#experience').show(); // opens next block
			}
		}); 
		
		
		// 6. Experience data save & next	
		$('#saveExperienceData').click(function(e){
			var classes = $(this).attr('class');
			var isReady = classes.split(' ');
			e.preventDefault();
			if (isReady[1] == 'ready') {
				$('#experience').hide(); // closes experience data block
				$('.list-link').show(); // show links of all blocks
				
				$('.list-link[rel=more]').hide(); // hides next block link
				$('#more').show(); // opens next block
			}
		}); 
		
		
		// 7. More data save & next	
		$('#saveMoreData').click(function(e){
			var classes = $(this).attr('class');
			var isReady = classes.split(' ');
			e.preventDefault();
			if (isReady[1] == 'ready') {
				$('#more').hide(); // closes more data block
				$('.list-link').show(); // show links of all blocks
				
				$('.list-link[rel=spouse-personal-data]').hide(); // hides next block link
				$('#spouse-personal-data').show(); // opens next block
			}
		}); 
		
		
		// 8. Spouse personal data save & next	
		$('#saveSpousePersonalData').click(function(e){
			var classes = $(this).attr('class');
			var isReady = classes.split(' ');
			e.preventDefault();
			if (isReady[1] == 'ready') {
				$('#spouse-personal-data').hide(); // closes spouse personal data block
				$('.list-link').show(); // show links of all blocks
				
				$('.list-link[rel=spouse-education]').hide(); // hides next block link
				$('#spouse-education').show(); // opens next block
			}
		}); 
		
		
		// 9. Spouse education data save & next	
		$('#saveSpouseEducationData').click(function(e){
			var classes = $(this).attr('class');
			var isReady = classes.split(' ');
			e.preventDefault();
			if (isReady[1] == 'ready') {
				$('#spouse-education').hide(); // closes spouse education data block
				$('.list-link').show(); // show links of all blocks
				
				$('.list-link[rel=spouse-lang-knwoledge]').hide(); // hides next block link
				$('#spouse-lang-knwoledge').show(); // opens next block
			}
		}); 
		
		
		// 10. Spouse language knowledge data save & next	
		$('#saveSpouseKnowledgeData').click(function(e){
			var classes = $(this).attr('class');
			var isReady = classes.split(' ');
			e.preventDefault();
			if (isReady[1] == 'ready') {
				$('#spouse-lang-knwoledge').hide(); // closes spouse languag data block
				$('.list-link').show(); // show links of all blocks
				
				$('.list-link[rel=spouse-experience]').hide(); // hides next block link
				$('#spouse-experience').show(); // opens next block
			}
		}); 
		
		
		// 11. Experience data save & next	
		$('#saveSpouseExperienceData').click(function(e){
			var classes = $(this).attr('class');
			var isReady = classes.split(' ');
			e.preventDefault();
			if (isReady[1] == 'ready') {
				$('#spouse-experience').hide(); // closes spouse experience data block
				$('.list-link').show(); // show links of all blocks
			}
		}); 
		
		
		
	});
	
	
	callValidator = function() {
		
		var error = "";
		var value = "";
		
		
		// Question form 
		
		error = false;
		$('input[name=questioner-name],input[name=questioner-email],input[name=questioner-phone],#questioner-message').each(function(){
			value = $(this).attr('value');
			//alert(value);
			if (value == '') { error = true; }
		});
		
		if (error == false) {
			$('#sendQuestionForm').addClass('ready'); 
		}
		
		
		
		
		// 1. Personal data validator	
		error = false;
		$('input[name=lastname],input[name=firstname],select[name=birth-day],select[name=birth-year],select[name=nationality],input[name=address],input[name=email],input[name=fax]').each(function(){
			value = $(this).attr('value');
			if (value == '') { error = true; }
		});
		
		if (error == false) { 
			$('#savePersonalData').addClass('ready'); 
			$('.list-link[rel=personal-data]').addClass('list-link-done'); 
		} else {
			$('#savePersonalData').removeClass('ready'); 
			$('.list-link[rel=personal-data]').removeClass('list-link-done'); 
			$('#sendForm').removeClass('ready'); 
		}
		
		
		// 2. Martial status data validator			
		error = false;
		var spouse = false;
		$('input[name=married],input[name=intend-marry]').each(function(){
			value = $(this).attr('checked');
			if($(this).attr('name')=='married'){
				var ch=$('input[name=married]:checked');
				if ($(ch).val()=='yes'){
					spouse = true;
					if($('input[name=married-since]').val() == '') { error = true; }
				} else if($(ch).val()=='no') {  /*spouse = false; */} else { error = true; }
			}
			if($(this).attr('name')=='intend-marry'){
				var ch=$('input[name=intend-marry]:checked');
				if ($(ch).val()=='yes'){
					spouse = true;
					if($('input[name=intend-marry-when]').val() == '') { error = true; }
				} else if($(ch).val()=='no') { /*error = false;*/ }  else { error = true; }
			}	
		});
		
		if (error == false) { 
			$('#saveMaritalData').addClass('ready'); 
			$('.list-link[rel=marital-status]').addClass('list-link-done'); 
		} else {
			$('#saveMaritalData').removeClass('ready'); 
			$('.list-link[rel=marital-status]').removeClass('list-link-done'); 
			$('#sendForm').removeClass('ready'); 
		}
		
		
		// 3. Children data validator	
		error = false;
		
		var ch=$('input[name=have_children]:checked');
		if ($(ch).val()=='yes') {
			$('input[name=child-name1],select[name=child-kindship1],select[name=child-birth-day1],select[name=child-birth-month1],select[name=child-birth-year1]').each(function(){
				value = $(this).attr('value');
				if (value == '') { error = true; }
			});			
		} else if($(ch).val()=='no') { error = false; } else { error = true;}
	

		if (error == false) { 
			$('#saveChildData').addClass('ready'); 
			$('.list-link[rel=children]').addClass('list-link-done'); 
		} else {
			$('#saveChildData').removeClass('ready'); 
			$('.list-link[rel=children]').removeClass('list-link-done'); 
			$('#sendForm').removeClass('ready'); 
		}
		
		// 4. Education data validator	
		error = false;
		$('input[name=duration-start-month1],input[name=duration-start-year1],input[name=duration-finish-month1],input[name=duration-finish-year1],input[name=school-name1],input[name=study-field1],input[name=study-speciality1]').each(function(){
			value = $(this).attr('value');
			if (value == '') { error = true; }
		});
		
		if (error == false) { 
			$('#saveEducationData').addClass('ready'); 
			$('.list-link[rel=education]').addClass('list-link-done'); 
		} else {
			$('#saveEducationData').removeClass('ready'); 
			$('.list-link[rel=education]').removeClass('list-link-done'); 
			$('#sendForm').removeClass('ready'); 
		}
		
		
		// 5. Language knowledge data validator	
		error = false;
		
		$('select[name=english-reading-level],select[name=english-letter-level],select[name=english-speaking-level],select[name=english-listening-level]').each(function(){
			value = $(this).attr('value');
			if (value == '') { error = true; }
		});
		
		if(error == true) {
			error = false;
			$('select[name=french-reading-level],select[name=french-letter-level],select[name=french-speaking-level],select[name=french-listening-level]').each(function(){
				value = $(this).attr('value');
				if (value == '') { error = true; }
			});
		}
		
		if (error == false) { 
			$('#saveKnowledgeData').addClass('ready'); 
			$('.list-link[rel=knowledge]').addClass('list-link-done'); 
		} else {
			$('#saveKnowledgeData').removeClass('ready'); 
			$('.list-link[rel=knowledge]').removeClass('list-link-done'); 
			$('#sendForm').removeClass('ready'); 
		}
		
		
		// 6. Experience data validator	
		error = false;
		$('input[name=experience-start-month1],input[name=experience-start-year1],input[name=experience-finish-month1],input[name=experience-finish-year1],input[name=experience-school-name1],input[name=experience-study-field1]').each(function(){
			value = $(this).attr('value');
			if (value == '') { error = true; }
		});
		
		if (error == false) { 
			$('#saveExperienceData').addClass('ready'); 
			$('.list-link[rel=experience]').addClass('list-link-done'); 
		} else {
			$('#saveExperienceData').removeClass('ready'); 
			$('.list-link[rel=experience]').removeClass('list-link-done'); 
			$('#sendForm').removeClass('ready'); 
		}
		
		
		// 7. More data validator	
		error = false;
		var notes = false;
		
		$('input[name=got-relatives],input[name=got-employer],input[name=spouse-studied],input[name=health-problems],input[name=criminal-liability],input[name=deported],input[name=have-visited],input[name=got-imigrant-visa]').each(function(){
			
			/*
			$('input[name=relative-kindship]').each(function(){
				value = $(this).attr('value');
				if (value == '') { error = true; }
			});
			*/	
			
			if($(this).attr('name')=='got-relatives'){
				var ch=$('input[name=got-relatives]:checked');
				if(($(ch).val()!='yes') && ($(ch).val()!='no')) { error = true; }
				if($(ch).val()=='yes') { notes = true; }
			}
			
			if($(this).attr('name')=='got-employer'){
				var ch=$('input[name=got-employer]:checked');
				if(($(ch).val()!='yes') && ($(ch).val()!='no')) { error = true; }
				if($(ch).val() =='yes') { notes = true; }
			}
			if($(this).attr('name')=='spouse-studied'){
				var ch=$('input[name=spouse-studied]:checked');
				if(($(ch).val()!='yes') && ($(ch).val()!='no')) { error = true; }
				if($(ch).val() =='yes') { notes = true; }
			}
			if($(this).attr('name')=='health-problems'){
				var ch=$('input[name=health-problems]:checked');
				if(($(ch).val()!='yes') && ($(ch).val()!='no')) { error = true; }
				if($(ch).val() =='yes') { notes = true; }
			}
			if($(this).attr('name')=='criminal-liability'){
				var ch=$('input[name=criminal-liability]:checked');
				if(($(ch).val()!='yes') && ($(ch).val()!='no')) { error = true; }
				if($(ch).val() =='yes') { notes = true; }
			}
			if($(this).attr('name')=='deported'){
				var ch=$('input[name=deported]:checked');
				if(($(ch).val()!='yes') && ($(ch).val()!='no')) { error = true; }
				if($(ch).val() =='yes') { notes = true; }
			}
			if($(this).attr('name')=='have-visited'){
				var ch=$('input[name=have-visited]:checked');
				if(($(ch).val()!='yes') && ($(ch).val()!='no')) { error = true; }
				if($(ch).val() =='yes') { notes = true; }
			}
			if($(this).attr('name')=='got-imigrant-visa'){
				var ch=$('input[name=got-imigrant-visa]:checked');
				if(($(ch).val()!='yes') && ($(ch).val()!='no')) { error = true; }
				if($(ch).val() =='yes') { notes = true; }
			}	
			
		});
		
			
		if (notes == true) {
			
			var more_info = $('textarea[name=more-additional-details]').val();
			if (more_info == '') { error = true; }
		}
		
		if (error == false) { 
			$('#saveMoreData').addClass('ready'); 
			$('.list-link[rel=more]').addClass('list-link-done'); 
		} else {
			$('#saveMoreData').removeClass('ready'); 
			$('.list-link[rel=more]').removeClass('list-link-done'); 
			$('#sendForm').removeClass('ready'); 
		}
		
		//alert(spouse);
		//alert(error);
		
		if (spouse == true)  {
		// 8. Spouse personal data validator	
		error = false;
		$('input[name=spouse-lastname],input[name=spouse-firstname],select[name=spouse-birth-day],select[name=spouse-birth-year],input[name=spouse-nationality]').each(function(){
			value = $(this).attr('value');
			if (value == '') { error = true; }
		});
		
		if (error == false) { 
			$('#saveSpousePersonalData').addClass('ready'); 
			$('.list-link[rel=spouse-personal-data]').addClass('list-link-done'); 
		} else {
			$('#saveSpousePersonalData').removeClass('ready'); 
			$('.list-link[rel=spouse-personal-data]').removeClass('list-link-done');
			$('#sendForm').removeClass('ready'); 			
		}
		
		
		// 9. Spouse education data validator	
		error = false;
		$('input[name=spouse-duration-start-month1],input[name=spouse-duration-start-year1],input[name=spouse-duration-finish-month1],input[name=spouse-duration-finish-year1],input[name=spouse-school-name1],input[name=spouse-study-field1],input[name=spouse-study-speciality1]').each(function(){
			value = $(this).attr('value');
			if (value == '') { error = true; }
		});
		
		if (error == false) { 
			$('#saveSpouseEducationData').addClass('ready'); 
			$('.list-link[rel=spouse-education]').addClass('list-link-done'); 
		} else {
			$('#saveSpouseEducationData').removeClass('ready'); 
			$('.list-link[rel=spouse-education]').removeClass('list-link-done'); 
			$('#sendForm').removeClass('ready'); 
		}
		
		
		// 10. Spouse language knowledge data validator	
		error = false;
		
		$('select[name=spouse-english-reading-level],select[name=spouse-english-letter-level],select[name=spouse-english-speaking-level],select[name=spouse-english-listening-level]').each(function(){
			value = $(this).attr('value');
			if (value == '') { error = true; }
		});
		
		if(error == true) {
			error = false;
			$('select[name=spouse-french-reading-level],select[name=spouse-french-letter-level],select[name=spouse-french-speaking-level],select[name=spouse-french-listening-level]').each(function(){
				value = $(this).attr('value');
				if (value == '') { error = true; }
			});
		}
		
		if (error == false) { 
			$('#saveSpouseKnowledgeData').addClass('ready'); 
			$('.list-link[rel=spouse-lang-knwoledge]').addClass('list-link-done'); 
		} else {
			$('#saveSpouseKnowledgeData').removeClass('ready'); 
			$('.list-link[rel=spouse-lang-knwoledge]').removeClass('list-link-done'); 
			$('#sendForm').removeClass('ready'); 
		}
		
		
		// 11. Spouse experience data validator	
		error = false;
		$('input[name=spouse-experience-start-month1],input[name=spouse-experience-start-year1],input[name=spouse-experience-finish-month1],input[name=spouse-experience-finish-year1],input[name=spouse-experience-school-name1],input[name=spouse-experience-study-field1]').each(function(){
			value = $(this).attr('value');
			if (value == '') { error = true; }
		});
		
		
		if (error == false) { 
			$('#saveSpouseExperienceData').addClass('ready'); 
			$('.list-link[rel=spouse-experience]').addClass('list-link-done'); 
		} else {
			$('#saveSpouseExperienceData').removeClass('ready'); 
			$('.list-link[rel=spouse-experience]').removeClass('list-link-done'); 
			$('#sendForm').removeClass('ready'); 
		}
		
		var filledBlocks = $('.list-link-done').size();
		if (filledBlocks == '11') { $('#sendForm').addClass('ready'); }
		}  else {
			var filledBlocks = $('.list-link-done').size();
			if (filledBlocks == '7') { $('#sendForm').addClass('ready'); }
		}
		
		
		
}

/* antispam ++ */
	if(page == 'ask-us-a-question'){
		var nmbr=0;
		var intg=setInterval(function(){if(!key[nmbr]){clearInterval(intg)}else{$('input[name=antispambot]').val($('input[name=antispambot]').val()+key[nmbr]);nmbr++}},500)
	}
/* antispam -- */
	
