// JavaScript Document

// only accept alpha numeric, "-" and "_"
poll_id = poll_id.replace(/[^a-z0-9_-]/gi,"_");

// create a div with the ID same as poll_id, we will display the poll in it
document.write('<iframe id="'+poll_id+'" name="'+poll_id+'" src="" width="'+poll_width+'" height="'+poll_height+'" frameborder="0" scrolling="no" allowTransparency="true"></></iframe>');

// a function that retruns the full path of current .js file
var js_script_url = (function(){
	var scripts = document.getElementsByTagName('script'), script = scripts[scripts.length - 1];
	if (script.getAttribute.length !== undefined) {
		return script.getAttribute('src')
	}
	return script.getAttribute('src', 2)
}());


// get the working directory of this js script, to be able to redirect to poll.php properly
last_slash_position = js_script_url.lastIndexOf("/");
script_directory = js_script_url.slice(0,last_slash_position+1);

$variables_string = "?poll_id="+poll_id+"&poll_question="+poll_question+"&poll_titles="+poll_titles+"&poll_images="+poll_images;

// load the iframe
document.getElementById(poll_id).src = script_directory +"poll.php"+$variables_string;

