
// JavaScript Document
var generator = Math.random()*100000;
var tpl_counter=0;
var ans_list=new Array();
function getCookie(c_name){
	
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length
	//alert(c_name+"="+unescape(document.cookie.substring(c_start,c_end)));
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function setCookie(c_name,value,expiredays){
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function set_tblcounter(tbl_cntr){
	alert('sdg');
	//tpl_counter=tbl_cntr;
}
function search_template(pro){
	//alert("come here");
	var flagval=getCookie('flag');
	
	if(pro=='prev' && tpl_counter!=0)
	tpl_counter--;
	else if(pro=='next')
	tpl_counter++;
   	else if(pro=='search')
	tpl_counter=getCookie('tpl_counter');
	//alert(tpl_counter);

	if(tpl_counter==0)$("#prev_template").hide();
	var parametri1 = $("select").serialize();
	var parametri2= "rndtime="+Math.random()*100000;
	var parametri3= "tpl_counter="+tpl_counter;
	//var parametri4= "&"+idval;
	var parametri=parametri1+"&"+parametri2+"&"+parametri3;
	chk_next_tmpl(parametri);
	
	if(flagval == 1){
	ajx_arg("get_template_edit.php","#list",parametri);
	//ajx_arg("get_template_detail.php","#template_detail_addpoll",parametri);
	}
	else
	{
	ajx_arg("get_template.php","#list_preview",parametri);
	ajx_arg("get_template_detail.php","#template_detail",parametri);
	}
	setCookie('tpl_counter',0,1);
	//setCookie('tpl_counter',tpl_counter,1);
	//alert(tpl_counter);
	//show_template(pro,tpl_counter)
}
function del_tpl(tpl_id){
		if(confirm("Are you sure delete?"))
		{
			var parametri="tmpid="+tpl_id;
			$.ajax({
			  url: "delete_template.php",
			  type: "GET",
			  dataType: 'html',
			  data: parametri,
			  timeout: 2000,
			  cache: false,
			  success: function(html){ 
			   if(tpl_counter>0)
			   search_template('prev');
			   else
 			   search_template('next');
			  }
			});
		}
}
function chk_next_tmpl(parametri){
	  $.ajax({
	  url: "check_next_template.php",
	  type: "GET",
	  dataType: 'html',
	  data: parametri,
	  timeout: 2000,
	  cache: false,
	  success: function(html){ 
  	   if(html>0){
	   $("#next_template").show();
	   }
	   else{
	   $("#next_template").hide();
	   }
	   //call_paging(pgid,perpage,time);
	  }
	});
}
function ajx_arg(url,res_id,parametri){ //alert('comes');
	  $.ajax({
	  url: url,
	  type: "GET",
	  dataType: 'html',
	  data: parametri,
	  timeout: 2000,
	  cache: false,
	  success: function(html){ 
	 //alert(html);
	   $(res_id).html(html);
	   //call_paging(pgid,perpage,time);
	  }
	});

}

//adsense
function save_adsense(){
	var parametri1 = $("input").serialize();
	var parametri2 = $("textarea").serialize();
	var parametri3= Math.random()*100000;
	var parametri=parametri1+"&"+parametri2+"&"+parametri3;
	save_process('modules/save_adsense.php','GET','html',parametri,success_adsense);
}

function forgot_pass(){
	var parametri1 = $("input").serialize();
	var parametri2= Math.random()*100000;
	var parametri=parametri1+"&"+parametri2;
	save_process('modules/forgot_password/fp_process.php','GET','html',parametri,success_fp_process);

}

function save_gsetting(){
	var parametri1 = $("input").serialize();
	var parametri2 = $("textarea").serialize();
	var parametri3= Math.random()*100000;
	var parametri=parametri1+"&"+parametri2+"&"+parametri3;
	save_process('../../../admin/modules/general_setting/save_gsetting.php','GET','html',parametri,success_gsetting);
}
function save_loginuser(){
	var parametri1 = $("input").serialize();
	var parametri2 = $("textarea").serialize();
	var parametri3= Math.random()*100000;
	var parametri=parametri1+"&"+parametri2+"&"+parametri3;
	save_process('../../../admin/modules/general_setting/save_loginuser.php','GET','html',parametri,success_gsetting);
}


function success_gsetting(html){
   parent.tb_remove();
   tb_init('a.meem,a.thickbox, area.thickbox, input.thickbox');
}


function success_adsense(html){

}


function success_fp_process(html)
{
	$("#error_status").text(html);
}

function save_tmp_data(id,url,time){
var parametri1 = $("input").serialize();
var parametri2 = $("select").serialize();
var parametri3="tmptype="+get_tmp_radio_value();
var parametri4="tmpid="+id;
var parametri5="chart_type="+$("input[@name='chart_type']:checked").val();
var parametri6="time="+time;
var parametri = parametri1 + "&"+ parametri2 +  "&" + parametri3 + "&" + parametri4 + "&" + parametri5;
	$.ajax({
	  url: url,
	  type: "GET",
	  dataType: 'html',
	  data: parametri,
	  timeout: 2000,
	  cache: false,
	  success: function(html){ 
	  	 //alert(html);
		 $("#status").show();	
	     $("#status").html(html);
	  }
	});
}

function back(url,tpl_ctr){
	document.location.href=url;
	setCookie('tpl_counter',tpl_ctr,1);
}
function goto(url){
	document.location.href=url;
}

//save user data
function save_cat_data(id,pgid,perpage,url,time){
var parametri1 = $("input").serialize();
var parametri2 = $("select").serialize();
var parametri3="catid="+id;
var parametri4="time="+time;
var parametri = parametri1 + "&"+ parametri2 +  "&" + parametri3 + "&" + parametri4;
	$.ajax({
	  url: url,
	  type: "GET",
	  dataType: 'html',
	  data: parametri,
	  timeout: 2000,
	  cache: false,
	  success: function(html){
		  //alert(html);
	  if(html=='dublicate')
	  {
		alert("Category already exist");  
	  }
	  else
	  {
	   parent.tb_remove();
	   tb_init('a.meem,a.thickbox, area.thickbox, input.thickbox');
	   call_paging(pgid,perpage,time);
	  }
	  }
	});
	
}
function trim(strText) { 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;

   ////return str;
} 

function save_google_ads(id,pgid,perpage,url,time){
	//alert("come here");
var script1 =trim($("#descriptions").val());	
var parametri1 = $("input").serialize();
var parametri2 = $("textarea").serialize();
var image1 = trim($("#idimg1").val());

//alert('image'+image1);
var parametri3="id="+id;

 
var parametri4="time="+time;
var ty =get_radio_value();
var parametri5 ="type="+get_radio_value();
var flag = 0;
 
if(ty == 1)
{
	
	if(trim(script1)=='')
	{
		alert("Update Falied Script value is NULL ");
	   	flag = 1;
	}

}
else
{
   
   if(image1=='')
   {
			alert("Update Falied Browse Image value is NULL ");
	   	    flag = 1;
	}

}
//alert('flag'+ flag);
if(flag == 0)
{
	
var parametri = parametri1 + "&"+ parametri2 +  "&" + parametri3 + "&" + parametri4+ "&" + parametri5;
	//alert(type);
	
	$.ajax({
	  url: url,
	  type: "GET",
	  dataType: 'html',
	  data: parametri,
	  timeout: 2000,
	  cache: false,
	  success: function(html){ 
	// alert(html);
	   parent.tb_remove();
	   tb_init('a.meem,a.thickbox, area.thickbox, input.thickbox');
	   call_paging(pgid,perpage,time);
	  }
	});
}
}

function save_user_data(id,pgid,perpage,url,time){
var parametri1 = $("input[@type=text]").serialize();
var parametri2 = get_allocate_days();
var parametri3="pgid="+id;
var parametri4="time="+time;
var parametri5 = $("input[@type=password]").serialize();
var parametri = parametri1 + "&"+ parametri2 +  parametri3 + "&" + parametri5;
	$.ajax({
	  url: url,
	  type: "GET",
	  dataType: 'html',
	  data: parametri,
	  timeout: 2000,
	  cache: false,
	  success: function(html){ 
	   parent.tb_remove();
	   tb_init('a.meem,a.thickbox, area.thickbox, input.thickbox');
	   call_paging(pgid,perpage,time);
	  }
	});
	
}


function get_allocate_days(){
	var daychk="";
	var f=document.forms['editfrm'];
	for(var i = 0; i < f.elements.length; i++)
	      if(f.elements[i].type == 'checkbox')
			if(f.elements[i].checked) daychk+="day"+f.elements[i].value+"=1&";
	return daychk;		
}

function save_process(url,method,return_type,arg,function_name)
{
	 $.ajax({
	  url: url,
	  type: method,
	  dataType: return_type,
	  data: arg,
	  timeout: 2000,
	  cache: false,
	  success: function(html){
		  function_name(html);
	  },
	  error:function(sad){
		  //alert(sad.responseText)
		
	  }
	});

}
function ajx_set_tmp(){

	if(get_check_bgcolor()){
	var color1=$("#color1").val();
	$("#bg_poll").css("background",color1);
	}
	//alert($(".stemmen").html());
	var color2=$("#color2").val();
	$("#toplinks a").css("color",color2);
	var color3=$("#color3").val();
	$("#placepoll a").css("color",color3);
	var color4=$("#color4").val();
	$("#question").css("color",color4);
	var color5=$("#color5").val();
	$(".stemmen").css("color",color5);
	var color6=$("#color6").val();
	$(".comment a").css("color",color6);
	
	//set chart color
	
	
	var chart_from=$("#chart_from").val().split("#");
	var chart_to=$("#chart_to").val().split("#");
	if ($("input[@name='chart_type']:checked").val()=='bar'){
		
		var $img = $('#chart_loader1 img').load(function (){ 
		}).appendTo('chart_loader1').attr('src','create_image.php?w=150&h=7&ff='+chart_from[1]+'&ft='+chart_to[1]); 
	
		var $img = $('#chart_loader2 img').load(function (){ 
		}).appendTo('chart_loader2').attr('src','create_image.php?w=120&h=7&ff='+chart_from[1]+'&ft='+chart_to[1]); 
	
		var $img = $('#chart_loader3 img').load(function (){ 
		}).appendTo('chart_loader3').attr('src','create_image.php?w=90&h=7&ff='+chart_from[1]+'&ft='+chart_to[1]); 
	
		var $img = $('#chart_loader4 img').load(function (){ 
		}).appendTo('chart_loader4').attr('src','create_image.php?w=60&h=7&ff='+chart_from[1]+'&ft='+chart_to[1]); 
	}
	//$("#chart_loader1").html('<img src="create_image.php?w=150&h=7&ff='+chart_from[1]+'&ft='+chart_to[1]+'" align="top" />');
	//$("#chart_loader2").html();
	//$("#chart_loader3").html();

}


function ajx_set_color(){

	if(get_check_bgcolor()){
	var color1=$("#color1").val();
	$("#bg_poll").css("background",color1);
	}
	//alert($(".stemmen").html());
	var color2=$("#color2").val();
	$("#toplinks a").css("color",color2);
	var color3=$("#color3").val();
	$("#placepoll a").css("color",color3);
	var color4=$("#color4").val();
	$("#question").css("color",color4);
	var color5=$("#color5").val();
	$(".stemmen").css("color",color5);
	var color6=$("#color6").val();
	$(".comment a").css("color",color6);
	
	//set chart color
	
	
	var chart_from=$("#chart_from").val().split("#");
	var chart_to=$("#chart_to").val().split("#");
	if ($("input[@name='chart_type']:checked").val()=='bar'){
		
		var $img = $('#chart_loader1 img').load(function (){ 
		}).appendTo('chart_loader1').attr('src','create_image.php?w=150&h=7&ff='+chart_from[1]+'&ft='+chart_to[1]); 
	
		var $img = $('#chart_loader2 img').load(function (){ 
		}).appendTo('chart_loader2').attr('src','create_image.php?w=120&h=7&ff='+chart_from[1]+'&ft='+chart_to[1]); 
	
		var $img = $('#chart_loader3 img').load(function (){ 
		}).appendTo('chart_loader3').attr('src','create_image.php?w=90&h=7&ff='+chart_from[1]+'&ft='+chart_to[1]); 
	
		var $img = $('#chart_loader4 img').load(function (){ 
		}).appendTo('chart_loader4').attr('src','create_image.php?w=60&h=7&ff='+chart_from[1]+'&ft='+chart_to[1]); 
	}
	//$("#chart_loader1").html('<img src="create_image.php?w=150&h=7&ff='+chart_from[1]+'&ft='+chart_to[1]+'" align="top" />');
	//$("#chart_loader2").html();
	//$("#chart_loader3").html();

}

function get_image(id){
generator = Math.random()*100000;
//alert(id);	
arg="id="+id+"&rnd="+generator;
ajx_get_img("get_image.php","get","html",arg);
}	

/*function assign_img(html){
	//alert("SADG");
	$(".s").html(html);
	//alert(html);
}


function ajx_get_img(url,method,return_type,arg)
{
	$.ajax({
	  url: url,
	  type: method,
	  dataType: return_type,
	  data: arg,
	  timeout: 2000,
	  cache: false,
	  success: function(html){
		  //alert(html);
		  assign_img(html);
	  }
	});
}
*/
function ajx_get_img(url,method,return_type,arg,function_name,function_arg)
{
	//alert('ajx_get_img');
	var fn=function_name;
	//alert("fun"+fn);
	var final_val;
	$.ajax({
	  url: url,
	  type: method,
	  dataType: return_type,
	  data: arg,
	  timeout: 2000,
	  cache: false,
	  success: function(html){
          set_bg(html);
	  }
	});

}


function set_bg(html){
	//alert(html);
	var src="url("+html+")";
	//alert(src);
		$("#bg_poll").css("background-image",src);	  
}
function ajx_process(url,method,return_type,arg,function_name,function_arg)
{
	var fn=function_name;
//		alert(function_arg);
	//alert("fun"+fn);
	var final_val;
	$.ajax({
	  url: url,
	  type: method,
	  dataType: return_type,
	  data: arg,
	  timeout: 2000,
	  cache: false,
	  success: function(html){
		//  alert(html);
          fn(html,function_arg);
	  },
	  error: function(sad){
		  //alert("Error");
		  //alert(sad.responseText);
	  }
	});

}
function delete_user(uid,pgid,perpage,url,rand){
	if(uid==1)
	alert("You can't delete Yourself!");
	else{
		if(confirm("Are you sure delete?"))
		processForm(uid,pgid,perpage,url,rand);
	}
}


function delete_audio(aid,pgid,perpage,url,rand){
//	alert (aid);
			if(confirm("Are you sure delete?"))
		processForm(aid,pgid,perpage,url,rand);
	
}


function delete_category(id,pgid,perpage,url,rand){
	if(confirm("Are you sure delete?"))
	processForm(id,pgid,perpage,url,rand);
}

function delete_ads(id,pgid,perpage,url,rand){
	if(confirm("Are you sure delete?"))
	processForm(id,pgid,perpage,url,rand);
}


function processForm(id,pgid,perpage,url,time){
	//alert('comes here'+pgid+"&nbsp;"+perpage);
var parametri1 = $("input").serialize();
var parametri2 = $("textarea").serialize();
var parametri3="pgid="+id;
var parametri4="time="+time;
var parametri = parametri1 + "&"+ parametri2 + "&" + parametri3 + "&" + parametri4;
//alert(parametri);
	$.ajax({
	  url: url,
	  type: "GET",
	  dataType: 'html',
	  data: parametri,
	  timeout: 2000,
	  cache: false,
	  success: function(html){
	   //alert(html);
	    if(html == 'sub_cat')
		alert(" In this category  having Subcategory,  So you could not delete this Category" );
		if(html =='poll')
		alert(" In this category  having poll,  So you could not delete this Category" );
	   parent.tb_remove();
	   tb_init('a.meem,a.thickbox, area.thickbox, input.thickbox');
	   call_paging(pgid,perpage,time);
	  }
	});
}


function inside_thickbox(){
	var generator = Math.random()*100000;
	var pgid=getCookie('ajx_pgid');
	var perpg=getCookie('ajx_perpg');
	call_paging(pgid,perpg,generator);
}


function call_paging(pgid,perpage,time)
{
var generator = Math.random()*100000;
setCookie('ajx_pgid',pgid,1);
setCookie('ajx_perpg',perpage,1);
var iminval=getCookie("iminval");
var imaxval=getCookie("imaxval");
var menu_search=getCookie('ajx_search');
menu_search+='&minval='+iminval+'&maxval='+imaxval;
//var args=$("input").serialize();
//alert(args);
//alert(menu_search);
var url=getCookie('ajx_url');
var pgtype=getCookie('ajx_pgtype');
$.ajax({
  url: url,
  type: "GET",
  dataType: 'html',
  data: "pgtype="+pgtype+"&pageid="+pgid+"&"+menu_search+"&perpage="+perpage+"&randtime="+time+"&time="+generator,
  cache: false,
  success: function(html){	
  
   $('#listrow').attr('innerHTML',html);
   tb_init('a.thickbox, area.thickbox, input.thickbox');
  },
  error:function(sad){
  }
});
}


function call_ajx_search(){
generator = Math.random()*100000;
arg= $("input[@type=text]").serialize();
arg+='&usertype='+get_check_value();
setCookie('ajx_search',arg,365);
var perpg=getCookie('ajx_perpg');
call_paging(1,perpg,generator); 
}

function call_ajx_poll_search(){ //alert('search');
generator = Math.random()*100000;
var iminval=getCookie("iminval");
var imaxval=getCookie("imaxval");
arg= $("input[@type=text]").serialize();
arg+='&type='+get_polltype_radio_value();
arg+='&minval='+iminval+'&maxval='+imaxval;
arg+='&'+$("select").serialize();
//alert(arg);
setCookie('ajx_search',arg,365);
var perpg=getCookie('ajx_perpg');
call_paging(1,perpg,generator); 
}

function call_ajxaudio_search(){
generator = Math.random()*100000;
arg= $("input[@type=text]").serialize();
setCookie('ajx_search',arg,365);
var perpg=getCookie('ajx_perpg');
call_paging(1,perpg,generator); 
}

function call_ajx_cat_search()
{
var generator = Math.random()*100000;
var arg= $("select").serialize();

var r = arg.match(/[\d\.]+/g);
//alert(r[0]);
//alert(arg);

var catarg= arg.split("&");
var subcat_split=catarg[1].split("=");
var t_subcat=subcat_split[1];
var subcat = t_subcat.match(/[\d\.]+/g);
//alert(subcat);
arg +='&'+$("input[@type=text]").serialize();
setCookie('ajx_search',arg,365);
var pgid=getCookie('ajx_pgid');
var perpg=getCookie('ajx_perpg');
call_paging(pgid,perpg,generator); 
arg+="time="+generator;
ajx_process('modules/get_sub_category.php','GET','html',arg,get_sub_category,subcat);
}

function call_ajx_cat_search1(){ //alert('comes here');
var generator = Math.random()*100000;
var arg= $("select").serialize();
//alert(arg);
var catarg= arg.split("&");
var subcat_split=catarg[2].split("=");
var subcat=subcat_split[1];

arg +='&'+$("input[@type=text]").serialize();
arg+='&type='+get_polltype_radio_value();

setCookie('ajx_search',arg,365);

var pgid=getCookie('ajx_pgid');
var perpg=getCookie('ajx_perpg');
call_paging(pgid,perpg,generator); 
arg+="time="+generator;
//if(subcat==0)
//alert('subcat:'+subcat);
ajx_process('modules/get_sub_category.php','GET','html',arg,get_sub_category,subcat);

//alert('comes here');
 //search_frm.sub_category.subcat.selected=true;
}

function get_sub_category(html,subcat){ 

  objectSubcategory=document.getElementById('sub_category');
  for( var i = objectSubcategory.options.length-1; i >= 1; i--)
  {
   objectSubcategory.remove(i);
  }
   	//alert(subcat);
 var subst;
 var optcount=0;
 subst=html;
//alert(subst);
 var optcount=0;
 if(subst){
	 	 var subarr=subst.split(",");
	 	 var full_arr=new Array();
		 var key_arr=new Array();
		 var value_arr=new Array();

		 for(var i=0;i<subarr.length;i++)
			 full_arr[i]=subarr[i];

		for(var i=0;i<full_arr.length;i++){
			var tmp_list =full_arr[i].split(';');
			key_arr[i]=tmp_list[0];
			value_arr[i]=tmp_list[1];
		}
		
		 for(var i=0;i<full_arr.length;i++){
		 optcount+=1;
		// alert(key_arr[i]+"=>"+value_arr[i]);
		 search_frm.sub_category.options[optcount] = new Option(value_arr[i],key_arr[i]);
			 if(key_arr[i]==subcat) 
			 search_frm.sub_category.options[optcount].selected=true;
		}


 }
}


 function change_chart(type){
 var time = Math.random()*100000;
/*	$.ajax({
	  url: type+'_chart.php',
	  type: "GET",
	  dataType: 'html',
	  data: "randtime="+time,
	  cache: false,
	  success: function(html){	
	   $('#divtext').html(html);
	  },
	  error:function(sad){
	  }
	});
*/	 
	if(type=='bar'){
		$("#bar_chart").show();
		$("#column_chart").hide();
		$("#cylinder_chart").hide();
	}
	else if(type=='column'){
		$("#bar_chart").hide();
		$("#column_chart").show();
		$("#cylinder_chart").hide();
	}
	else if(type=='cylinder'){
		$("#bar_chart").hide();
		$("#column_chart").hide();
		$("#cylinder_chart").show();
	}
}


function get_check_bgcolor()
{
  if(document.editfrm.bckgnd_color.checked)
  {
	  return true;
  }
  else
	return false;
}
//function get_check_value()
//{
//var initobj1=Object(document.register.initial[0]);
//		var initobj2=Object(document.register.initial[1]);
//		if(initobj1.checked)
//			 return initobj1.value;
//		if(initobj2.checked)
//			return initval=initobj2.value;
//}

function get_check_value()
{

  var usertype;
  if(document.search_frm.search_utype1.checked)
  {
	  usertype = document.search_frm.search_utype1.value;
	  if(document.search_frm.search_utype2.checked)
	  {
	  usertype += ","+document.search_frm.search_utype2.value;
	  }
	  
  }
  else
  {
	  if(document.search_frm.search_utype2.checked)
	  {
	  usertype= document.search_frm.search_utype2.value;
	  }
	  else
	  usertype='';
	  
	  

  }
	return usertype;
}



function get__polltype_checkvalue()
{
	var polltype;
	if(document.search_frm.polltype.checked)
    {
	  polltype = document.search_frm.polltype.value;
	}
	else
	{
		polltype='0';
	}
	return polltype;
}


function get_radio_value()
{
 //var polltype;
//  if(document.search_frm.search_utype1[0].checked)
//  {
//	  polltype = document.search_frm.search_utype1[0].value;
//  }
//  else
//  {	
//	if(document.search_frm.search_utype1[1].checked)
//  	{
//	  polltype = document.search_frm.search_utype1[1].value;
//  	}

  var tmptype;
  if(document.addfrm.type1[0].checked)
  {
	  tmptype = document.addfrm.type1[0].value;
	  //alert(tmptype);
  }
  else
  {
	  
	  tmptype='0';

  }
   //alert(tmptype);
	return tmptype;
}

function get_tmp_radio_value()
{

  var tmptype;
  if(document.editfrm.bckgnd_color.checked)
  {
	  tmptype = document.editfrm.bckgnd_color.value;
  }
  else
  {
	  if(document.editfrm.bckgnd_image.checked)
	  {
	  tmptype= document.editfrm.bckgnd_image.value;
	  }
	  else
	  tmptype='0';

  }
	return tmptype;
}



function DoCustomValidation(f)
{
  var frm = document.forms['editfrm'];
  
  if(frm.pass.value || frm.repass.value)
  {
	  if(frm.pass.value != frm.repass.value)
	  {
		alert('Wachtwoord komt niet overseen');
		frm.pass.value='';
		frm.repass.value='';
		frm.pass.focus();
		return false;
	  }
	  else
	    return true;	
  }	  
  else
    return true;
  
}


function setapproved(pid,pgid,perpage,url,rand){
	
		processForm(pid,pgid,perpage,url,rand);
}

function add_poll(url, s)
{
	
	//alert(url);
	
	var closdat=document.getElementById("closedate");
	var hour=document.getElementById("hour");
	var minute=document.getElementById("minute");
	var category=document.getElementById("category");
	var sub_category=document.getElementById("sub_category");
	var question=document.getElementById("question");
	var keyword=document.getElementById("keyword");
	var description=document.getElementById("description");
	
	serial = $.SortSerialize(s);
	ans_list=(serial.hash).split("&");
	

	
	
if (isDate_2(closdat.value)==false){ //alert('comes here');
	}
	else if(isNaN(hour.value))
	{
		//alert(hour);
	}
	else if(hour.value>24)
	{
		//alert(hour);
	}
	else if(isNaN(minute.value))
	{
		//alert(minute);
	}
	else if(minute.value>60)
	{
	}
	else if(category.value == 0)
	{
		alert("Select Category");
	}
	//else if(sub_category.value == 0)
//	{
//		alert("Select  Sub Category");
//	}
    else
	{
		
	//alert('correct path');

	
	
	
	var arg= $("input[@type=text]").serialize();
	for(var i=0;i<ans_list.length;i++){
		var key=ans_list[i].split("=");
		arg+='&'+"option"+ i+"="+($("#"+key[1]+" .editable").attr("title"));
		//option=($("#"+key[1]+" .editable").html());
	}
	 
	arg+='&'+ $("select").serialize()+"&time="+generator;
	//arg+='&polltype='+get__polltype_checkvalue();
    //alert(arg);
	//alert(url);
	$.ajax({
	  url: url,
	  type: "GET",
	  dataType: 'html',
	  data: arg,
	  timeout: 2000,
	  cache: false,
	  success: function(html){
	  //alert(html);
	  
	  if(html == "success")
	  {
		  $("#responsedisp").html("Successfully Saved");
		  $("#responsedisp").focus();
	  }
	  // alert($("#response").innerHTML);
	  },
	  error: function(sad){
		 // alert("Error");
		  //alert(sad.responseText);
		  
	  }
	});
	}
	//alert('test');
}
function save_poll(url,s)
{
	var flag=s;
	//alert(flag);
	var ansarry = new Array();
	var anskey = new Array();
	
	serial = $.SortSerialize("Answer_list");
	ans_list=(serial.hash).split("&");
	
	
	for(var i=0;i<ans_list.length;i++){
		var key=ans_list[i].split("=");
		anskey[i]=key[1];
		ansarry[i]=($("#"+key[1]+" #ans_text").attr("title"));
		//alert($("#"+key[1]+" #ans_text").html());
	}
	//alert('jsfun:'+ansarry);
	//alert('jsfun:'+anskey);
//	
	
	var closdat=document.getElementById("closedate");
	var hour=document.getElementById("hour");
	var minute=document.getElementById("minute");
	//var minute=document.getElementById("minute");
	//var minute=document.getElementById("minute");
	//var ques=document.getElementById("question");
	var ques=Object(document.search_frm.question);
	//alert(ques);
	var cate=document.getElementById("cate");
	var subcat=document.getElementById("sub_category");
	
	var tmpobj=document.getElementById("tmp");
	var tmpcatobj=document.getElementById("tmpcat");
	var keywordobj=document.getElementById("keyword");
	if (isDate_2(closdat.value)==false){ //alert('comes here');
	}
	else if(hour.value=="")
	{
		alert("Enter Valid Hour");
	}
	else if(isNaN(hour.value))
	{
		alert("Hour Only Numbers");
	}
	else if(hour.value>24)
	{
		alert("Enter valid Hour");
	}
	else if(minute.value=="")
	{
		alert("Enter Valid Minutes");
	}
	else if(isNaN(minute.value))
	{
		alert("Minutes only Numbers");
	}
	else if(minute.value>60)
	{
		alert("Enter valid Minutes ");
	}
	else if(ques.value=="")
	{
		alert("Enter the Poll Question");
	}
	else if(cate.value==0)
	{
		alert("Select Category ");
	}
	else if(tmpcatobj.value==0)
	{
		alert("Select Template Category");
	}
	else if(tmpobj.value==0)
	{
		alert("Select Template Sub category");
	}
	else if(keywordobj.value=="")
	{
		alert("Enter Keywords ");
	}
    else
	{
	var generator = Math.random()*100000;
		
	//var parametri = getCookie("ajx_editpoll")+"&time="+generator;
	var arg= $("input[@type=text]").serialize();
	arg+='&'+$("input[@type=hidden]").serialize();
	arg+='&'+ $("select").serialize()+"&time="+generator;
	arg+='&flag='+flag;
	//alert('fulladdition:'+arg);
	//arg+='&polltype='+get__polltype_checkvalue();
	arg+='&ansarry='+ansarry;
	arg+='&anskey='+anskey;
    //alert(arg);
	//alert(url);
	$.ajax({
	  url: url,
	  type: "GET",
	  dataType: 'html',
	  data: arg,
	  timeout: 2000,
	  cache: false,
	  success: function(html){
	   //alert(html);
	  if(html == "success")
	  $("#response").html("Successfully Saved");
	  $("#topt").focus();
	   //alert($("#respon").html(html));
	  },
	  error: function(sad){
		//  alert("Error");
		//  alert(sad.responseText);
	  }
	});
	}
}

function call_getpollvalue(id,rand)
{
	//alert('comes here');
	var parametri = id;
	var url = "ajax_pollgetvalue.php";
	//alert(parametri);
	
	$.ajax({
	  url: url,
	  type: "GET",
	  dataType: 'html',
	  data: parametri,
	  timeout: 2000,
	  cache: false,
	  success: function(html){
	   //alert(html);
	  }
	});
}


function call_ajx_cat_fetch()
{
	//alert('test');
	var generator = Math.random()*100000;
	var arg=$("select").serialize()
	
	var catarg= arg.split("&");
	var subcat_split=catarg[1].split("=");
	var subcat=subcat_split[1];
	//alert(subcat);
	arg+="&time="+generator;
	ajx_process('get_sub_category.php','GET','html',arg,get_sub_category,subcat);
}

function search_template_edit(idval){
	//alert(idval);
	//alert("come here");
	var flagval=getCookie('flag');
	//alert(flagval);
	var parametri1 = $("select").serialize();
	var parametri2= "rndtime="+Math.random()*100000;
	//var parametri3= "flag="+flagval;
	var parametri4= "&"+idval;
	var parametri=parametri1+"&"+parametri2+"&"+parametri4;
	//alert(parametri);
	
	ajx_arg("get_template_edit.php","#list",parametri);
	//ajx_arg("get_template_detail_edit.php","#list_detail",parametri);
	
	setCookie('tpl_counter',0,1);
}

function search_template_add(){
	var thru = "addpoll";
	var parametri1 = $("select").serialize();

	var parametri2= "rndtime="+Math.random()*100000;
	var parametri3= "thru="+thru;
	//var parametri4= "&"+idval;
	var parametri=parametri1+"&"+parametri2+"&"+parametri3;
	
	ajx_arg("get_template_edit.php","#list",parametri);
}

function get_template_edit(idval){
	//alert(idval);
	var thru="tmp";
	//alert("come here");
	var flagval=getCookie('flag');
	//alert(flagval);
	var parametri1 = $("select").serialize();
	var parametri2= "rndtime="+Math.random()*100000;
	var parametri3= "thru="+thru;
	var parametri4= "&"+idval;
	var parametri=parametri1+"&"+parametri2+"&"+parametri3+"&"+parametri4;
	//chk_next_tmpl(parametri);
	
	ajx_arg("get_template_edit.php","#list",parametri);
	//ajx_arg("get_template_detail.php","#template_detail_addpoll",parametri);
	
	//setCookie('tpl_counter',0,1);
}


function call_ajx_tmpcat_search(){
var generator = Math.random()*100000;
var arg= $("select").serialize();
//alert(arg);
var catarg= arg.split("&");
//alert(catarg);
var via=getCookie("via");
if(via == "political")
	var tmpcat_split=catarg[0].split("=");
else	
	var tmpcat_split=catarg[2].split("=");
var tmpcat=tmpcat_split[1];
//alert(tmpcat);
arg+="time="+generator;

ajx_process('get_tmp_list.php','GET','html',arg,get_tmp_category_select,tmpcat);

}


function get_tmp_category(html,subcat){  //alert('template');

  objectSubcategory=document.getElementById('tmp');
  for( var i = objectSubcategory.options.length-1; i >= 1; i--)
  {
   objectSubcategory.remove(i);
  }
   //	alert('tmp:'+subcat);
 var subst;
 var optcount=0;
 subst=html;
//alert(subst);
 var optcount=0;
 if(subst){
	 	 var subarr=subst.split(",");
	 	 var full_arr=new Array();
		 var key_arr=new Array();
		 var value_arr=new Array();

		 for(var i=0;i<subarr.length;i++)
			 full_arr[i]=subarr[i];

		for(var i=0;i<full_arr.length;i++){
			var tmp_list =full_arr[i].split(';');
			key_arr[i]=tmp_list[0];
			value_arr[i]=tmp_list[1];
		}
		
		 for(var i=0;i<full_arr.length;i++){
		 optcount+=1;
		 //alert(key_arr[i]+"=>"+value_arr[i]);
		 search_frm.tmp.options[optcount] = new Option(value_arr[i],key_arr[i]);
		 //if(subcat==0){
			 if(optcount ==1)
			 	search_frm.tmp.options[optcount].selected=true;
			// }
		
		}
get_template_model2();

 }

}



function call_ajx_cat_editpage(){ //alert('test');
var generator = Math.random()*100000;
var arg= $("select").serialize();
//alert(arg);
var catarg= arg.split("&");
var subcat_split=catarg[1].split("=");
var subcat=subcat_split[1];
arg+="time="+generator;
//alert('arg:'+arg);
ajx_process('get_sub_category.php','GET','html',arg,get_sub_category,subcat);
}

function send_mail(url,rand,f)
{
	//alert(url);
	var arysval=document.getElementById("arys").value;
	var arysval1=document.getElementById("arys1").value;
	
	if(arysval.length==0 && arysval1.length==0)
	{
		alert('Select any user');
	}
	
	else
	{
	var generator = Math.random()*100000;
	var parametri1 = $("input").serialize();
	var parametri2 = $("textarea").serialize();
	var parametri3="time="+generator;
	var parametri = parametri1 + "&"+ parametri2 + "&" + parametri3;

	$.ajax({
	  url: url,
	  type: "GET",
	  dataType: 'html',
	  data: parametri,
	  timeout: 2000,
	  cache: false,
	  success: function(html){
	   if(html == "success")
	   		$("#respons").html("Successfully Sent");
	   else
	   		$("#respons").html("Failed to Sent");	
		
		 //alert($("#response").html());
	  },
	  error: function(sad){
		  //alert("Error");
		 // alert(sad.responseText);
	  }
	});
	}
	
}

function emailsearch()
{
enerator = Math.random()*100000;
arg= $("input[@type=text]").serialize();
//alert(arg);
setCookie('ajx_search',arg,365);
var perpg=getCookie('ajx_perpg');
call_paging(1,perpg,generator); 
}


function get_polltype_radio_value()
{
//alert('comes here');
  var polltype;
  if(document.search_frm.search_utype1[0].checked)
  {
	  polltype = document.search_frm.search_utype1[0].value;
  }
  else
  {	
	if(document.search_frm.search_utype1[1].checked)
  	{
	  polltype = document.search_frm.search_utype1[1].value;
  	}

  }
  //alert(polltype);
	return polltype;
}

function delete_poll(uid,pgid,perpage,url,rand){
	
	if(confirm("Are you sure delete?"))
		processForm(uid,pgid,perpage,url,rand);
	
}

function poll_day(uid,pgid,perpage,url,rand){
	var rand = Math.random()*100000;
	processForm(uid,pgid,perpage,url,rand);
}


function delete_option(optid,time)
{
	var parametri='optid='+optid+'&time='+time;
	//alert(parametri);
	var url = "delete_option.php";
	$.ajax({
	  url: url,
	  type: "GET",
	  dataType: 'html',
	  data: parametri,
	  timeout: 2000,
	  cache: false,
	  success: function(html){
	   //alert(html);
	     
	  },
	  error: function(sad){
		  //alert("Error");
		 // alert(sad.responseText);
	  }
	});
}


function save_political_poll(url,s)
{
	var flag=s;
	var ansarry = new Array();
	var anskey = new Array();
	
	serial = $.SortSerialize("Answer_list");
	ans_list=(serial.hash).split("&");
	
	for(var i=0;i<ans_list.length;i++){
		var key=ans_list[i].split("=");
		anskey[i]=key[1];
		ansarry[i]=$("#"+key[1]+" #ans_text").attr("title");
		//alert($("#"+key[1]+" #ans_text").html());
	}
	
	var closdat=document.getElementById("closedate");
	var hour=document.getElementById("hour");
	var minute=document.getElementById("minute");
	var ques=Object(document.search_frm.question);
	
	var tmpobj=document.getElementById("tmp");
	var tmpcatobj=document.getElementById("tmpcat");
	var keywordobj=document.getElementById("keyword");
	
	if(ques.value=="")
	{
		alert("Enter the Poll Question");
		ques.focus();
	}
	else if(keywordobj.value=="")
	{
		alert("Enter Keywords");
		keywordobj.focus();
	}
	else if (isDate_2(closdat.value)==false){ //alert('comes here');
	}
	else if(hour.value=="")
	{
		alert("Enter Valid Hour");
		hour.focus();
	}
	else if(isNaN(hour.value))
	{
		alert("Hour Only Numbers");
		hour.focus();
	}
	else if(hour.value>24)
	{
		alert("Enter valid Hour");
		hour.focus();
	}
	else if(minute.value=="")
	{
		alert("Enter Valid Minutes ");
		minute.focus();
	}
	else if(isNaN(minute.value))
	{
		alert("Minutes only Numbers");
		minute.focus();
	}
	else if(minute.value>60)
	{
		alert("Enter valid Minutes");
		minute.focus();
	}
	
	else if(tmpcatobj.value==0)
	{
		alert("Select Template Category ");
		tmpcatobj.focus();
	}
	else if(tmpobj.value==0)
	{
		alert("Select Template Sub category ");
		tmpobj.focus();
	}
	
    else
	{
	var generator = Math.random()*100000;
		
	var arg= $("input[@type=text]").serialize();
	arg+='&'+$("input[@type=hidden]").serialize();
	arg+='&'+ $("select").serialize()+"&time="+generator;
	arg+='&flag='+flag;
	arg+='&ansarry='+ansarry;
	arg+='&anskey='+anskey;
   
   $.ajax({
	  url: url,
	  type: "GET",
	  dataType: 'html',
	  data: arg,
	  timeout: 2000,
	  cache: false,
	  success: function(html){
	  // alert(html);
	  if(html == "success")
	  $("#response").html("Successfully Saved");
	  $("#loading").focus();
	  // alert($("#response").innerHTML);
	  },
	  error: function(sad){
		//  alert("Error");
		//  alert(sad.responseText);
	  }
	});
	}
}



function call_ajx_search_year()
{
var val=document.search_frm.searchyear.value;
var minval='01/01/'+val;
var maxval='12/31/'+val;
var res=minval+','+maxval;
return res;
}


function list_template(res)
{
	//alert('comes here');
	var generator = Math.random()*100000;
	var url="get_template_model.php";
	var parametri =$("select").serialize()+"&time="+generator;
	//alert(parametri);
	 $.ajax({
	  url: url,
	  type: "GET",
	  dataType: 'html',
	  data: parametri,
	  timeout: 2000,
	  cache: false,
	  success: function(html){ 
	   //alert(html);
	   $("#list").html(html);
	   //call_paging(pgid,perpage,time);
	  }
	});
	 
	var url="get_template_details1.php";
	var parametri =$("select").serialize()+"&time="+generator;
	//alert(parametri);
	 $.ajax({
	  url: url,
	  type: "GET",
	  dataType: 'html',
	  data: parametri,
	  timeout: 2000,
	  cache: false,
	  success: function(html){ 
	   //alert(html);
	   $("#template_detail").html(html);
	   //call_paging(pgid,perpage,time);
	  }
	});
}


function call_ajx_tmpcat_search1(){
	
	var generator = Math.random()*100000;
	var arg= $("select").serialize();
	var catarg= arg.split("&");
	var tmpcat_split=catarg[0].split("=");
	var tmpcat=tmpcat_split[1];
	arg+="time="+generator;
//	var url = "get_tmp_list.php";
	ajx_process('get_tmp_list.php','GET','html',arg,get_tmp_category_select,tmpcat);
	//get_template_model();
}


function call_ajx_tmpcat_search2(){
	
	var generator = Math.random()*100000;
	var arg= $("select").serialize();
	var catarg= arg.split("&");
	var tmpcat_split=catarg[0].split("=");
	var tmpcat=tmpcat_split[1];
	arg+="time="+generator;
//	var url = "get_tmp_list.php";
	ajx_process('get_tmp_list.php','GET','html',arg,get_tmp_category_select,tmpcat);
	get_template_model();
}


function get_template_model(){ //alert('model');

	var thru="tmp";
	var parametri1 = $("select").serialize();
	var parametri2= "rndtime="+Math.random()*100000;
	var parametri3= "thru="+thru;
	var parametri=parametri1+"&"+parametri2+"&"+parametri3;

	ajx_arg("get_template_model.php","#list",parametri);
	
	ajx_arg("get_template_details1.php","#template_detail",parametri);
}

function get_template_model2(){ //alert('model');

	var thru="tmp";
	var parametri1 = $("select").serialize();
	var parametri2= "rndtime="+Math.random()*100000;
	var parametri3= "thru="+thru;
	var parametri=parametri1+"&"+parametri2+"&"+parametri3;
	//alert(parametri);
	ajx_arg("manage_templates/get_template_model.php","#list10",parametri);
}

function get_template_model3(tmp){ //alert('model');

	var thru="tmp";
	var parametri1 = "id="+tmp;
	var parametri2= "rndtime="+Math.random()*100000;
	var parametri3= "thru="+thru;
	var parametri=parametri1+"&"+parametri2+"&"+parametri3;
	//alert(parametri);
	ajx_arg("get_template_viewpage.php","#listtemp",parametri);
}

//// Front End
function search_template_front(idval){
	//alert(idval);
	//alert("come here");
	var flagval=getCookie('flag');
	//alert(flagval);
	var parametri1 = $("select").serialize();
	var parametri2= "rndtime="+Math.random()*100000;
	//var parametri3= "flag="+flagval;
	var parametri4= "&"+idval;
	var parametri=parametri1+"&"+parametri2+"&"+parametri4;
	//alert(parametri);
	
	ajx_arg("../admin/modules/get_template_edit.php","#listtemp",parametri);
	//ajx_arg("get_template_detail_edit.php","#list_detail",parametri);
}


function image_insert()
{
	alert('comes here');
	var generator = Math.random()*100000;
	var url="image_insert.php";
	var parametri ="time="+generator;
	 $.ajax({
	  url: url,
	  type: "GET",
	  dataType: 'html',
	  data: parametri,
	  timeout: 2000,
	  cache: false,
	  success: function(html){ 
	   alert(html);

	  }
	});
	 
}
////


