var errCode = new Array();
 	errCode["fa"] = new Array();
	errCode["en"] = new Array();
	
	errCode["fa"]["10"]= 'لطفاً اطلاعات خواسته شده را تکمیل نمائید';
	errCode['en']["10"]= 'Please fill the informations';
	errCode["fa"]["spliter"]='، ';
	errCode["en"]["spliter"]=', ';
	errCode["fa"]["req"]=' ضروری است ! ';
	errCode["en"]["req"]=' is required !';
	errCode["fa"]["captcha"]=' کد امنیتی را اشتباه وارد کرده اید ';
	errCode["en"]["captcha"]=' The Security Code is wrong';
	errCode["fa"]["key"]=' کلمه یا کلمات کلیدی شغل ';
	errCode["en"]["key"]=' Job Keyword(s) ';
	errCode["fa"]["name"]='نام';
	errCode["en"]["name"]='Name';
	errCode["fa"]["lname"]='نام خانوادگی';
	errCode["fa"]["sex"]='جنسیت';
	errCode["en"]["sex"]='Sex';
	errCode["fa"]["city"]='شهر';
	errCode["en"]["city"]='City';
	errCode["en"]["lname"]='LastName';
	errCode["fa"]["company"]='نام شرکت';
	errCode["en"]["company"]='Company';
	errCode["fa"]["tel"]='تلفن';
	errCode["en"]["tel"]='Tel';
	errCode["fa"]["email"]='ایمیل';
	errCode["en"]["email"]='Email';
	errCode["fa"]["fav_job"]='گروه شغلی';
	errCode["en"]["fav_job"]='Employment Category';
	errCode["fa"]["school"]='محل تحصیل';
	errCode["en"]["school"]='School';
	errCode["fa"]["major"]='رشته تحصیلی';
	errCode["en"]["major"]='Major';
	errCode["fa"]["degree"]='مقطع تحصیلی';
	errCode["en"]["degree"]='Degree Level';
	errCode["fa"]["pass"]='رمز عبور';
	errCode["en"]["pass"]='Passowrd';
	errCode["en"]["RePASS"]='First Password dose not match with second password';
	errCode["fa"]["RePASS"]='رمز عبور اولی با تکرار آن همخوانی ندارد';
	errCode["fa"]["notFound"]='متاسفیم! چنین ایمیلی در سیستم ما ثبت نشده است';
	errCode["en"]["notFound"]='Sorry! This email in not registred on our website';
	errCode["fa"]["emptyE"]='لطفاً ایمیل خود را در فرمت صحیح وارد نمائید';
	errCode["en"]["emptyE"]='Please enter a valid email';
	errCode["fa"]["emailF"]='فرمت ایمیل شما صحیح نمی باشد';
	errCode["en"]["emailF"]='Your email is not valid';
	errCode["fa"]["fail"]='خطلا در سیستم! لطفاً در زمان دیگری اقدام نمائید';
	errCode["en"]["fail"]='Registration Failed! Please try later';
	errCode["fa"]["dup"]='این ایمیل قبلاً در سیستم ما ثبت شده است!';
	errCode["en"]["dup"]='The email is already exist!';
	errCode["fa"]["failLogin"]='متاسفیم! عملیات ورود به سایت ناموفق بود';
	errCode["en"]["failLogin"]='Sorry! Please try again';
	errCode["fa"]["Fill"]='لطفاً فیلد هایی را که با علامت * مشخص شده اند را بطور کامل تکمیل نمائید';
	errCode["en"]["Fill"]='Please fill the fileds with Star sign';
	errCode["fa"]["success"]='عملیات با موفقیت انجام شد';
	errCode["en"]["success"]='Successfully Updated';
	errCode["fa"]["userBlock"]='حساب شما قفل شده است، لطفاً با مدیریت سایت برای اطلاعات بیشتر تماس بگیرید';
	errCode["en"]["userBlock"]='Your account has been suspend, for more information please contact to administrator';
	
	errCode["fa"]["usedCoupon"]='این کوپن کد قبلا استفاده شده است. لطفاً از کد جدیدی استفاده نمائید و یا از طریق پی پل وجه آگهی خود را پرداخت نمائید';
	errCode["en"]["usedCoupon"]='This coupon has been used. Please enter another coupon number or use your PayPal.';
	
	errCode["fa"]["invalidCoupon"]='کد کوپن شما معتبر نمی باشد. لطفاً کد را تصحیح کنید';
	errCode["en"]["invalidCoupon"]='Your coupon code is not valid, please correct your code.';
	
	
