var r = new Date().getTime(); 
$(document).ready(function() {
	$(".main_ban_sub").hover(function() {
		$(this).find("div").stop(true, true).slideDown(300);
	} , function() { 
		$(this).find("div").stop(true, true).slideUp(300);
	});
});
//####################################################################//
function str(tr1,tr2){
	$("#"+tr1).stop(true, true).slideUp(300);
	$("#"+tr2).stop(true, true).slideDown(300);
	
	}
//####################################################################//
function h_div(){
    $("#div1").fadeOut(150);
    $("#view_img").fadeOut(100);
}
function view_img(img_url){
	$("#div1").hide().fadeIn(100).fadeTo("slow", 0.70);
	$("#img_src").attr("src", ""+img_url+"");
	$("#view_img").hide().fadeIn(100).fadeTo("slow", 0.9);
	}
	
//####################################################################//
function add_vote(vid){
	var val=$('input:radio[name=vote_val]:checked').val();
	var x=$('input:radio[name=vote_val]:checked').length;
	if(x !='0'){
		$('input:radio[name=vote_val]').attr("disabled", "disabled"); 
		$("#vote_sub").attr("disabled", "disabled"); 
		$("#vote_status").hide().fadeIn(300).html('الرجاء الإنتظار <img src="images/load.gif"  align="baseline">');
		var url="funcs.php?do=add_vote&val="+ val +"&r="+r;
		$.get(url, function(msg) {
			if(msg== '1'){
						$("#vote_status").hide().fadeIn(300).html('تم التصويت بنجاح.. شكرا لك');
				get_vote(vid,val);
				}
				else if(msg== '2'){
						$("#vote_status").hide().fadeIn(300).html('خطأ .!!');
					}
				else if(msg== '3'){
						$("#vote_status").hide().fadeIn(300).html('لقد قمت بالتصويت مسبقا');
					}
		});
	}
	else{
	$("#vote_status").hide().fadeIn(300).html('تأكد من اختيار خيار التصويت');
		}
}
//####################################################################//
function get_vote(vid,sid){
		var url="funcs.php?do=get_vote&val="+ vid +"&sid="+ sid +"&r="+r;
		$.get(url, function(msg) {
			$("#vote_body").hide().fadeIn(300).html(msg);
		});
}
//####################################################################//
function send_vote(){
	$("#vwait").hide().fadeIn(300).html('الرجاء الإنتظار <img src="images/load.gif"  align="baseline">');
	var name=$("#vt1").val();
	var gender=$("#vt2").val();
	var count=$("#vt3").val();
	var tag=$("#vt4").val();
	var vote=$("#vt5").val();
	if(name==''){$("#vwait").hide().fadeIn(300).html('الرجاء كتابة الإسم');}
	else if(gender==''){$("#vwait").hide().fadeIn(300).html('الرجاء كتابة الجنس');}
	else if(count==''){$("#vwait").hide().fadeIn(300).html('الرجاء كتابة الدولة');}
	else if(tag==''){$("#vwait").hide().fadeIn(300).html('الرجاء كتابة التعليق');}
	else{
	$("#vwait").hide().fadeIn(300).html('الرجاء الإنتظار <img src="images/load.gif"  align="baseline">');
	var url="funcs.php?do=send_vote&vid="+vote+"&r="+r;
	$.post(url, { name: name, gender: gender , count: count , tag: tag },
	 function(data) {
	$("#vwait").hide().fadeIn(300).html(data);
	 }
	);
	}
}
//####################################################################//
function add_email(){
	$("#add_wait").hide().fadeIn(300).html('الرجاء الإنتظار <img src="images/load.gif"  align="baseline">');
	var email=$("#tmail").val();
	if(email==''){$("#add_wait").hide().fadeIn(300).html('الرجاء كتابة البريد الالكتروني');}
	else{
	$("#add_wait").hide().fadeIn(300).html('الرجاء الإنتظار <img src="images/load.gif"  align="baseline">');
	var url="funcs.php?do=add_email&r="+r;
	$.post(url, { email: email },
	 function(data) {
	$("#add_wait").hide().fadeIn(300).html(data);
	 }
	);
	}
}
//####################################################################//
function save_vote_details(){
	var r = new Date().getTime(); 
	$("#vwait").hide().fadeIn(300).html('<img src="images/load.gif"  align="baseline"> الرجاء الإنتظار ');
	var name=$("#vt1").val();
	var email=$("#vt2").val();
	var count=$("#vt3").val();
	var vote=$("#vt4").val();
	var notes=$("#vt5").val();
	if(name==''){$("#vwait").hide().fadeIn(300).html('الرجاء كتابة الإسم');}
	else if(email==''){$("#vwait").hide().fadeIn(300).html('الرجاء كتابة البريد الإلكتروني');}
	else if(count==''){$("#vwait").hide().fadeIn(300).html('الرجاء كتابة الدولة');}
	else{
		var tag='';
		var x=0;
		while (x<11){
			x++;
			if($("input:radio[name=t_"+x+"]:checked").length!=''){
			tag=tag+" , "+$("input:radio[name=t_"+x+"]:checked").val();
			}
			}
	$("#vwait").hide().fadeIn(300).html('<img src="images/load.gif"  align="baseline"> الرجاء الإنتظار ');
	var url="funcs.php?do=send_vote&vid="+vote+"&r="+r;
	$.post(url, { name: name, email: email , count: count , tag: tag  , notes: notes },
	 function(data) {
	$("#vwait").hide().fadeIn(300).html(data);
	 }
	);
	}
}
//####################################################################//
function get_news(num,mnum){
	var x=0;
	while(x<20){
		x++;
		$("#a_"+x).attr('class','pna');
		}
		$("#a_"+num).attr('class','pnha');

		var url="funcs.php?do=get_mnews&num="+ num +"&mnum="+ mnum +"&r="+r;
		$.get(url, function(msg) {
			$("#news_body").hide().fadeIn(300).html(msg);
		});
}
//####################################################################//
function newPopup(url,w,h) {
	popupWindow = window.open(
		url,'popUpWindow','height='+h+',width='+w+',left=0,top=0,resizable=no,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=no')
}
//####################################################################//
function send_msg(){
	$("#msg_val").html('<img src="images/load.gif" width="16" height="11" />  الرجاء الإنتظار ');
	var txt=$("#t5").val();
	$.post("funcs.php?do=send_message&r="+r+"",{ y_name: $("#t1").val(),    
y_email: $("#t2").val() , f_name: $("#t3").val(),    
f_email: $("#t4").val(),    
rr: $("#rr").val() , y_msg: txt}, function(msg) {
			$("#msg_val").html(msg);
		});
}
//####################################################################//
function ad_tag(){
	$("#div1").hide().fadeIn(300);
	$("#ad_tag").slideDown(300);
}
function close_ad_tag(){
	$("#ad_tag").slideUp(300);
	setTimeout(function(){
	$("#div1").fadeOut(500);
	},600);
	}
//####################################################################//
function save_tag(){
	$("#msg_val").html('<img src="images/load.gif" width="16" height="11" />  الرجاء الإنتظار ');
	var name=$("#t1").val();
	var email=$("#t2").val();
	var addr=$("#t3").val();
	var txt=$("#t4").val();
	var subj=$("#subj").val();
	
	
		$.post("funcs.php?do=save_tag&r="+r+"",{ name: $("#t1").val(),    
		email: $("#t2").val(), addr: $("#t3").val(), txt: txt , subj: $("#subj").val()}, function(msg) {
	$("#msg_val").html('تمت إضافة التعليق بنجاح');
		setTimeout(function(){
	close_ad_tag();
		},2000);
		
	});

		
}

