// JavaScript Document
<!-- Video Gallery going here  -->

var active_tab='tab1';
function changePage(page,id)
{

	for(var i=1;i<=5;i++)
	{
		if(i==1)
			document.getElementById('dot' + i).className='tabs_scrol activedot';
		else
			document.getElementById('dot' + i).className='tabs_scrol';
		

		if(id==i)
		{
			active_tab='tab' + i;
			document.getElementById('tab' + i).className='rgt_tabbg_active';
			document.getElementById('tab_' + i).className='tab_active';
		}
		else
		{
		document.getElementById("tab" + i).className='rgt_tabbg';
		document.getElementById("tab_" + i).className='';
		}
	}
	
	Stop_Timer();

    jQuery.ajax({
		   
         type: "POST",
         url: "ajaxpages/"+ page +".php",
         data: "page=" + page,
		 target: '#tabs_contentTop',
		 beforeSend: function(){jQuery("#tabs_contentTop").html("<div id=\"tabs_content_flow\"><br><br><br><br><br><br><div align='center'><img src='http://www.hazara.com.pk/js/loading.gif' border='0'></div></div>")},
		 success: function(msg){
			 
			jQuery("#tabs_contentTop").html(msg);
			Start_SlideTimer();		
		  
		 },
		 error: function(){
			jQuery("#tabs_contentTop").html("Error Loading Page");
		 }	

    });
}

//Change Tab Slide
function ChangeTabSlide(id, stopTimer)
{
	//Abid Ali : 27/04/2011
	//alert("Stop timer is " + stopTimer);
	if(stopTimer == 'true')
	{
		Stop_Timer();
	}
	for(var i=1;i<=6;i++)
	{
		
		if(id==i)
		{
			document.getElementById('dot' + i).className='tabs_scrol activedot';
			if (document.getElementById('data_' + active_tab + '_' + i) != null)
				document.getElementById('data_' + active_tab + '_' + i).style.display='block';

		}
		else
		{
			document.getElementById("dot" + i).className='tabs_scrol';
			if (document.getElementById('data_' + active_tab + '_' + i) != null)
				document.getElementById('data_'+ active_tab+'_' + i).style.display='none';
		}
	}
	
}


//Change Jobs Navigation
function ChangeJobsSlide(id)
{
	for(var i=1;i<=5;i++)
	{
		if(id==i)
		{
			document.getElementById('jobdot_' + i).className='tabs_scrol activedot';
			document.getElementById('jobs_'+ i).style.display='block';

		}
		else
		{
			document.getElementById("jobdot_" + i).className='tabs_scrol';
			document.getElementById('jobs_' + i).style.display='none';

		}
	}
	
}
//Add Poll value
function addVal(option_id)
{
	document.getElementById('pollOptionID').value = option_id;
	
}
//Poll
function postPoll(poll_ID)
{
	var pollOptionID = 0;
	pollOptionID =document.getElementById('pollOptionID').value;
	
	if(pollOptionID == 0)
	{
		alert("Please select your poll option.");
		return false;
	}
	
	jQuery.ajax({
		   
         type: "POST",
         url: "ajaxpages/indexpoll.php",
         data: "polloptionid=" + pollOptionID+"&pollid=" + poll_ID,
		 target: '#pollOptions',
		 beforeSend: function(){jQuery('#pollOptions').html("<div style='margin-top:20px;' align='center'><img src='http://www.hazara.com.pk/js/loading.gif' border='0'></div>")},
		 success: function(msg){
			 
			jQuery('#pollOptions').html(msg);		
		  
		 },
		 error: function(){
			jQuery('#pollOptions').html("Error Loading Page");
		 }	

    });
	
}

//Ajax call to Videos
function getVideos(page,id)
{
	$("#video_tab ul li a.tab_active span").removeClass('arrow', '');
	$("#video_tab ul li a").removeClass('tab_active', '');
	
	document.getElementById('VideoTab' + id).className='tab_active';
	document.getElementById('ActiveArrow' + id).className='arrow';

	
    jQuery.ajax({
		   
         type: "POST",
         url: "/ajaxpages/video-tabs.php",
         data: "page=" + page,
		 target: '#video_flow',
		 beforeSend: function(){jQuery("#video_flow").html("<div align='center'><img src='http://www.hazara.com.pk/js/loading.gif' border='0'></div>")},
		 success: function(msg){
			jQuery("#video_flow").html(msg);		
		  
		 },
		 error: function(){
			jQuery("#video_flow").html("Error Loading Page");
		 }	

    });
}