function confirm_del(id)
{
	if(confirm('Are you sure to delete this item?'))
		window.location='include/process.php?task=delAD&adID='+id;
	else
	return false;
}

function increaseFontSize() {
	var currentFontSize = $('#wrapper').css('font-size');
	var currentFontSizeNum = parseFloat(currentFontSize, 10);
	if (currentFontSizeNum < 17) {
		var newFontSize = currentFontSizeNum * 1.2;
		$('#wrapper').css('font-size', newFontSize);
		
		var currentFontSize = $('#footer').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum * 1.2;
		$('#footer').css('font-size', newFontSize);
		
		var currentFontSize = $('.nav').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum * 1.2;
		$('.nav a').css('font-size', newFontSize);
	}
	
}

function decreaseFontSize() {
	var currentFontSize = $('#wrapper').css('font-size');
	var currentFontSizeNum = parseFloat(currentFontSize, 10);
	//alert(currentFontSizeNum);
	if (currentFontSizeNum > 10) {
		var newFontSize = currentFontSizeNum * 0.8;
		$('#wrapper').css('font-size', newFontSize);
		
		var currentFontSize = $('#footer').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum * 0.8;
		$('#footer').css('font-size', newFontSize);
		
		var currentFontSize = $('.nav').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum * 0.8;
		$('.nav a').css('font-size', newFontSize);
	}
}


