//Poll Post Comment
function loadXMLString(txt) {
	try{ //Internet Explorer
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.loadXML(txt);
		return(xmlDoc);  
	}catch(e){
		try {//Firefox, Mozilla, Opera, etc.
			parser=new DOMParser();
			xmlDoc=parser.parseFromString(txt,"text/xml");
			return(xmlDoc);
		}catch(e) {alert(e.message)}
	}
	return(null);
}


function pollpostComment(frm){
	//alert("Ready");
	$.ajax({	method: "get",
				url: AJAX_SITE_REQUEST_USERS_URL+"check_login2.php",
				data: '',
				beforeSend: function(){}, 
				complete: function(){ }, 
				success: function(html){ //so, if data is retrieved, store it in html
					is_login=html;

					islgn		= is_login.split("^");
					is_login	=	islgn[0];					
					if(is_login=='yes'){
						if(document.getElementById("prep")!=null){
							document.getElementById("prep").style.display='block';
							document.frm_comment.userID.value	=	islgn[1];
							document.frm_comment.usernickname_.value=islgn[4]
							document.frm_comment.userimg_.value=islgn[2]							
							document.frm_comment.userhref_.value=islgn[3]														
							document.getElementById("lcp").style.display="block";
							document.getElementById("wlcp").style.display="none";							
							return false;
						}
							var pollId = frm.pollId.value;
							var t = 'Post Comments';
							var a = SITE_URL + "index.php?action=polls&task=postComment&pollId="+pollId+"&popup&keepThis=true&TB_iframe=true&height=200&width=250";
							var g = false;
								tb_show(t,a,g);
								return true;
					}else{
						var t = null;
						var a = AJAX_SITE_REQUEST_USERS_URL + "short_login_register.php?jsfunc=pollpostComment&jsfunc_frmref="+frm.name+"&popup&keepThis=true&TB_iframe=true&height=288&width=790";
						var g = false;
						tb_show(t,a,g);
					}
					return false;
				}
	});
	return false;
}

function pollpostCommentReply(frm){
	//alert("ready");
	$.ajax({	method: "get",
				url: AJAX_SITE_REQUEST_USERS_URL+"check_login.php",
				data: '',
				beforeSend: function(){}, 
				complete: function(){ }, 
				success: function(html){ //so, if data is retrieved, store it in html
					is_login=html;
					if(is_login=='yes'){
						if(frm.pcntr!=null){
							vval	=	frm.pcntr.value
							document.getElementById("prep"+vval).style.display="block";
							return false;
						}
							var pollId 	  = frm.pollId.value;
							var commentID = frm.commentID.value;
							var t = 'Post Comments';
							var a = SITE_URL + "index.php?action=polls&task=postComment&pollId="+pollId+"&commentID="+commentID+"&popup&keepThis=true&TB_iframe=true&height=200&width=250";
							var g = false;
								tb_show(t,a,g);
								return true;
					}else{
						var t = null;
						var a = AJAX_SITE_REQUEST_USERS_URL + "short_login_register.php?jsfunc=pollpostCommentReply&jsfunc_frmref="+frm.name+"&popup&keepThis=true&TB_iframe=true&height=288&width=790";
						var g = false;
						tb_show(t,a,g);
					}
					return false;
				}
	});
	return false;
}



//Poll Share 
function pollShare(frm){
	//alert("Ready");
	$.ajax({	method: "get",
				url: AJAX_SITE_REQUEST_USERS_URL+"check_login.php",
				data: '',
				beforeSend: function(){}, 
				complete: function(){ }, 
				success: function(html){ //so, if data is retrieved, store it in html
					is_login=html;
						if(is_login=='yes'){
							var pollId = frm.pollId.value;
							var t = 'Share Poll';
							var a = SITE_URL + "index.php?action=polls&task=postShare&pollId="+pollId+"&popup&keepThis=true&TB_iframe=true&width=500";
							var g = false;
								tb_show(t,a,g);
								return true;
					}else{
						var t = null;
							var a = AJAX_SITE_REQUEST_USERS_URL + "short_login_register.php?jsfunc=pollShare&jsfunc_frmref="+frm.name+"&popup&keepThis=true&TB_iframe=true&height=288&width=790";
						var g = false;
						tb_show(t,a,g);
					}
					return false;
				}
	});
	return false;
}

