
	/******************************************************************************
								P O L L  S C R I P T
	*******************************************************************************/
	 /*
	  * Poll main path url
	  */
	//ppPollPath="http://localhost/poll/";
	ppPollPath="http://www.1upbanners.com/poll/";
	
	 /*
	  * Register this page
	  * If this page doesn't exists this page will be register
	  * otherwise it will not consider
	  */
	ppPollDynamicScript("in/register_page.php", "registerJson");
	ppPollDeleteScript("registerJson");
	
	 /*
	  * By this function we can meke the dynamic script tag
	  * By the dynamic script we can call any server side page instantly and execute that page
	  */
	
	function ppPollDynamicScript(src, id)
	{
		//Add the dynamic script into the head of the requested page.
		var registerScript=document.createElement("script");
		registerScript.src=ppPollPath+src;
		if(navigator.appName!="Microsoft Internet Explorer")
			registerScript.id=id;
		registerScript.type="text/javascript";
		registerScript.charset="utf-8";
		var head=document.getElementsByTagName("head")[0];
		head.appendChild(registerScript);
	}
	
	 /*
	  * After successfull request sending, delete the script tag, 
	  * not only the tag, all properties of the script tag will be
	  * delete from the memory to avoid the memory leak.
	  * in IE this removeChild doesn't work, fortunately an IE is instead of add a new script node,
	  * that replace the src property of the script.
	  */
	
	function ppPollDeleteScript(id)
	{
		//After successfull request sending, delete the script tag, 
		//not only the tag, all properties of the script tag will be
		//delete from the memory to avoid the memory leak.
		
		//in IE this removeChild doesn't work, fortunately an IE is instead of add a new script node,
		//that replace the src property of the script.
		var script;
		while(script=document.getElementById(id))
		{
			script.parentNode.removeChild(script);
			for(var prop in script)
			{
				delete script[prop];
			}
		}
	}
	
	 /*
	  * Make and place the element
	  * This element is using to display (hide) the response from the server
	  * If it is append with body, it will append with body at last element
	  */
	
	function ppPollSetContainer(id)
	{
		// Add the container to display the response
	//	var span=document.createElement("span");
	//	span.id=id;
	//	span.innerHTML='<div style="text-align:center"><img src="'+ppPollPath+'loader.gif"/></div>';
	//	span.style.textAlign="center";
	//	var body=document.getElementsByTagName("body")[0];
	//	body.appendChild(span);
		
		var span='<span id="'+id+'" >';
		span+='<div style="text-align:center"><img src="'+ppPollPath+'loader.gif"/></div>'+'</span>';
		document.writeln(span);
	}
	 
	 /*
	  * Callback function of Poll
	  * When the server side page will execute by the dynamic script tag
	  * that will produce the responce in JSON object
	  */
	
	function ppPollCallback(result)
	{
		var ppPollObj=eval('('+result+')');
		document.getElementById(ppPollObj.element).innerHTML=ppPollObj.pollForm;
	}
	
	 /*
	  * Retrieve the poll
	  */
	
	function poll(poll_id)
	{
		var postId=Math.ceil(Math.random()*100000);
		var element="ppPollContainer"+postId;
		ppPollSetContainer(element);
		ppPollDynamicScript("in/poll.php?jsonp=ppPollCallback&ele="+element+"&pollid="+poll_id, "pollJson"); 
		if(navigator.appName!="Microsoft Internet Explorer")
			ppPollDeleteScript("pollJson");
	}
	
	 /*
	  * Vote to the poll
	  */
	
	function ppPollVote(poll_id)
	{
		var ans='';
		for(var i=0; i<document.poll_form.poll_ans.length; i++)
		{
			if(document.poll_form.poll_ans[i].checked)
				ans=document.poll_form.poll_ans[i].value;
		}
		
		if(ans!='')
		{
			ppPollDynamicScript("in/poll_vote.php?jsonp=ppPollVoteCallback&ans="+ans+"&pollid="+poll_id, "pollVoteJson"); 
			if(navigator.appName!="Microsoft Internet Explorer")
				ppPollDeleteScript("pollVoteJson");
		}
		else
			alert('Please select anyone to vote !');
	}
	
	 /*
	  * Poll vote callback
	  * By this callback we know about our vote status (success or failure)
	  */
	
	function ppPollVoteCallback(result)
	{
		var ppPollVoteObj=eval('('+result+')');
		alert(ppPollVoteObj.reply);
	}