function validateEmail(email){

	var at = email.lastIndexOf("@");

	if (at < 1 || (at + 1) === email.length)
		return false;

	if (/(\.{2,})/.test(email))
		return false;

	var local = email.substring(0, at);
	var domain = email.substring(at + 1);

	if (local.length < 1 || local.length > 64 || domain.length < 4 || domain.length > 255)
		return false;

	if (/(^\.|\.$)/.test(local) || /(^\.|\.$)/.test(domain))
		return false;

	if (!/^"(.+)"$/.test(local)) {
		if (!/^[-a-zA-Z0-9!#$%*\/?|^{}`~&'+=_\.]*$/.test(local))
			return false;
	}

	if (!/^[-a-zA-Z0-9\.]*$/.test(domain) || domain.indexOf(".") === -1)
		return false;	

	return true;
}
	
function showError(errMsg, errHolder){
	errHolder.fadeOut(200, function () {
		errHolder.empty()
				 .html(errMsg)
		         .fadeIn('slow')
				 .animate({opacity: 1.0}, 2000)
				 .fadeOut('slow');
	});
}

function regPost(current,next){
	
	var lang = $('#langID').val();
	
	$(".resultTxt").empty();
	$(".resultTxt").hide();
	$('.loading').show();
	
	$.ajax({
		type: "POST",
		url: "include/process.php",
		data: $(".formHolder form").serialize(),
		success: function(msg){
			if(msg=='y'){
				$('.loading').hide();
				$(".resultTxt").empty();
				current.fadeOut('normal',function(){
					next.fadeIn('normal');
				});
			}else{
				if(msg=='D'){
					var str=errCode[lang]["dup"];
				}else{
					var str=errCode[lang]["fail"];
				}
				$(".loading").fadeOut('fast',function(){
					$(".resultTxt").fadeIn('slow');
					$(".resultTxt").html(str);
				});
			}
			
		}
	});
		
}


function generalPostI(redirect){
	
	var lang = $('#langID').val();
	
	$(".resultTxt").hide();
	$('.loading').show();
	$.ajax({
			type: "POST",
			url: "include/process.php",
			data: $(".membersFormHolder form").serialize(),
			success: function(msg){
				if(msg=='yes'){
					window.location='?page='+redirect;
				}else{
					if(msg=='F'){
						var str=errCode[lang]["Fill"];
					}else{
						var str=errCode[lang]["fail"];
					}
					$(".loading").fadeOut('fast',function(){
						$(".resultTxt").fadeIn('slow');
						$(".resultTxt").html(str);
					});	
				}
				
			}
		});
		
}

function generalPostII(){
	
	var lang = $('#langID').val();
	
	$(".resultTxt").hide();
	$('.loading').show();
	$.ajax({
			type: "POST",
			url: "include/process.php",
			data: $(".membersFormHolder form").serialize(),
			success: function(msg){
					if(msg=='yes'){
						var str=errCode[lang]["success"];
					}else if(msg=='F'){
						var str=errCode[lang]["Fill"];
					}else if(msg=='P'){
						var str=errCode[lang]["RePASS"];
					}else{
						var str=errCode[lang]["fail"];
					}
					$(".loading").fadeOut('fast',function(){
						$(".resultTxt").fadeIn('slow');
						$(".resultTxt").html(str);
					});	
				
			}
		});
		
}

function goto_search_st1(){
	$('#searchSt1').fadeOut('normal',function(){
			var temp=$('#stateID').val();
			var temp2=$('#countryID').val();
			if (temp!=''){
				$("#countrySpin").show();
				$('#searchSt2').fadeIn('normal', function(){
					$(".countryT").html($('#countryID > option[value="'+temp2+'"]').text());
					$(".cityT").html($('#stateID > option[value="'+temp+'"]').text());
					$.post("./include/process.php", {task: "search_criteria_ST2", sID: ""+ temp +"" }, function(data) {
						$("#jobT").html(data);
					});
					$.post("./include/process.php", {task: "show_categories", sID: ""+ temp +"" }, function(data) {
						$("#job_catID").html(data);
					});
				});
				
			}
			
		});
}


function goto_searchJob2(){
	var lang = $('#langID').val();
	var keys=$('#tags').val();
	var state=$('#stateID').val();
	if (!keys) {
		stMessage = errCode[lang]['key']+errCode[lang]['req'];
		alert(stMessage);
	}else{
		var data= 'tags='+keys+'&state='+state;
		window.location='?page=search_job_result&sector=job_search2&'+data;
	}
}

function goto_erGo3Step(){
	
	$("#resultHolderER2 .resultTxt").empty();
	$("#resultHolderER2 .resultTxt").hide();
	$('#resultHolderER2 .loading').hide();

	var lang = $('#langID').val();
	stMessage = '';
	
	if (!$('#er_name').val()) {
		stMessage += errCode[lang]['name']+errCode[lang]['spliter'];
	}

	if (!$('#er_company').val()) {
		stMessage += errCode[lang]['company']+errCode[lang]['spliter'];
	}
	
	if (!$('#er_tel').val()) {
		stMessage += errCode[lang]['tel']+errCode[lang]['spliter'];
	}

	if (stMessage.length > 0) {
		var msgHolder = $('#resultHolderER2 .resultTxt');
		stMessage+=errCode[lang]['req'];
		showError(stMessage, msgHolder);
	}
	else {
		$("#resultHolderER2 .resultTxt").empty();
		$("#resultHolderER2 .resultTxt").hide();
		$('#regStep2').fadeOut('normal',function(){
			$('#regStep3').fadeIn('normal');
		});
	}
	
}

function goto_reg_er(){
		
		$("#resultHolderER3 .resultTxt").empty();
		$("#resultHolderER3 .resultTxt").hide();
		$('#resultHolderER3 .loading').hide();
		
		var msgHolder = $('#resultHolderER3 .resultTxt');
		var lang = $('#langID').val();
		stMessage = '';
		
		if (!$('#er_email').val()) {
			stMessage += errCode[lang]['email']+errCode[lang]['spliter'];
		}

		if (!$('#er_pass').val()) {
			stMessage += errCode[lang]['pass']+errCode[lang]['spliter'];
		}
		
		if (stMessage.length > 0) {
			stMessage+=errCode[lang]['req'];
			showError(stMessage, msgHolder);
		}
		else {
			if(validateEmail($('#er_email').val())){
				var curr = $('#regStep3');
				var next = $('#regStep4');
				regPost(curr,next);
			}else{
				stMessage=errCode[lang]['emailF'];
				showError(stMessage, msgHolder);
			}
			
		}
}

function goto_login(){
	
	var lang = $('#langID').val();
	
	$(".resultTxt").hide();
	$('.loading').show();
	$.ajax({
			type: "POST",
			url: "include/process.php",
			data: $(".formHolder form").serialize(),
			success: function(msg){
				if(msg=='yes'){
					window.location='?page=member_panel';
				}else{
					if(msg=='block'){
						var str=errCode[lang]["userBlock"];
					}else{
						var str=errCode[lang]["failLogin"];
					}
					$(".loading").fadeOut('fast',function(){
						$(".resultTxt").fadeIn('slow');
						$(".resultTxt").html(str);
					});	
				}
				
			}
		});
		
}

$(document).ready(function() {
	
	var img = ['Pen.png', 'Pen 3.png', 'submit_h.gif'];
	$(img).each(function () {
		var i = new Image();
		i.src = 'images/' + this;
	});
	
	$(".passForm form").submit(function(e) {

		e.preventDefault();

		var lang = $('#langID').val();
	
		$(".resultTxt").hide();
		$('.loading').show();
		$.ajax({
				type: "POST",
				url: "include/process.php",
				data: $(".passForm form").serialize(),
				success: function(msg){
					if(msg=='yes'){
						window.location='?page=success_recover';
					}else{
						if(msg=='empty'){
							var str=errCode[lang]["emptyE"];
						}else if(msg=='notFound'){
							var str=errCode[lang]["notFound"];
						}else{
							var str=errCode[lang]["failLogin"];
						}
						$(".loading").fadeOut('fast',function(){
							$(".resultTxt").fadeIn('slow');
							$(".resultTxt").html(str);
						});	
					}
					
				}
			});
		  
	    return false;
		  
    });
	
	
	$("#contact_form_holder form").submit(function(e) {

		e.preventDefault();

		var lang = $('#langID').val();
	
		$(".resultTxt").hide();
		$('.loading').show();
		$.ajax({
				type: "POST",
				url: "include/process.php",
				data: $("#contact_form_holder form").serialize(),
				success: function(msg){
					if(msg=='yes'){
						window.location='?page=success_contact';
					}else{
						if(msg=='empty'){
							var str=errCode[lang]["10"];
						}else if(msg=='captcha'){
							var str=errCode[lang]["captcha"];
							document.getElementById('capImg').src = 'include/securimage_show.php?sid=' + Math.random();
							$('#capthca').val('');
						}else{
							var str=errCode[lang]["fail"];
						}
						$(".loading").fadeOut('fast',function(){
							$(".resultTxt").fadeIn('slow');
							$(".resultTxt").html(str);
						});	
					}
					
				}
			});
		  
	    return false;
		  
    });
	
	$('#font_i').click(function(){
		increaseFontSize();
	});
	
	$('#font_d').click(function(){
		decreaseFontSize();
	});
	
	$(".arrow").hover(function(){
		$(this).fadeTo("normal", 0.5); 
	},function(){
   		$(this).fadeTo("normal", 1.0); 
	});
	
	$(".jobHolder").hover(function(){
		$(this).addClass("jobHolderO");
	},function(){
   		$(this).removeClass("jobHolderO"); 
	});
	
	$(".cel").hover(function(){
		$(this).addClass("celHover");
	},function(){
   		$(this).removeClass("celHover"); 
	});
	
	$(".celBHolder").hover(function(){
		$(this).addClass("celBHover");
	},function(){
   		$(this).removeClass("celBHover"); 
	});
	
	$(".searchT").hover(function(){
		$(this).addClass("searchTHover");
	},function(){
   		$(this).removeClass("searchTHover"); 
	});
	
	
	/*$("#login_form").submit(function(){
		$("#loginBTN").trigger('click');
		return false;
	});*/
	

	
	$("#emailLog").keypress(function (e) {
      if (e.which == 13) {
      	  goto_login();
    	}
	});
	
	$("#passLog").keypress(function (e) {
      if (e.which == 13) {
      	  goto_login();
    	}
	});
		
	$("#loginBTN").click( function(e) {
		e.preventDefault();
		goto_login();
	} ); 
	
	$("#couponHolder form").submit(function(e){
		
		e.preventDefault();
		var lang = $('#langID').val();
		$(".resultTxt").hide();
		$('.loading').show();
		$.ajax({
				type: "POST",
				url: "include/process.php",
				data: $(".formHolder form").serialize(),
				success: function(msg){
					if(msg=='yes'){
						window.location='?page=success_payment';
					}else{
						if(msg=='usedCoupon'){
							var str=errCode[lang]["usedCoupon"];
						}else if(msg=='invalidCoupon'){
							var str=errCode[lang]["invalidCoupon"];
						}else{
							var str=errCode[lang]["fail"];
						}
						$(".loading").fadeOut('fast',function(){
							$(".resultTxt").fadeIn('slow');
							$(".resultTxt").html(str);
						});	
					}
					
				}
			});
		return false;
	});
	
	$('#voting').change(function(){
		var vote=$('#voting').val();
		var lang = $('#langID').val();
		var coid=$('#coID').val();
		if (vote!=''){
			$("#factor").fadeOut('fast', function(){
				$("#load").fadeIn();
				$.post("./include/process.php", {task: "voting", vote: ""+ vote +"", company: ""+ coid +""}, 
					function(data) {
						$("#voteResult").html(data);
						$("#load").fadeOut('normal', function(){
							$("#factor").fadeIn('fast');
						});
				});	
			});
			
		}
	});
		
	$('#ads_period').change(function(){
		var count=$('#ads_period').val();
		var adid=$('#adID').val();
		var coid=$('#coID').val();
		var lang = $('#langID').val();
		if (count!=''){
			$("#factor").fadeOut('fast', function(){
				$("#load").fadeIn();
				$.post("./include/process.php", {task: "update_week", week: ""+ count +"", company: ""+ coid +"", ads: ""+ adid +"" }, 
					function(data) {
						$("#paypalBottun").attr('href', 'include/paypal.gateway.php?total='+count+'&tmpID='+adid+'&pType=newAD');
						$("#item_price_1").val(count);
						if(lang=='en'){
							var tmpCount='$'+count;
						}else{
							var tmpCount=count+'$';
						}
						$(".totalP").html(tmpCount);
						$("#load").fadeOut('normal', function(){
							$("#factor").fadeIn('fast');
						});
				});	
			});
			
		}
	});
	
	
	$('#ads_period2').change(function(){
		var count=$('#ads_period2').val();
		var adid=$('#adID').val();
		var coid=$('#coID').val();
		var exp=$('#exp').val();
		if(exp=='yes'){
			$type='renewADExp';
		}else{
			$type='renewAD';
		} 
		if (count!=''){
			$("#factor").fadeOut('fast', function(){
				$("#load").fadeIn();
				$("#paypalBottun").attr('href', 'include/paypal.gateway.php?total='+count+'&tmpID='+adid+'&pType='+$type);
				$("#item_price_1").val(count);
				$(".totalP").html(count);
				$("#load").fadeOut('normal', function(){
					$("#factor").fadeIn('fast');
				});
			});
			
		}
	});
	
	
	$('#countryID').change(function(){
		var temp=$('#countryID').val();
		if (temp!=''){
			$("#stateID").html('');
			$("#countrySpin").show();
			$.post("./include/process.php", {task: "show_states", cID: ""+ temp +"" }, function(data) {
				$("#stateID").html(data);
				$("#countrySpin").hide();
			});
		}
	});
	
	$('#job_lang').change(function(e){
		var activeLang=$('#job_lang').val();
		if(activeLang=='EN'){
			FarsiType.Type = false;
			$('#FarsiType_button_1').val('EN');
			$('#FarsiType_button_1').attr('title', 'Change lang to persian');
			$('#FarsiType_button_2').val('EN');
			$('#FarsiType_button_2').attr('title', 'Change lang to persian');
			$('.changableInput').css('align', 'left');
			$('.changableInput').css('direction', 'ltr');
			$('.changableInput').css('text-align', 'left');
		}
		else{
			FarsiType.Type = true;
			$('#FarsiType_button_1').val('FA');
			$('#FarsiType_button_1').attr('title', 'Change lang to english');
			$('#FarsiType_button_2').val('FA');
			$('#FarsiType_button_2').attr('title', 'Change lang to english');
			$('.changableInput').css('align', 'right');
			$('.changableInput').css('direction', 'rtl');
			$('.changableInput').css('text-align', 'right');
		}
		$('.changableInput').attr('value', '');
	});
	
	$("#searchSt1BTN").click( function(e) {
		e.preventDefault();
		goto_search_st1();
	});
	
	$("#countryID").keypress(function (e) {
      if (e.which == 13) {
        goto_search_st1();
    }
	});
	
	$("#stateID").keypress(function (e) {
      if (e.which == 13) {
        goto_search_st1();
    }
	});
	
	$("#backSearchBTN").click( function(e) {
		e.preventDefault();
		$("#cityID").html('');
		$('#searchSt2').fadeOut('normal',function(){
			$("#countrySpin").hide();
			$('#searchSt1').fadeIn('normal');
		});
	});
	
	$(".backSt1BTN").click( function(e) {
		e.preventDefault();
		$('#searchSt2').fadeOut('normal',function(){
			$("#countrySpin").hide();
			$('#searchSt1').fadeIn('normal');
		});
	});
	
	$("#gotoCatStep").click( function(e) {
		e.preventDefault();
		$('.sideBar2').hide('normal',function(){
			$('#catSide').show('normal');
		});
	});
	
	$("#gotoKeyStep").click( function(e) {
		e.preventDefault();
		$('.sideBar2').hide('normal',function(){
			$('#keySide').show('normal');
		});
	});
	
	$("#gotoJobsList").click( function(e) {
		e.preventDefault();
		var data= $(".formHolder form").serialize();
		window.location='?page=search_job_result&sector=job_search1&'+data;
	} ); 
	
	$("#job_catID").change( function(e) {
		e.preventDefault();
		var data= $(".formHolder form").serialize();
		window.location='?page=search_job_result&sector=job_search1&'+data;
	} ); 

	
	$("#searchJob1").click( function(e) {
		e.preventDefault();
		var data= $("#job_search_form1 form").serialize();
		window.location='?page=member_panel&task=member_job_result&'+data;
	} ); 
	
	$('#searchForm').submit(function(){
		return false;
	});
	
	$("#searchJob2").click( function(e) {
		e.preventDefault();
		goto_searchJob2();
	} ); 
	
	$("#tags").keypress(function (e) {
      if (e.which == 13) {
        goto_searchJob2();
		e.preventDefault();
    	}
	});
	
	
	$("#submitAD").click( function(e){
		e.preventDefault();
		generalPostI('member_panel&task=success_ads');
	} ); 
	
	$("#sendCV").click( function(e) {
		e.preventDefault();
		generalPostI('member_panel&task=success_send_cv');
	} ); 
	
	$("#updateER").click( function(e) {
		e.preventDefault();
		generalPostII();
	} ); 
	
	$("#updateEE").click( function(e) {
		e.preventDefault();
		generalPostII();
	} ); 
	
	
	$("#eeStartBTN").click( function(e) {
		e.preventDefault();
		$('#regStep1').fadeOut('normal',function(){
			$('#regStep2').fadeIn('normal');
		});
	});
	
		  
 });
 