//Poll Share Online
function pollShareOnline(frm){
	//alert("Ready");
	$.ajax({	method: "get",
				url: AJAX_SITE_REQUEST_USERS_URL+"check_login.php",
				data: '',
				beforeSend: function(){}, 
				complete: function(){ }, 
				success: function(html){ //so, if data is retrieved, store it in html
					is_login=html;
					if(is_login=='yes'){
							var pollId = frm.pollId.value;
							var t = 'Share With Online Friends';
							var a = SITE_URL + "index.php?action=polls&task=pollshare_expert&pollId="+pollId+"&popup&keepThis=true&TB_iframe=true&height=280&width=450";
							var g = false;
								tb_show(t,a,g);
								return true;
					}else{
						var t = null;
						var a = AJAX_SITE_REQUEST_USERS_URL + "short_login_register.php?jsfunc=pollShareOnline&jsfunc_frmref="+frm.name+"&popup&keepThis=true&TB_iframe=true&height=288&width=790";
						var g = false;
						tb_show(t,a,g);
					}
					return false;
				}
	});
	return false;
}
// poll comment report abuse
function do_show_abuse(frm){
//alert("ready");
$.ajax({	method: "get",
				url: AJAX_SITE_REQUEST_USERS_URL+"check_login.php",
				data: '',
				beforeSend: function(){},
				complete : function() {},
				success : function(html){ //so, if data is retrieved, store it in html
				is_login=html;
				if(is_login=='yes'){
				   var t="Report Abuse";
				   var a=SITE_URL + "index.php?action=polls&task=report_abuse&id="+frm.pollId.value+"&uName="+frm.uname.value+"&commId="+frm.commentID.value+"&pDesc="+frm.polldesc.value+"&popup&keepThis=true&TB_iframe=true&height=300&width=380";
					 var g=false;
					 tb_show(t,a,g);
					  return true;
				}else{
					var t=null;
				    var a= AJAX_SITE_REQUEST_USERS_URL + "short_login_register.php?jsfunc=do_show_abuse&jsfunc_frmref="+frm.name+"&popup&keepThis=true&TB_iframe=true&height=288&width=790";
					var g=false;
					tb_show(t,a,g);
				}
				return false;
				}
		   });
	    return false;
}

/// function for ratings on poll
function rate_up(){
	pollId='';
	CatID='';
	querystring = '';
	with(document.MyForm){	
	querystring="&task=rating&CatID="+CatID.value+	
					"&pollId="+pollId.value+"&rate="+rateValue.value;
	}
	$.ajax({ 	method: "get",
				url:AJAX_SITE_REQUEST_POLL_URL+"polls_rate.php",
				data: querystring ,
				beforeSend: function(){ }, //show loading just when link is clicked
				complete: function(){ },  
				success: function(html){ //so, if data is retrieved, store it in html
				xmlDoc=loadXMLString(html);
					x=xmlDoc.documentElement.childNodes;
					rate_result = 'no'; errors =''; total_errors=0; 
					updated_ups=0;	updated_downs=0;
					for (i=0;i<x.length;i++){
						switch(x[i].nodeName){
							case 'state' :			rate_result = x[i].childNodes[0].nodeValue; break;
							case 'total_ups' :		updated_ups= x[i].childNodes[0].nodeValue; break;
							case 'total_downs' :	updated_downs= x[i].childNodes[0].nodeValue; break;
							case 'errors' :			errors = x[i].childNodes[0].nodeValue; break;
							case 'errors_count' : 	total_errors = x[i].childNodes[0].nodeValue;break;
						}
					}
					if(rate_result=='yes'){	// Means Successfult done Rating 
						$("#up_count").html("(" + updated_ups + ")");
						$("#down_count").html("(" + updated_downs + ")");
						$("#up_down_msg").hide();
						$("#up_down_msg").html(errors);
						$("#up_down_msg").slideDown("slow");
						$("#up_down_msg").addClass("BgDarkYellow Black");
					}else{
						$("#up_down_msg").hide();
						$("#up_down_msg").html(errors);
						$("#up_down_msg").slideDown("slow");
						$("#up_down_msg").addClass("BgLightRed Black");
					}
				
				/*	$("#doRateProcessing").html("");
					$("#doRateProcessing").slideUp();
					$("#doRateProcessing").html(html);
					$("#doRateProcessing").slideDown("slow");*/

				}
	});	
}	


