// JavaScript Document
var url_home = "http://localhost/pfw/";
function rempass(){
	var un= $("#username").val();	
	var params = 'action=fetchrempass';
	params += "&un="+un;
	$.ajax({
		url : url_home+'rempass.php?'+params,
		success : function (data) {
			if(data!="") {
				$("#password").val(data);
				$("#rem").attr('checked', true);
			}
		}
	});
}

$(document).ready(function() {
	$("#search-text").focus(function() {
		$("#search-text").val("");
	});
	$("#search-text").blur(function() {
		$("#search-text").val("Enter Kewords");
	});
});
/* USER PAGE */
$(document).ready(function() { 
	$("#change-email").click(function () {
		$("#change-password-div").hide('fast');
		$("#change-email-div").show();
	});
	$("#change-password").click(function (){
		$("#change-email-div").hide('fast');
		$("#change-password-div").show();
	});
	//show pending questions div
	$("#pending-questions").click(function (){
		$("#ask-question-div").hide('fast');
		$("#answered-question-div").hide('fast');
		$("#pending-questions-div").show();
	});
	//show pending questions div
	$("#ask-question").click(function (){
		$("#answered-questionanswered-question-div").hide('fast');
		$("#pending-questions-div").hide('fast');
		$("#ask-question-div").show();
	});
	//show answered questions div
	$("#answered-question").click(function (){
		$("#ask-question-div").hide('fast');
		$("#pending-questions-div").hide('fast');
		$("#answered-question-div").show();
	});
	//show Question to Answers
	$("#question-to-answer").click(function (){
		$("#ans-pend-approval-div").hide('fast');
		$("#ans-approved-div").hide('fast');
		$("#question-to-answer-div").show();
		$("#question-to-answer").parent().parent().children().removeClass("active");
		$("#question-to-answer").parent().addClass("active");
	});
	//show Pending Answers
	$("#ans-pend-approval").click(function (){
		$("#question-to-answer-div").hide('fast');
		$("#ans-approved-div").hide('fast');
		$("#ans-pend-approval-div").show();
		$("#ans-pend-approval").parent().parent().children().removeClass("active");
		$("#ans-pend-approval").parent().addClass("active");
	});
	//show Question to Answers
	$("#ans-approved").click(function () {
		$("#ans-pend-approval-div").hide('fast');
		$("#question-to-answer-div").hide('fast');
		$("#ans-approved-div").show();
		$("#ans-approved").parent().parent().children().removeClass("active");
		$("#ans-approved").parent().addClass("active");
	});
	
	$("#opt_new").click(function () {
		$("#art-option").hide();
		$("#select-art-area").hide();
		$("#writer-area-1").show();
		$("#writer-area-2").hide();
	});
	$("#opt_sel").click(function () {
		$("#writer-area-1").hide('fast');
		$("#select-art-area").show();
	});
});
function addArticle(catid,catname) {
	$("#art-option").hide();
	$("#select-art-area").hide();
	$("#writer-area-1").hide();
	$("#writer-area-2").show();
	$("#cat_id").val(catid);
	$("input[name=cat_name]").val(catname);
}
var cnt = 0;

function showArticle(artid) {
	$(document).ready(function(){
	$.post("ArticleAjax.php",{suggest:artid},function(result){
	  $("#art_details").html(result);
	  $("#art_details").show();
	  $("#write-an-article-div").hide('fast');
	  $("#pending-article-div").hide('fast');
	  $("#approved-article-div").hide('fast');
	  $("#rejected-article-div").hide('fast');	  
	});
	});	
}
function showPostAnswer(divid,qid){
	var qns = $("#"+divid+" p.qns").text();
	$("#give-answer").show();
	$("#qns").text( $("#"+divid+" p.qns").text() );
	$("input[name=qnsid]").val(qid);
}

function showAnswer(divid){
	var currentId = $(divid).attr('id');
	var newdiv = currentId+"_div";
	$("#"+newdiv).slideToggle();
}
/********************/
function fillURL(txtvalue,txtfld){
	var nstr = "";
	for(var i=0;i<txtvalue.length;i++) {		
		var iChars = "!@#$%^&*()+=[]\\\';,/{}|\":<>";
		if (iChars.indexOf(txtvalue.charAt(i)) != -1) {
			nstr += '-';
		}
		else if(txtvalue[i]==" ") {
			nstr += '-';
		}
		else {
			nstr += txtvalue[i];
		}
	}
	document.getElementById(txtfld).value = nstr.toLowerCase();
}
function setRatingValue(val,elid) {
	if(confirm("Confirm to assign "+val+" rating for this ?")){
		document.getElementById(elid).value = val;
	}
}
function setAnsRating(val,frm) {
	if(confirm("Confirm to assign "+val+" rating to this ?")){
		document.frm.rating.value = val;
	}
}
function printPartOfPage(elementId)
{
 var printContent = document.getElementById(elementId);
 var windowUrl = 'print_article.php';
 var uniqueName = new Date();
 var windowName = 'Print' + uniqueName.getTime();
 var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');
 
 printWindow.document.write(printContent.innerHTML);
 printWindow.document.close();
 printWindow.focus();
 printWindow.print();
 printWindow.close();
}
function validateQnsComment(formid) {
	if(!valid_required(formid.comment.value))	{	
		alert("Please enter your comment!");		
		formid.comment.focus();
	}
	else {
		var qnsid=$("input[name=qnsid]").val();
		var comment=$("textarea[name=comment]").val();		
		var dataString = 'qns_id='+ qnsid + '&comment=' + comment;
		alert (dataString);
		$.ajax({
      type: "POST",
      url: "qnsAjax.php",
      data: dataString,
      success: function(result) {
		alert (result);
		$("textarea[name=comment]").html(result);
      }
     });alert (dataString);
	}
	return false;
}
$(document).ready(function() {
		$("#rqb_up").click(function(){	
  	$("#rqb").animate({"scrollTop": "+=200px"}, 1200);
		});$("#rqb_down").click(function(){	
  	$("#rqb").animate({"scrollTop": "-=200px"}, 1200);
		});
});
