$(document).ready(function() {
	$(".questions").toggle(
		function() {
				$(this).removeClass("collapsed");
				$(this).addClass("expanded");
				var ids = $(this).attr("id");
				var ansid = "ans_"+ids.split("_")[1];
				$("#"+ansid).show(500);
		},
		function() {
				$(this).removeClass("expanded");
				$(this).addClass("collapsed");
				var ids = $(this).attr("id");
				var ansid = "ans_"+ids.split("_")[1];
				$("#"+ansid).hide(500);
		}
	);


	$(".abouttitle").click(function() {
		$(".abouttitle").removeClass("selected");
		$(".aboutcontent").hide();
		$(this).addClass("selected");
		var ids = $(this).attr("id");
		var content_id = "content_"+ids.split("_")[1];
		$("#"+content_id).show();
	});

	$(".partners_content").click(function() {
			var curr_id_str = $(this).attr('rel');
			var curr_id_arr = curr_id_str.split("_");
			$(".partners_content_category").hide();
			$("#cat_"+curr_id_arr[0]).show();
			for(i=1;i<=7;++i) {
				$("#cat_img_"+i).removeClass("link"+i+"selected");
				$("#cat_img_"+i).addClass("link"+i);
			}
			$("#cat_img_"+curr_id_arr[1]).addClass("link"+curr_id_arr[1]+"selected");
	});

	$(".cellnumber").keyup(function() {
		var vl = $(this).attr("value");
		var vl_id = $(this).attr("id");
		var tr_id = "";
		if(vl.length == 3) {
			if(vl_id == "cell1") {
				tr_id = "cell2";
			}
			if(vl_id == "cell2") {
				tr_id = "cell3";
			}
		}
		if(tr_id) {
			$("#"+tr_id).focus();
		}
	});
	
	$(".rss_links").click(function() {
			$(".rss_links").removeClass("selected");
			$(this).addClass("selected");
			var rel = $(this).attr("rel");
			var data_id = "data_"+rel;
			$(".rss_data").hide();
			$("#"+data_id).show()	;
			//$("#rss_container").html($("#"+data_id).html());
	});
	
	$(".treemenu").click(function() {
		var id = $(this).attr("rel");
		if($("#description_"+id).attr("rel") == "close") {
			$(".treemenu").removeClass("minus");
			$(".treemenu").addClass("plus");
			$(this).removeClass("plus");
			$(this).addClass("minus");
			$(".subtree").hide(500);
			$(".subtree").attr("rel","close");
			$("#description_"+id).show(500);
			$("#description_"+id).attr("rel","open");
		}else {
			$(this).removeClass("minus");
			$(this).addClass("plus");
			$("#description_"+id).attr("rel","close");
			$($("#description_"+id)).hide(500);
		}
	});
	
})

function current_rss_data() {
	current_data_id = 'data_articlenav';
	current_sel_id = 'articlenav';
	$("#"+current_sel_id).addClass("selected");
	$("#"+current_data_id).show();
	//$("#rss_container").html($("#"+current_data_id).html());
}

/*
function send_to_phone_prc(post_id) {

	var pos = $("#s2p_"+post_id).position();
	$("#post_id").attr("value",post_id);
	$("#send_to_phone").css("left",pos.left+"px");
	$("#send_to_phone").css("top",pos.top+"px");
	$("#ques").show();
	$("#ans").html("");
	$("#ans").hide();
	$("#send_to_phone").show(500);
}*/

//Function modified by Puru on 4th August 2010 to show different message
function send_to_phone_prc(post_id,submit_from_hero_spot) {

	if(submit_from_hero_spot == 1) {
		jQuery('#submit_from_hero_spot').val(submit_from_hero_spot);
	}else {
		jQuery('#submit_from_hero_spot').val(0);
	}
	var pos = $("#s2p_"+post_id).position();
	if(submit_from_hero_spot == 1) {
		pos.left = pos.left - 140;
	}
	
	pos.top = pos.top + 25;
	
	$("#post_id").attr("value",post_id);
	$("#send_to_phone").css("left",pos.left+"px");
	$("#send_to_phone").css("top",pos.top+"px");
	$("#ques").show();
	$("#ans").html("");
	$("#ans").hide();
	$("#send_to_phone").show(500);
}