/// for ratings on polls using thumbs Up /Down Functionality
function do_poll_rate(frm){
	//alert("ready");
	$.ajax({	method: "get",
				url: AJAX_SITE_REQUEST_USERS_URL+"check_login.php",
				data: '',
				beforeSend: function(){}, 
				complete: function(){ }, 
				success: function(html){ //so, if data is retrieved, store it in html
					is_login=html;
					if(is_login=='yes'){
						var val=frm.rateValue.value;
						if(val=='1'){
						rate_up();
						}else{
							rate_up();
						}
						return true;
					}else{
						var t = null;
						var a = AJAX_SITE_REQUEST_USERS_URL + "short_login_register.php?jsfunc=do_offer_rate&jsfunc_frmref="+frm.name+"&popup&keepThis=true&TB_iframe=true&height=288&width=790";
						var g = false;
						tb_show(t,a,g);
						return false;
					}
				}
	});
	return false;
}




/// function for ratings on comment
function rate_comment(frm,tot){
	pollId='';
	CommID='';
	querystring = '';
	with(frm){	
		querystring="&task=comment_rate&CommID="+commentID.value+	"&pollId="+pollId.value+"&memId="+memId.value+"&rate="+rateValue.value;
	}
	//alert(querystring);
	$.ajax({ 	method: "get",
				url:AJAX_SITE_REQUEST_POLL_URL+"polls_rate.php",
				data: querystring ,
				beforeSend: function(){ }, //show loading just when link is clicked
				complete: function(){ },  
				success: function(html){ //so, if data is retrieved, store it in html
					xmlDoc=loadXMLString(html);
					x=xmlDoc.documentElement.childNodes;
					rate_result = 'no'; errors =''; total_errors=0; 
					updated_ups=0;	updated_downs=0;
					for (i=0;i<x.length;i++){
						switch(x[i].nodeName){
							case 'state' :			rate_result = x[i].childNodes[0].nodeValue; break;
							case 'total_ups' :		updated_ups= x[i].childNodes[0].nodeValue; break;
							case 'total_downs' :	updated_downs= x[i].childNodes[0].nodeValue; break;
							case 'errors' :			errors = x[i].childNodes[0].nodeValue; break;
							case 'errors_count' : 	total_errors = x[i].childNodes[0].nodeValue;break;
						}
					}
					if(rate_result=='yes'){	// Means Successfult done Rating 
						//alert("rate Done SuccessFully " + tot)
						$("#up_count"+tot).html("(" + updated_ups + ")");
						$("#down_count"+tot).html("(" + updated_downs + ")");
						$("#up_down_msg"+tot).hide();
						$("#up_down_msg"+tot).html(errors);
						$("#up_down_msg"+tot).slideDown("slow");
						$("#up_down_msg"+tot).addClass("BgDarkYellow Black");
					}else{
						$("#up_down_msg"+tot).hide();
						$("#up_down_msg"+tot).html(errors);
						$("#up_down_msg"+tot).slideDown("slow");
						$("#up_down_msg"+tot).addClass("BgLightRed Black");
					}
					
					/*$("#doRateProcessing1"+ tot).html("");
					$("#doRateProcessing1"+ tot).slideUp();
					$("#doRateProcessing1"+ tot).html(html);
					$("#doRateProcessing1"+ tot).slideDown("slow");*/

				}
	});	
}	



/// for ratings on comments 
function do_comment_rate(frm,tot){
	//alert("ready");
	$.ajax({	method: "get",
				url: AJAX_SITE_REQUEST_USERS_URL+"check_login.php",
				data: '',
				beforeSend: function(){}, 
				complete: function(){ }, 
				success: function(html){ //so, if data is retrieved, store it in html
					is_login=html;
					if(is_login=='yes'){
						var val=frm.rateValue.value;
						rate_comment(frm,tot);
						return true;
							/*curent_userID = parseInt(document.getElementById("globalCurrentUserID").innerHTML);
							if(parseInt(userID.value)== parseInt(memId.value)){
								$("#up_down_msg").hide();
								$("#up_down_msg").html("You cannot rate on your comment");
								$("#up_down_msg").slideDown("slow");
								$("#up_down_msg").addClass("BgRed White");
								return true;
							}*/
							
					}else{
						var t = null;
						var a = AJAX_SITE_REQUEST_USERS_URL + "short_login_register.php?jsfunc=do_comment_rate&jsfunc_frmref="+frm.name+"&popup&keepThis=true&TB_iframe=true&height=288&width=790";
						var g = false;
						tb_show(t,a,g);
						return false;
					}
				}
	});
	return false;
}

