﻿function ajaxpage(url, containerid, id){

		var path='';
 	$('#'+containerid+'').html('<div align="center">.: Loading :.</div>'); // ajax-r irsen data-g hevleh #id
		$.ajax({
				method: 'html',
				type:'GET',
				url:url,
				cache: false,
				dataType: 'html',
				data: path,
				error: function(){
					alert('Tanii handsan huudas alga bna! / Page not found!');
				},
				success: function(html){
					$('#'+containerid+'').html(html); // ajax-r irsen data-g hevleh #id
				}
		});
}
function addReply(div,val,id){

		document.replyForm.comment.value='';
		$.ajax({
				method: 'html',
				type:'GET',
				url:val,
				cache: false,
				dataType: 'html',
				data: val,
				error: function(){
					alert('Tanii handsan huudas alga bna! / Page not found!');
				},
				success: function(html){
					$('#'+div+'').append(html); // ajax-r irsen data-g hevleh #id
				}
		});
		$('#reply'+id+'').html('');
		return false;
}
function reportabuse(url,div){
			jConfirm('Таны мэдэгдэлд тулгуурлан энэ сэтгэгдэлийг хянах болно!', 'Энэ сэтгэгдэлийг админд мэдэгдэх гэж байгаадаа итгэлтэй байна уу?', function(r) {

							if(r==true){
										$.ajax({
															method: 'html',
															type:'GET',
															url:url,
															cache: false,
															dataType: 'html',
															data: url,
															error: function(){
																alert('Tanii handsan huudas alga bna! / Page not found!');
															},
															success: function(html){
																	$('#'+div+'').html(html); // ajax-r irsen data-g hevleh #id
															}
													});	
								}
			});

}
function formElems(form_id,url) {
	var str = "";
	var frm;
	frm = $("#"+form_id+"").serialize(); 
	str=url+"?"+frm;
	ajaxpage(str,'output_div');
}
function ajaxForm(form_id,url,containId) {
	var str = "";
	frm = document.forms[form_id]; 
	for(i = 0;i < frm.length; i++) {
		if(frm[i].type != "button") {
			str += "&" + frm[i].name + "=" + encodeURIComponent(frm[i].value);
		}
	}
	ajaxpage(url+'?'+str,containId);
}
function get(theForm,div,msg) {
	var radioSelected = false;
	var getstr = "";
	for (i=0; i<theForm.results.length; i++) 
	{
		if (theForm.results[i].checked) 
		{
		getstr += theForm.results[i].name + "=" + theForm.results[i].value+"&"+theForm.chid[i].name + "=" + theForm.chid[i].value + "&id=" +theForm.meta_pollID.value;
		checkedValue = theForm.results[i].value;
		checkedValueChild = theForm.chid[i].value;
		radioSelected = true;
		}
	}
	if (!radioSelected)
	{
		alert(msg);
		return (false);
	}
	else
	{
		ajaxpage('mod/poll/get.php?songolt=module&task=poll&option=poll_result&div='+div+'&'+getstr+'',''+div+'','');
		return (false);
	}
}
function res(val,div) {
	ajaxpage('mod/poll/get.php?songolt=module&task=poll&option=poll_result&div='+div+'&id='+val+'&title=POLL RESULT',''+div+'','');
	return (false)
}

function backRe(val,div) {
	ajaxpage('mod/poll/get.php?songolt=module&task=poll&option=back&div='+div+'&id='+val+'&title=POLL RESULT',''+div+'','');
}
function poll(val,div) {
	ajaxpage('mod_poll.php',''+div+'');
	return (false)
}
function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}
