
//for tags validation
function fn_validation(e) {
var keycode;
if(window.event) {
    keycode=window.event.keyCode;
}
else if(e) {
    keycode=e.which;
}
if((keycode == 0) || (keycode == 8) || (keycode >= 65 && keycode <= 90) || (keycode >= 97 && keycode <=122) ||(keycode >=48 && keycode <= 57)) {}
else { return false;}
}
//tags validation ends


//Char validation
function fn_chkchar(e){
	var keycode;if(window.event){	keycode = window.event.keyCode;}
	else if(e){ keycode = e.which;}
	if((keycode == 0) || (keycode == 8) || (keycode >= 65 && keycode <= 90) || (keycode >= 97 && keycode <= 122) || (keycode == 32) || (keycode == 47)  || (keycode >= 48 && keycode <= 57) || (keycode == 95) || (keycode == 45) || (keycode == 46)) 
	{}
	else {return false;}}
//Char validation ends


// Email Validation
function fn_email(e){
	var keycode;if(window.event){	keycode = window.event.keyCode;}
	else if(e){ keycode = e.which;}
	if((keycode == 0) || (keycode == 8) || (keycode >= 65 && keycode <= 90) || (keycode >=97 && keycode <= 122) || (keycode == 32) || (keycode == 64) || (keycode == 46) || (keycode == 47)  || (keycode >=48 && keycode <= 57) || (keycode == 95) || (keycode == 45)) 
	{}
	else {return false;}
}
//Email validation ends

//for popup box
/******************************************
* Popup Box- By Jim Silver @ jimsilver47@yahoo.com
* Visit http://www.dynamicdrive.com/ for full source code
* This notice must stay intact for use
******************************************/
var ns4=document.layers
var ie4=document.all
var ns6=document.getElementById&&!document.all

//drag drop function for NS 4////
var dragswitch=0
var nsx
var nsy
var nstemp

function drag_dropns(name){
if (!ns4)
return
temp=eval(name)
temp.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP)
temp.onmousedown=gons
temp.onmousemove=dragns
temp.onmouseup=stopns
}

function gons(e){
temp.captureEvents(Event.MOUSEMOVE)
nsx=e.x
nsy=e.y
}
function dragns(e){
if (dragswitch==1){
temp.moveBy(e.x-nsx,e.y-nsy)
return false
}
}

function stopns(){
temp.releaseEvents(Event.MOUSEMOVE)
}
//drag drop function for ie4+ and NS6////

function drag_drop(e){
if (ie4&&dragapproved){
crossobj.style.left=tempx+event.clientX-offsetx
crossobj.style.top=tempy+event.clientY-offsety
return false
}
else if (ns6&&dragapproved){
crossobj.style.left=tempx+e.clientX-offsetx+"px"
crossobj.style.top=tempy+e.clientY-offsety+"px"
return false
}
}

function initializedrag(e){
crossobj=ns6? document.getElementById("showimage") : document.all.showimage
var firedobj=ns6? e.target : event.srcElement
var topelement=ns6? "html" : document.compatMode && document.compatMode!="BackCompat"? "documentElement" : "body"
while (firedobj.tagName!=topelement.toUpperCase() && firedobj.id!="dragbar"){
firedobj=ns6? firedobj.parentNode : firedobj.parentElement
}

if (firedobj.id=="dragbar"){
offsetx=ie4? event.clientX : e.clientX
offsety=ie4? event.clientY : e.clientY

tempx=parseInt(crossobj.style.left)
tempy=parseInt(crossobj.style.top)

dragapproved=true
document.onmousemove=drag_drop
}
}
document.onmouseup=new Function("dragapproved=false")
////drag drop functions end here//////

function hidebox(){
crossobj=ns6? document.getElementById("showimage") : document.all.showimage
if (ie4||ns6)
crossobj.style.visibility="hidden"
else if (ns4)
document.showimage.visibility="hide"
}
//pop up box ends

//for latest news 
var xmlHttp;
function showlatestnews(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }
var url="lat-news.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("latestnews").innerHTML=xmlHttp.responseText;
 } 
}
//latest news script ends

//for add favorite 
function favourite(tid,catid)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }
var url="addfavourite.php";
url=url+"?type="+tid;
url=url+"&category="+catid;
xmlHttp.onreadystatechange=stateChanged1;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged1() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("favourite").innerHTML=xmlHttp.responseText;
 } 
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
//add favorite ends