function rate_comment1(frm,tot){
	pollId='';
	CommID='';
	querystring = '';
	with(frm){	
	querystring="&task=comment_rates&CommID="+commentID.value+	
					"&pollId="+pollId.value+"&memId="+memId.value+"&rate="+rateValue.value;
	}
	//alert(querystring);
	$.ajax({ 	method: "get",
				url:AJAX_SITE_REQUEST_POLL_URL+"polls_rate.php",
				data: querystring ,
				beforeSend: function(){ }, //show loading just when link is clicked
				complete: function(){ },  
				success: function(html){ //so, if data is retrieved, store it in html
					xmlDoc=loadXMLString(html);
					x=xmlDoc.documentElement.childNodes;
					rate_result = 'no'; errors =''; total_errors=0; 
					updated_ups=0;	updated_downs=0;
					for (i=0;i<x.length;i++){
						switch(x[i].nodeName){
							case 'state' :			rate_result = x[i].childNodes[0].nodeValue; break;
							case 'total_ups' :		updated_ups= x[i].childNodes[0].nodeValue; break;
							case 'total_downs' :	updated_downs= x[i].childNodes[0].nodeValue; break;
							case 'errors' :			errors = x[i].childNodes[0].nodeValue; break;
							case 'errors_count' : 	total_errors = x[i].childNodes[0].nodeValue;break;
						}
					}
						if(rate_result=='yes'){	// Means Successfult done Rating 
						$("#up_count"+tot).html("(" + updated_ups + ")");
						$("#down_count"+tot).html("(" + updated_downs + ")");
						$("#up_down_msg"+tot).hide();
						$("#up_down_msg"+tot).html(errors);
						$("#up_down_msg"+tot).slideDown("slow");
						$("#up_down_msg"+tot).addClass("BgGreen White");
					}else{
						$("#up_down_msg"+tot).hide();
						$("#up_down_msg"+tot).html(errors);
						$("#up_down_msg"+tot).slideDown("slow");
						$("#up_down_msg"+tot).addClass("BgRed White");
					}
					
					/*$("#doRateProcessing1"+ tot).html("");
					$("#doRateProcessing1"+ tot).slideUp();
					$("#doRateProcessing1"+ tot).html(html);
					$("#doRateProcessing1"+ tot).slideDown("slow");*/

				}
	});	
}	



function do_comment_rating(frm,tot){
	//alert("ready");
	$.ajax({	method: "get",
				url: AJAX_SITE_REQUEST_USERS_URL+"check_login.php",
				data: '',
				beforeSend: function(){}, 
				complete: function(){ }, 
				success: function(html){ //so, if data is retrieved, store it in html
					is_login=html;
					if(is_login=='yes'){
					var val=frm.rateValue.value;
					rate_comment1(frm,tot);
					return true;
							/*curent_userID = parseInt(document.getElementById("globalCurrentUserID").innerHTML);
							if(parseInt(userID.value)== parseInt(memId.value)){
								$("#up_down_msg").hide();
								$("#up_down_msg").html("You cannot rate on your comment");
								$("#up_down_msg").slideDown("slow");
								$("#up_down_msg").addClass("BgRed White");
								return true;
							}*/
							
					}else{
						var t = null;
						var a = AJAX_SITE_REQUEST_USERS_URL + "short_login_register.php?jsfunc=do_comment_rate&jsfunc_frmref="+frm.name+"&popup&keepThis=true&TB_iframe=true&height=288&width=790";
						var g = false;
						tb_show(t,a,g);
						return false;
					}
				}
	});
	return false;
}




// View Closed Poll
function viewClosedPoll(frm){
	//alert("Ready");
	$.ajax({	method: "get",
				url: AJAX_SITE_REQUEST_USERS_URL+"check_login.php",
				data: '',
				beforeSend: function(){}, 
				complete: function(){ }, 
				success: function(html){ //so, if data is retrieved, store it in html
					is_login=html;
					if(is_login=='yes'){
						var pollId = frm.pollId.value;
						var t = null;
						var a = SITE_URL + "index.php?action=polls&task=postShare&pollId="+pollId+"&popup&keepThis=true&TB_iframe=true&height=200&width=250";
					//	var a = "index.php?action=polls&task=pollwinnerlist&pollId="+pollId+"";
						var g = false;
						tb_show(t,a,g);
					}else{
						var t = null;
						var a = AJAX_SITE_REQUEST_USERS_URL + "short_login_register.php?jsfunc=viewClosedPoll&jsfunc_frmref="+frm.name+"&popup&keepThis=true&TB_iframe=true&height=288&width=790";
						var g = false;
						tb_show(t,a,g);
					}
					return false;
				}
	});
	return false;
}