//Ajax call to get single news info
function getNewsInfo(newsid)
{
    jQuery.ajax({
		   
         type: "POST",
         url: "../ajaxpages/singlenews.php",
         data: "newsid=" + newsid,
		 target: '#newsGroup',
		 beforeSend: function(){jQuery("#newsGroup").html("<div align='center'><img src='http://www.hazara.com.pk/js/loading.gif' border='0'></div>")},
		 success: function(msg){
			 
			jQuery("#newsGroup").html(msg);		
		  
		 },
		 error: function(){
			jQuery("#newsGroup").html("Error Loading Page");
		 }	

    });
}


/*Edidted by Abid*/
var slide_id = 1;
var timer = null;

function Start_SlideTimer()
{
	ChangeTabSlide(slide_id, 'false');
	if(slide_id == 6)
		slide_id = 1;
	else 
		slide_id = slide_id + 1;
	timer = setTimeout("Start_SlideTimer()",5000);
}
	
function Stop_Timer()
{
	slide_id = 1;
	if(timer != null)
    	clearTimeout(timer);
}
		
function postRating(id,task, userID)
{
	if (userID == 0)
	{
		jQuery('#postRat').html("Please Sign In to cast your vote!");
		return;

	}

	var txtcomments;
	if(task=='comments')
		txtcomments="&txtcomments=" + document.getElementById('txtcomments').value;
	else
		txtcomments='';
	jQuery.ajax({
		   
         type: "POST",
         url: "/ajaxpages/post-rat.php",
         data: "task=" + task + "&id=" + id + txtcomments,
		 target: '#pollq'+ id,
		 beforeSend: function(){jQuery('#postRat').html("<div style='margin-top:50px;' align='center'><img src='http://www.hazara.com.pk/js/loading.gif' border='0'></div>")},
		 success: function(msg){
			 
			jQuery('#likedislikID').html(msg);
			
			if(task != "comments")
			{
			jQuery.ajax({
				   
				 type: "POST",
				 url: "/ajaxpages/post-rat.php",
				 data: "task=updateLikeDislike&id=" + id ,
				 target: '#likedislike_id',
				 beforeSend: function(){jQuery('#likedislike_id').html("<div style='margin-top:50px;' align='center'><img src='http://www.hazara.com.pk/js/loading.gif' border='0'></div>")},
				 success: function(msg){
					 
					jQuery('#likedislike_id').html(msg);		
				  
				 },
				 error: function(){
					jQuery('#likedislike_id').html("Error Loading Page");
				 }	
		
			});
			}
		  
		 },
		 error: function(){
			jQuery('#postRat').html("Error Loading Page");
		 }	

    });
	
}

function postComments(id,task, userID)
{
	var txtcomments;
	
	if (userID == 0)
	{
		jQuery('#postComments').html("Please Sign In to post your comments!");
		return;

	}
	else if (task=='comments' && document.getElementById('txtcomments').value.trim().length == 0)
	{
		jQuery('#postComments').html("Please write some comments...");
		return;
	}
	
	
	if(task=='comments')
		txtcomments="&txtcomments=" + document.getElementById('txtcomments').value;
	else
		txtcomments='';
	jQuery.ajax({
		   
         type: "POST",
         url: "/ajaxpages/post-rat.php",
         data: "task=" + task + "&id=" + id + txtcomments,
		 target: '#pollq'+ id,
		 beforeSend: function(){jQuery('#postComments').html("<img src='http://www.hazara.com.pk/js/loading.gif' border='0'>")},
		 success: function(msg){
			 
			jQuery('#uploader_comments').html(msg);
			
			jQuery('#postComments').html("");
		 },
		 error: function(){
			jQuery('#postComments').html("Error Loading Page");
			jQuery('#postComments').html("");
		 }	

    });
	
}