//Script to store Result Graph
OFC = {};
		 
		OFC.none = {
		    name: "pure DOM",
		    version: function(src) { return document.getElementById(src).get_version() },
		    rasterize: function (src, dst) {
		      var _dst = document.getElementById(dst)
		      e = document.createElement("div")
		      e.innerHTML = Control.OFC.image(src)
		      _dst.parentNode.replaceChild(e, _dst);
		    },
		    image: function(src) {return "<img src='data:image/png;base64," + document.getElementById(src).get_img_binary() + "' />"},
		    popup: function(src) {
		        var img_win = window.open('http://www.opinionpoll.in/tmp/test.html', 'Charts: Export as Image')
		        with(img_win.document) {
					//WriteFile("<html><head><title>Charts: Export as Image<\/title><\/head><body>" + Control.OFC.image(src) + "<\/body><\/html>");
		            write("<html><head><title>Charts: Export as Image<\/title><\/head><body><form><input type='hidden' id='grap' value='" + Control.OFC.image(src) + "'></form>" + Control.OFC.image(src) + "<\/body><\/html>") }
		     }
		}
		 
		if (typeof(Control == "undefined")) {
		        var Control = {OFC: OFC.none}
		}
		 
		function save_image() { 
		        //Control.OFC.popup('viewresult')
				//Control.OFC.image('viewresult')
				//Control.OFC.rasterize('viewresult', 'img_chart_1');
		}

// The chart object
function chart(name) {
	this.name = name;
 
	this.image_saved = function(id) {
		alert('saved:'+this.name+', id:'+id );
	};
}
 
// create a new chart object
var viewresult = new chart('chart1');
function done(id)
{
	//alert("Finished upload. Id:"+id);
}
 
function post_image(debug) {
	var fname = document.getElementById("gra-name").value;
	url = "http://www.opinionpoll.in/ofc-library/ofc_upload_image.php?name="+fname+".png";
	//alert(url);
 	//setTimeout("alert('Thanks for Downloading')",10000);
	//
	// call the save function in the flash chart,
	// ofc == open flash chart
	// call the done() function when the image has been POSTed
	//
	var ofc = findSWF("viewresult");
	x = ofc.post_image( url, 'done', debug );
}
 
function post_image_2(debug)
{
	var fname = document.getElementById("gra-name").value;
	url = "http://www.opinionpoll.in/ofc-library/ofc_upload_image.php?name="+fname+".png";
	var ofc = findSWF("viewresult");
	// call our objects image_saved() method when finished
	x = ofc.post_image( url, 'viewresult.image_saved', debug );
}
 
function ofc_ready()
{
	//alert('ofc_ready');
	//setTimeout("post_image()",10000);
}
 