function send_to_phone_close() {
	$("#send_to_phone").hide(500);
	$("#cell1").attr("value","");
	$("#cell2").attr("value","");
	$("#cell3").attr("value","");
}

function send_sms() {
	var post_id = $("#post_id").attr("value");
	var cell1 = $("#cell1").attr("value");
	var cell2 = $("#cell2").attr("value");
	var cell3 = $("#cell3").attr("value");
	if(!cell1) {
		alert("Please enter your cell number in the input box.");
		return false;
	}
	else if(IsNumeric(cell1) == false) {
		alert("Please enter valid cell number.");
		return false;
	}
	if(!cell2) {
		alert("Please enter your cell number in the input box.");
		return false;
	}
	else if(IsNumeric(cell2) == false) {
		alert("Please enter valid cell number.");
		return false;
	}

	if(!cell3) {
		alert("Please enter your cell number in the input box.");
		return false;
	}
	else if(IsNumeric(cell3) == false) {
		alert("Please enter valid cell number.");
		return false;
	}

	$.get(base_url, {post_id:post_id,cell1:cell1,cell2:cell2,cell3:cell3,submit_from_hero_spot:$('submit_from_hero_spot').val(),type:'sendsms'},
   function(data){
			$("#ques").hide();
			$("#ans").html(data);
			$("#ans").show();
  });
}

var prev_cat_id = "all";
function fetch_cat_data(url,cat_id) {
  var pos =  $("#id_"+cat_id).position();
  show_loader(pos);
	$.get(url, { fetch_cat_id: 'yes'},
   function(data){
     $("#data_container").html(data);
     //$(".facebooklike").html($("#facebooklikebtn").html());
     $(".atabs").removeClass("current");
     $("#id_"+cat_id).addClass("current");
		hide_loader();
  });
}


function show_loader(pos) {
	var top = parseInt(pos.top)+50;
	$("#ajax-loader").css("left",pos.left+"px");
	$("#ajax-loader").css("top",top+"px");
	$("#ajax-loader").css("display","block");
}

function hide_loader() {
	$("#ajax-loader").css("left",0);
	$("#ajax-loader").css("top",0);
	$("#ajax-loader").css("display","none");
}


function show_help_content(id) {
	if(id == 'faq') {
			$("#buyingguide").removeClass("current");
			$("#faq").addClass("current");
			$("#faqcontent").css("display","block");
			$("#buyingguidecontent").css("display","none");
	}else {
			$("#faq").removeClass("current");
			$("#buyingguide").addClass("current");
			$("#faqcontent").css("display","none");
			$("#buyingguidecontent").css("display","block");
	}
}

function openform(obj,post_id) {
	var jpos = $(obj).position();
	var ntop = jpos.top + 30;
	$("#response_html").html("");
	$("#post_id").attr("value",post_id);
	$("#sendemailfriend").css("left",jpos.left+"px");
	$("#sendemailfriend").css("top",ntop+"px");
	$("#sendemailfriend").show(300);
}

function close_send_to_fried() {
	$("#sendemailfriend").hide(300);
}

function send_email_friend() {
	var post_id = $("#post_id").attr("value");
	var name = $("#name").attr("value");
	if(!name) {
		alert("Please enter name");
		return false;
	}
	var email = $("#emailaddr").attr("value");
	if(!email) {
		alert("Please enter Email");
		return false;
	}else {
	 	if(!checkemail(email)) {
		 	alert("Please enter Valid Email");
			return false;
	 	}
	}
	var message = $("#message").attr("value");

	var url = base_url+"?send_to_friend=1";
	$.get(url, { post_id:post_id, name:name, email:email, message:message},
   function(data){
		$("#response_html").html(data);
		$("#name").attr("value","");
		$("#emailaddr").attr("value","");
		$("#message").attr("value","");

		window.setTimeout("close_send_to_fried()",500);
  });
}

function checkemail(email) {
	var str = email;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
		testresults=true
	else{
		testresults = false
	}
	return (testresults);
}

function IsNumeric(strString) {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;
   if (strString.length == 0) return false;
   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++) {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1) {
         blnResult = false;
      }
   }
   return blnResult;
}