function findSWF(movieName) {
	if (navigator.appName.indexOf("Microsoft")!= -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}


//Script to store Result Graph ends
//For new tag script
var xmlHttp
	function addtags(pqid){
					xmlHttp=GetXmlHttpObject();
					if (xmlHttp==null)	  {
					  alert ("Your browser does not support AJAX!");
					  return;
					  } 
					var net = document.getElementById("newtags").value;				
					document.getElementById("newtags").value = '';
					document.getElementById("newt").style.display="none";
					document.getElementById("addnew").style.display="";
					var url="http://www.opinionpoll.in/modules/poll/newtag.php?pqid="+pqid+"&tag="+net;
					xmlHttp.onreadystatechange=stateChanged7;
					xmlHttp.open("GET",url,true);
					xmlHttp.send(null);
				}
				
				function stateChanged7(){
					if (xmlHttp.readyState==4){ 
						document.getElementById("newtag-span").innerHTML=xmlHttp.responseText;
					}
				}
				
				function GetXmlHttpObject(){
					var xmlHttp=null;
					try  {
						xmlHttp=new XMLHttpRequest();
					}
					catch (e) {
					  try {
							xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
					  }
					  catch (e){
						xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
					  }
					}
					return xmlHttp;
				}
				function showadd() {
					document.getElementById("newt").style.display="";
					document.getElementById("addnew").style.display="none";
				}
				function showadd_an() {
					alert("Please Login to add Tags to this poll");
				}
//New tag script ends

function vote_check(e,popid,pid,alpid, chek)
{
 // TO VALID THE VOTE OPTION
 var pollans = document.getElementById('pollans').value;
 var count=0;
 for(i = 0;i < document.vote.pollans.length;i++) {
 	if(document.vote.pollans[i].checked == true) {
	count = count+1;
	}
 }
	var checked=count;
if(checked == 0) {
	alert('Please choose an option before vote!');
	return false;
}	
else {
	   if(checked != 0){
              document.vote.submit();
	       //var rand = Math.random();
         /* $.get('modules/poll/captcha_login.php?target=viewdetails',{popid:popid,rand:rand,pid:pid,alpid:alpid,pollans:pollans},
           function (resp)
           {
                document.getElementById('viewresult').style.display = 'none';
                var windowWidth  = document.documentElement.clientWidth - 200;
                var windowHeight = document.documentElement.clientHeight;
                var popupHeight  = $("#add_sub_forms").height()+450;
                var popupWidth   = $("#add_sub_forms").width()+320;

                var mousex = e.clientX;////to get mouse position x axis
                var mousey = e.clientY;////to get mouse position y axis

                $('#add_sub_forms').css({'left' : 400,'top' : 350});////set the css for popup using jquery
                $("#add_sub_forms").css({"opacity": "0.7"});

                $("#backgroundPopup").css({"opacity": "0.7","height": windowHeight});  
                $("#backgroundPopup").fadeIn(30);
                $("#add_sub_forms").fadeIn(30);
                document.getElementById('add_sub_forms').innerHTML = resp;
                document.getElementById('add_sub_forms').style.visibility = "visible";
             });*/
      ///////////function to enable security check in vote it page
/* $.get('modules/poll/captcha_login.php',{popid:popid,rand:rand,pid:pid,alpid:alpid,pollans:pollans},
 function (resp)
 {
     //alert(resp);
     var mousex = e.clientX;////to get mouse position x axis
     var mousey = e.clientY;////to get mouse position y axis

     mousex = mousex - 450;////to get the popup window in desired x position
     mousey = mousey + 50;////to get the popup window in desired y position
     
     
     document.getElementById('vote_captcha').innerHTML = resp;
     document.getElementById("viewresult").style.visibility='hidden';
     document.getElementById('vote_captcha').style.display = "";

 }
);*/
		}
	 }
  return false;
}


function security_code() {
    if(document.getElementById('security_code').value == ''){
        alert("Please Enter Security Code");
        document.getElementById('security_code').focus();
        return false;
    }
    var pid = document.getElementById('pid').value;
    var alpid = document.getElementById('alpid').value;
    var code = document.getElementById('security_code').value;
    var pollans = document.getElementById('pollans').value;
    $.get("/modules/poll/captcha_insert.php",{security_code:code,pid:pid,alpid:alpid,pollans:pollans},
    function (resp){
        if(resp == "error"){
            alert("Security Code is invalid");
            document.getElementById('security_code').value = '';
            document.getElementById('security_code').focus(); 
        }
       else {
             if(resp == 1){ 
             document.getElementById('add_sub_forms').innerHTML = "";
	         $("#backgroundPopup").fadeOut(30);
             document.getElementById('add_sub_forms').style.visibility = "hidden";    
             document.getElementById('viewresult').style.display = 'block';
             // $('#main').load('http://www.opinionpoll.in/voteit.php?security_code='+scode+'&pollans='+pollans);
             //self.location = 'http://www.opinionpoll.in/'+alpid+'&id='+1;
             //self.location = "http://www.opinionpoll.in/"+alpid+'&pollans='+Ballet;
			//window.document.vote.submit();
			return true;
			//vote_check(e,popid,pid,alpid, 'true');
             }
      }
    
    }
   );
            //    return true;
}

// Checking Security Code Validation
function fn_securitycode(e){
	var key = (document.all)?event.keycode:e.which;
	if((key >= 48) && (key <= 57) || ((key >= 65) && (key <= 90)) || (key == 32) || (key == 8) || (key == 0) || (key >= 97) && (key <= 122))
		return true;
	else 
		return false;
} 

////////////function for check captha and poll posting
function check_captcha()
{
 
  var sec_code = document.getElementById('security_code').value;
  if(sec_code == "")
    {
      alert("Please enter Captcha Code");
      return false;
    }
  var rand = Math.random();
  $.get("/modules/poll/captcha_insert.php",{security_code:sec_code,rand:rand},
 function (resp)
 {
   if(resp == 1)
     {
       document.vote.submit();
     }
    else
      {
        alert("Please enter correct Security Code");
      }
 }
)
  return false;
}
////////////function for check captha and poll posting

////////////function to close captha window
function close_captcha()
{
  document.getElementById('vote_captcha').innerHTML = "";
  document.getElementById('vote_captcha').style.display = "none";
   document.getElementById("viewresult").style.visibility='visible';

}
////////////function to close captha window

//////////function to show alert box
function show_alert(channel,subcat,url,pqid)
{
 var rand = Math.random();
 $.get('/includes/alert_list.php',{chan1:channel,cate1:subcat,rand:rand,ur:url,qid:pqid},
           function (resp)
           {
               document.getElementById('alertdis').innerHTML = resp;
               document.getElementById('alertdis').style.visibility = "visible";
           }

 );
  /* var rand = Math.random();
          $.get('includes/alert_list.php',{user:uid,rand:rand},
           function (resp)
           {
       alert(resp);
               var mousex = e.clientX;////to get mouse position x axis
               var mousey = e.clientY;////to get mouse position y axis

               mousex = mousex - 450;////to get the popup window in desired x position
               mousey = mousey + 50;////to get the popup window in desired y position

               $('#myalert').css({'left' : 400,'top' : 550 });////set the css for popup using jquery
               document.getElementById('myalert').innerHTML = resp;
               document.getElementById('myalert').style.display = "";
           }
          );*/
}


//////////function to show alert box

