// JavaScript Document
// Daniel Raquel

//GALLERY CLASS
function Gallery(){
	
	this.gid = 0;
	this.type = null;
	this.name = null;
	this.content = new DLList();
	this.current = this.content.getFirst();
	
	//CLASS SET/GET FUNCTIONS
	this.getGID = getGID;
	function getGID(){
		return this.gid;
	}
	this.setGID = setGID;
	function setGID(id){
		this.gid = id;
	}
	this.getType = getType;
	function getType(){
		return this.type;
	}
	this.setType = setType;
	function setType(t){
		this.type = t;
	}
	this.getName = getName;
	function getName(){
		return this.name;	
	}
	this.setName = setName;
	function setName(n){
		this.name = n;	
	}
	//END CLASS SET/GET FUNCTIONS
	this.fullPath = fullPath;
	function fullPath(index){
		$n = this.content.getNode(index);
		//Content Image
		if($n.data.type == "jpg" || $n.data.type == "png" || $n.data.type == "gif"){
			$p = "content/img/"+$n.data.path+"."+$n.data.type;
		}
		//Content File
		if($n.data.type == "zip" || $n.data.type == "rar" || $n.data.type == "doc"  || $n.data.type == "docx" || $n.data.type == "xls" || $n.data.type == "xlsx" || $n.data.type == "ppt" || $n.data.type == "pps"){
			$p = "content/file/"+$n.data.path+"."+$n.data.type;
		}
		return $p;
	}
	//AJAX GET FUNCTIONS
	this.getGallery = getGallery;
	function getGallery(gid){
		var xmlhttp, url, imgs;
		xmlhttp = ajaxReq();
		url = "post/getGallery.php";
		xmlhttp.open("POST",url,false);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		if(_sid != null && gid != null ){
			ins = "s="+_sid+"&g="+gid;
		}else{
			return false;	
		}
		xmlhttp.send(ins);
		xmlDoc = loadXML(xmlhttp.responseText);
		this.readXML(xmlDoc);
		imgs = new Array();
		var i = 0;
		this.current = this.content.getFirst();
		while(this.current != null){
			imgs[i] = "content/img/t/"+this.current.data.getPath()+"."+this.current.data.getType();
			this.current = this.current.next;
			i++;
		}
		_imgp = new Array();
		_imgp = imgs;
	}
	this.getSeries = getSeries;
	function getSeries(sid){
		var xmlhttp, url, imgs;
		xmlhttp = ajaxReq();
		url = "post/getSeries.php";
		xmlhttp.open("POST",url,false);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		if(_sid != null && sid != null ){
			ins = "s="+_sid+"&r="+sid;
		}else{
			return false;	
		}
		xmlhttp.send(ins);
		xmlDoc = loadXML(xmlhttp.responseText);
		this.readXML(xmlDoc);
		imgs = new Array();
		var i = 0;
		this.current = this.content.getFirst();
		while(this.current != null){
			imgs[i] = "content/img/t/"+this.current.data.getPath()+"."+this.current.data.getType();
			this.current = this.current.next;
			i++;
		}
		_imgp = new Array();
		_imgp = imgs;
	}
	//END AJAX GET FUNCTIONS
	//XML FUNCTIONS
	this.readXML = readXML;
	function readXML(doc){
		d = doc.documentElement;
		a = d.attributes;
		this.setGID(a.getNamedItem("gid").nodeValue);
		this.setName(a.getNamedItem("name").nodeValue);
		
		gi = d.getElementsByTagName("ContentImage");
		for(i = 0; i < gi.length; i++){
			c = new ContentImage();
			c.name = gi[i].getElementsByTagName("name")[0].childNodes[0].nodeValue;
			if(gi[i].getElementsByTagName("info")[0].childNodes[0].nodeValue == "NULL"){
				c.info = null;
			}else{
				c.info = gi[i].getElementsByTagName("info")[0].childNodes[0].nodeValue;
			}
			c.cid = gi[i].getElementsByTagName("CID")[0].childNodes[0].nodeValue;
			c.gid = gi[i].getElementsByTagName("GID")[0].childNodes[0].nodeValue;
			c.added = gi[i].getElementsByTagName("added")[0].childNodes[0].nodeValue;
			c.views = gi[i].getElementsByTagName("views")[0].childNodes[0].nodeValue;
			c.iid = gi[i].getElementsByTagName("IID")[0].childNodes[0].nodeValue;
			c.path = gi[i].getElementsByTagName("path")[0].childNodes[0].nodeValue;
			c.type = gi[i].getElementsByTagName("type")[0].childNodes[0].nodeValue;
			c.size = gi[i].getElementsByTagName("size")[0].childNodes[0].nodeValue;
			this.content.add(c);
		}
		gf = d.getElementsByTagName("ContentFile");
		for(i = 0; i < gf.length; i++){
			c = new ContentFile();
			c.name = gf[i].getElementsByTagName("name")[0].childNodes[0].nodeValue;
			c.info = gf[i].getElementsByTagName("info")[0].childNodes[0].nodeValue;
			c.cid = gf[i].getElementsByTagName("CID")[0].childNodes[0].nodeValue;
			c.gid = gf[i].getElementsByTagName("GID")[0].childNodes[0].nodeValue;
			c.added = gf[i].getElementsByTagName("added")[0].childNodes[0].nodeValue;
			c.views = gf[i].getElementsByTagName("views")[0].childNodes[0].nodeValue;
			c.fid = gf[i].getElementsByTagName("FID")[0].childNodes[0].nodeValue;
			c.path = gf[i].getElementsByTagName("path")[0].childNodes[0].nodeValue;
			c.type = gf[i].getElementsByTagName("type")[0].childNodes[0].nodeValue;
			c.size = gf[i].getElementsByTagName("size")[0].childNodes[0].nodeValue;
			this.content.add(c);
		}
	}
	//END XML FUNCTIONS
	//AUTO SLIDE SHOW FUNCTIONS
	this.slideShow = slideShow;
	function slideShow(eid){
		if(document.getElementById(eid)){
			document.getElementById(eid).src = "content/img/loader.gif";
		}
		preloadImages(_imgp);
		this.current = this.content.getFirst();
		this.slide(eid);
		var instant = this;
		setInterval(function(){instant.slide(eid);},_tts);
	}
	this.slide = slide;
	function slide(eid){
		fade(eid);
		var instant = this;
		setTimeout(function(){instant.fillSlide(eid);fade(eid);if(instant.current.next == null){instant.current = instant.content.getFirst();}else{instant.current = instant.current.next;}},_ttf+200);
	}
	//END AUTO SLIDE SHOW FUNCTIONS
	//MANUAL SLIDE SHOW FUNCTIONS
	this.show = show;
	function show(eid){
		//document.getElementById(eid).src = "content/img/loader.gif";
		//fade(eid);
		preloadImages(_imgp);
		this.current = this.content.getFirst();
		instant = this;
		setTimeout(function(){instant.fillSlide(eid);fade(eid);},_ttf+200);
	}
	this.showNext = showNext;
	function showNext(eid,cir){
		if(this.current.next == null){
			if(cir == true){
				this.current = this.content.getFirst();
			}else{
				return false;	
			}
		}else{
			this.current = this.current.next;
		}
		fade(eid);
		instant = this;
		setTimeout(function(){instant.fillSlide(eid);fade(eid);},_ttf+200);
	}
	this.showPrev = showPrev;
	function showPrev(eid,cir){
		if(this.current.prev == null){
			if(cir == true){
				this.current = this.content.getLast();
			}else{
				return false;	
			}
		}else{
			this.current = this.current.prev;	
		}
		fade(eid);
		instant = this;
		setTimeout(function(){instant.fillSlide(eid);fade(eid);},_ttf+200);
	}
	//END MANUAL SLIDE SHOW FUNCTIONS
	//THUMBNAIL SHOW FUNCTIONS
	this.showThumbs = showThumbs;
	function showThumbs(eid,num,p){
		if(num <= 0 || eid == null){
			return false;
		}else{
			preloadImages(_imgp);
			if(p == 1 || p == 0 || p == null){
				this.current = this.content.getFirst();
			}else{
				this.current = this.content.getNode(((p*num)-(num-1))); //first node of page p
			}
			
			for(i = 1; i <= num; i++){
				this.fillSlide(eid+i);
				if(i != num){
					if(this.current.next == null){
						break;
					}else{
						this.current = this.current.next;
					}
				}
			}
			this.current = this.content.getFirst();
		}
	}
	this.thumbsNext = thumbsNext;
	function thumbsNext(eid,num){
		var curr = this.content.getLast();
		var count = 0;
		while(curr.data.getCID() != this.current.data.getCID()){
			count++;
			curr = curr.prev;
		}
		if(num <= 0 || eid == null || count < num){
			return false;
		}
		for(i = 0; i < num; i++){this.current = this.current.next;}
		var end = false;
		var os = 0;
		for(i = 1; i <= num; i++){
			if(end){
				this.clearSlide(eid+i);		
			}else{
				this.fillSlide(eid+i);	
			}
			if(this.current.next == null){
				if(end){
					os++;
				}else{
					end = true;
				}
			}else{
				this.current = this.current.next;	
			}
		}
		if(os != 0){os = os +1;}
		var p = num-os;
		for(i = 0; i < p; i++){
			this.current = this.current.prev;
		}
	}
	this.thumbsPrev = thumbsPrev;
	function thumbsPrev(eid,num){
		if(num <= 0 || eid == null || this.current.data.getCID() == this.content.getFirst().data.getCID()){
			return false;
		}
		for(i = 0; i < num; i++){this.current = this.current.prev;}
		var begin = false;
		for(i = 1; i <= num; i++){
			this.fillSlide(eid+i);
			this.current = this.current.next;
		}
		for(i = 0; i < num; i++){this.current = this.current.prev;}
	}
	//END THUMBNAIL SHOW FUNCTIONS
	//SLIDE FUNCTIONS
	this.fillSlide = fillSlide;
	function fillSlide(eid){
		if(document.getElementById(eid+"Img")){
			document.getElementById(eid+"Img").src="content/img/t/" + this.current.data.getPath() +"."+ this.current.data.getType();
			document.getElementById(eid+"Img").alt = this.current.data.getName();
			document.getElementById(eid+"Img").title = this.current.data.getName();
		}
		if(document.getElementById(eid+"Link")){
			document.getElementById(eid+"Link").title = this.current.data.getName();//Lightbox Comment
			document.getElementById(eid+"Link").href = "content/img/t/" + this.current.data.getPath() +"."+ this.current.data.getType();//Lightbox Link or Link Path
		}
		if(document.getElementById(eid+"Name")){
			document.getElementById(eid+"Name").innerHTML = this.current.data.getName();
		}
		
		if(document.getElementById(eid+"Info")){
			document.getElementById(eid+"Info").innerHTML = this.current.data.getInfo();
		}
		if(document.getElementById(eid+"Added")){
			var dms = parseInt(this.current.data.getAdded())*1000;
			var d = new Date(dms);
			if(d.getSeconds() < 10){ var s = "0"+d.getSeconds();}else{var s = d.getSeconds();}
			var ds =  d.getMonth()+"."+d.getDay()+"."+d.getFullYear()+" "+d.getHours()+":"+d.getMinutes()+":"+s;
			document.getElementById(eid+"Added").innerHTML = "Added: "+ds;
		}
		if(document.getElementById(eid+"Views")){
			document.getElementById(eid+"Views").innerHTML = this.current.data.getViews();
		}
		if(document.getElementById(eid+"Size")){
			var n = new Number(this.current.data.getSize()/1024);
			document.getElementById(eid+"Size").innerHTML = n.toFixed(2) + " KB";
		}
	}
	this.clearSlide = clearSlide;
	function clearSlide(eid){
		if(document.getElementById(eid+"Img")){
			document.getElementById(eid+"Img").src="#";
			document.getElementById(eid+"Img").alt = "";
			document.getElementById(eid+"Img").title = "";
		}
		if(document.getElementById(eid+"Link")){
			document.getElementById(eid+"Link").title = "";//Lightbox Comment
			document.getElementById(eid+"Link").href = "#";//Lightbox Link or Link Path
		}
		if(document.getElementById(eid+"Name")){
			document.getElementById(eid+"Name").innerHTML = "";	
		}
		if(document.getElementById(eid+"Info")){
			document.getElementById(eid+"Info").innerHTML = "";
		}
		if(document.getElementById(eid+"Added")){
			document.getElementById(eid+"Added").innerHTML = "";
		}
		if(document.getElementById(eid+"Views")){
			document.getElementById(eid+"Views").innerHTML = "";
		}
		if(document.getElementById(eid+"Size")){
			document.getElementById(eid+"Size").innerHTML = "";
		}
	}
	//END SLIDE FUNCTIONS
	//TEST OUTPUT FUNCITON
	this.toHTMLString = toHTMLString;
	function toHTMLString(){
		s ="<h2>--"+this.name+"--</h2>\n";
		s +="<p>GID: "+this.gid+"<br />\n";
		current = this.content.getFirst();
		while(current != null){
			s += current.data.toHTMLString()+"\n";
			current = current.next;
		}
		return s;
	}
}
//END GALLERY CLASS
//CONTENT OBJECTS
function ContentImage(){
		
	this.cid = 0;
	this.name = null;
	this.info = null;
	this.gid = 0;
	this.added = 0;
	this.views = 0;
	this.iid = 0;
	this.path = null;
	this.type = null;
	this.size = 0;
	
	//CLASS SET/GET FUNCTIONS
	this.getCID = getCID;
	function getCID(){
		return this.cid;	
	}
	this.setCID = setCID;
	function setCID(id){
		this.cid = id;	
	}
	this.getIID = getIID;
	function getIID(){
		return this.iid;	
	}
	this.setIID = setIID;
	function setIID(id){
		this.iid = id;	
	}
	this.getName = getName;
	function getName(){
		return this.name;	
	}
	this.setName = setName;
	function setName(n){
		this.name = n;
	}
	this.getPath = getPath;
	function getPath(){
		return this.path;	
	}
	this.setPath = setPath;
	function setPath($path){
		this.path = $path;	
	}
	this.getAdded = getAdded;
	function getAdded(){
		return this.added;	
	}
	this.setAdded = setAdded;
	function setAdded(a){
		this.added = a;	
	}
	this.getType = getType;
	function getType(){
		return this.type;	
	}
	this.setType = setType;
	function setType(t){
		this.type = t;	
	}
	this.getInfo = getInfo;
	function getInfo(){
		return this.info;
	}
	this.setInfo = setInfo;
	function setInfo(i){
		this.info = i;
	}
	this.getViews = getViews;
	function getViews(){
		return this.views;	
	}
	this.setViews = setViews;
	function setViews(v){
		this.views = v;	
	}	
	this.getSize = getSize;
	function getSize(){
		return this.size;	
	}
	this.setSize = setSize;
	function setSize(s){
		this.size = s;	
	}
	//END CLASS SET/GET FUNCTIONS
	this.getContent = getContent;
	function getContent(cid){
		var xmlhttp;
		xmlhttp = ajaxReq();
		url = "post/getContent.php";
		if(_sid != null && cid != null ){
			url += "?s="+_sid+"&c="+gid;
		}else{
			return false;	
		}
		xmlhttp.open("GET",url,false);
		xmlhttp.send();
		xmlDoc = loadXML(xmlhttp.responseText);
		this.readXML(xmlDoc);
	}
	this.readXML = readXML;
	function readXML(doc){
		 this.name = doc.getElementsByTagName("name")[0].childNodes[0].nodeValue;
		 this.cid = doc.getElementsByTagName("CID")[0].childNodes[0].nodeValue;
		 this.gid = doc.getElementsByTagName("GID")[0].childNodes[0].nodeValue;
		 this.added = doc.getElementsByTagName("added")[0].childNodes[0].nodeValue;
		 this.views = doc.getElementsByTagName("views")[0].childNodes[0].nodeValue;
		 this.iid = doc.getElementsByTagName("IID")[0].childNodes[0].nodeValue;
		 this.path = doc.getElementsByTagName("path")[0].childNodes[0].nodeValue;
		 this.type = doc.getElementsByTagName("type")[0].childNodes[0].nodeValue;
		 this.size = doc.getElementsByTagName("size")[0].childNodes[0].nodeValue;
	}
	this.view = view;
	function view(){
		var xmlhttp;
		xmlhttp = ajaxReq();
		xmlhttp.onreadystatechange=function(){
			if (xmlhttp.readyState==4 && xmlhttp.status==200){
				if(xmlhttp.responseText == "0"){
					return true;
				}else{
					return false;	
				}
			}
		}
		url = "post/setView.php?s="+_sid+"&c="+this.cid;
		xmlhttp.open("GET",url,true);
		xmlhttp.send();
	}
	this.toHTMLString = toHTMLString;
	function toHTMLString(){
		s = "<ul>";
		s += "<li>CID: "+this.cid+"</li>\n";
		s += "<li>Name: "+this.name+"</li>\n";
		s += "<li>Info: "+this.info+"</li>\n";
		s += "<li>GID: "+this.gid+"</li>\n";
		s += "<li>Added:"+this.added+"</li>\n";
		s += "<li>Views: "+this.views+"</li>\n";
		s += "<li>IID: "+this.iid+"</li>\n";
		s += "<li>Path: "+this.path+"</li>\n";
		s += "<li>Type: "+this.type+"</li>\n";
		s += "<li>Size: "+this.size+"</li>\n</ul>\n";
		return s;
	}
}

function ContentFile(){
	
	this.cid = 0;
	this.name = null;
	this.info = null;
	this.gid = 0;
	this.added = 0;
	this.views = 0;
	this.fid = 0;
	this.path = null;
	this.type = null;
	this.size = 0;
	this.view = view;
	
	//CLASS SET/GET FUNCTIONS
	this.getCID = getCID;
	function getCID(){
		return this.cid;	
	}
	this.setCID = setCID;
	function setCID(id){
		this.cid = id;	
	}
	this.getFID = getFID;
	function getFID(){
		return this.fid;	
	}
	this.setFID = setFID;
	function setFID(id){
		this.fid = id;	
	}
	this.getName = getName;
	function getName(){
		return this.name;	
	}
	this.setName = setName;
	function setName(n){
		this.name = n;
	}
	this.getPath = getPath;
	function getPath(){
		return this.path;	
	}
	this.setPath = setPath;
	function setPath($path){
		this.path = $path;	
	}
	this.getAdded = getAdded;
	function getAdded(){
		return this.added;	
	}
	this.setAdded = setAdded;
	function setAdded(a){
		this.added = a;	
	}
	this.getType = getType;
	function getType(){
		return this.type;	
	}
	this.setType = setType;
	function setType(t){
		this.type = t;	
	}
	this.getInfo = getInfo;
	function getInfo(){
		return this.info;
	}
	this.setInfo = setInfo;
	function setInfo(i){
		this.info = i;
	}
	this.getViews = getViews;
	function getViews(){
		return this.views;	
	}
	this.setViews = setViews;
	function setViews(v){
		this.views = v;	
	}	
	this.getSize = getSize;
	function getSize(){
		return this.size;	
	}
	this.setSize = setSize;
	function setSize(s){
		this.size = s;	
	}
	//END CLASS SET/GET FUNCTIONS
	function view(){
		var xmlhttp;
		xmlhttp = ajaxReq();
		xmlhttp.onreadystatechange=function(){
			if (xmlhttp.readyState==4 && xmlhttp.status==200){
				document.getElementById('views').innerHTML=xmlhttp.responseText;
				return;
			}
		}
		url = "post/view.php?s="+_sid+"&c="+this.cid;
		xmlhttp.open("GET",url,true);
		xmlhttp.send();
	}
	this.toHTMLString = toHTMLString;
	function toHTMLString(){
		s = "<ul>";
		s += "<li>CID: "+this.cid+"</li>\n";
		s += "<li>Name: "+this.name+"</li>\n";
		s += "<li>Info: "+this.info+"</li>\n";
		s += "<li>GID: "+this.gid+"</li>\n";
		s += "<li>Added:"+this.added+"</li>\n";
		s += "<li>Views: "+this.views+"</li>\n";
		s += "<li>FID: "+this.fid+"</li>\n";
		s += "<li>Path: "+this.path+"</li>\n";
		s += "<li>Type: "+this.type+"</li>\n";
		s += "<li>Size: "+this.size+"</li>\n</ul>\n";
		return s;
	}
}

function ContentText(){
	
	this.cid = 0;
	this.name = null;
	this.info = null;
	this.gid = 0;
	this.added = 0;
	this.views = 0;
	this.tid = 0;
	this.text = null;
	this.align = "left";
	
	//CLASS SET/GET FUNCTIONS
	this.getCID = getCID;
	function getCID(){
		return this.cid;	
	}
	this.setCID = setCID;
	function setCID(id){
		this.cid = id;	
	}
	this.getTID = getTID;
	function getTID(){
		return this.tid;	
	}
	this.setTID = setTID;
	function setTID(id){
		this.tid = id;	
	}
	this.getName = getName;
	function getName(){
		return this.name;	
	}
	this.setName = setName;
	function setName(n){
		this.name = n;
	}
	this.getInfo = getInfo;
	function getInfo(){
		return this.info;
	}
	this.setInfo = setInfo;
	function setInfo(i){
		this.info = i;
	}
	this.getViews = getViews;
	function getViews(){
		return this.views;	
	}
	this.setViews = setViews;
	function setViews(v){
		this.views = v;	
	}
	this.getAdded = getAdded;
	function getAdded(){
		return this.added;	
	}
	this.setAdded = setAdded;
	function setAdded(a){
		this.added = a;	
	}
	this.getText = getText;
	function getText(){
		return this.text;	
	}
	this.setText = setText;
	function setText(t){
		this.text = t;	
	}
	this.getAlign = getAlign;
	function getAlign(){
		return this.align;	
	}
	this.setAlign = setAlign;
	function setAlign(a){
		this.align = a;	
	}
	//END CLASS SET/GET FUNCTIONS	
	this.getTxtByID = getTxtByID;
	function getTxtByID(cid){
		var xmlhttp, url;
		xmlhttp = ajaxReq();
		url = "post/getText.php";
		xmlhttp.open("POST",url,false);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		if(_sid != null && cid != null ){
			ins = "s="+_sid+"&c="+cid;
		}else{
			return false;	
		}
		xmlhttp.send(ins);
		xmlDoc = loadXML(xmlhttp.responseText);
		this.readXML(xmlDoc);
	}
	this.getTxtByName = getTxtByName;
	function getTxtByName(n){
		var xmlhttp, url;
		xmlhttp = ajaxReq();
		url = "post/getText.php";
		xmlhttp.open("POST",url,false);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		if(_sid != null && n != null ){
			ins = "s="+_sid+"&n="+n;
		}else{
			return false;	
		}
		xmlhttp.send(ins);
		xmlDoc = loadXML(xmlhttp.responseText);
		this.readXML(xmlDoc);
	}
	this.setTxt = setTxt;
	function setTxt(eid){
			if(document.getElementById(eid)){
				document.getElementById(eid).innerHTML = this.text;	
			}
	}
	this.readXML = readXML;
	function readXML(doc){
		 this.name = doc.getElementsByTagName("name")[0].childNodes[0].nodeValue;
		 this.cid = doc.getElementsByTagName("CID")[0].childNodes[0].nodeValue;
		 //this.gid = doc.getElementsByTagName("GID")[0].childNodes[0].nodeValue;
		 this.info = doc.getElementsByTagName("info")[0].childNodes[0].nodeValue;
		 this.added = doc.getElementsByTagName("added")[0].childNodes[0].nodeValue;
		 //this.views = doc.getElementsByTagName("views")[0].childNodes[0].nodeValue;
		 this.tid = doc.getElementsByTagName("TID")[0].childNodes[0].nodeValue;
		 this.text = doc.getElementsByTagName("text")[0].childNodes[0].nodeValue;
		 this.align = doc.getElementsByTagName("align")[0].childNodes[0].nodeValue;
	}
}
//END CONTENT OBJECTS
//POLLING SYSTEM
function Poll(){
	this.pid = 0;
	this.title = null;
	this.options = new Array();
	this.values = new Array();
	
	this.getPID = getPID;
	function getPID(){
		return this.pid;	
	}
	this.setPID = setPID;
	function setPID(id){
		this.pid = id;	
	}
	this.getTitle = getTitle;
	function getTitle(){
		return this.title;	
	}
	this.setTitle = setTitle;
	function setTitle(t){
		this.title = t;	
	}
	this.addOption = addOption;
	function addOption(o,v){
		this.options[this.options.length] = o;
		this.values[this.options.length] = v;
	}
	this.getPoll = getPoll;
	function getPoll(pid){
		var xmlhttp, url;
		xmlhttp = ajaxReq();
		url = "post/getPoll.php";
		xmlhttp.open("POST",url,false);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		if(_sid != null && pid != null ){
			ins = "s="+_sid+"&p="+pid;
		}else{
			return false;	
		}
		xmlhttp.send(ins);
		xmlDoc = loadXML(xmlhttp.responseText);
		this.readXML(xmlDoc);
	}
	this.setPoll = setPoll;
	function setPoll(eid){
		if(document.getElementById(eid+"Title")){
			document.getElementById(eid+"Title").innerHTML = this.getTitle();
		}
		if(document.getElementById(eid+"Options")){
			document.getElementById(eid+"Options").innerHTML = "<form>\n";
			for(i = 0; i < this.options.length; i++){
				document.getElementById(eid+"Options").innerHTML += "<input type=\"radio\" name=\"vote\" value=\""+i+"\" onclick=\"vote('"+eid+"',"+this.pid+","+i+")\" />"+this.options[i]+"<br />\n";
			}
			document.getElementById(eid+"Options").innerHTML += "</form>\n";
			document.getElementById(eid+"Options").innerHTML += "<a href=\"#\" onClick=\"vote('"+eid+"',"+this.pid+",'vr')\">View Results</a>";
		}
	}
	this.readXML = readXML;
	function readXML(doc){
		d = doc.documentElement;
		a = d.attributes;
		this.pid = a.getNamedItem("pid").nodeValue;
		this.title = d.getElementsByTagName("title")[0].childNodes[0].nodeValue;
		o = d.getElementsByTagName("option");
		for(i = 0; i < o.length; i++){
			this.options[i] = o[i].attributes.getNamedItem("label").nodeValue;
			this.values[i] = o[i].attributes.getNamedItem("value").nodeValue;
		}
	}
}
function vote(eid,pid,oi){
	var url = "post/setVote.php";
		var xmlhttp;
	  	xmlhttp = ajaxReq();
		xmlhttp.onreadystatechange=function(){
			if (xmlhttp.readyState==4 && xmlhttp.status==200){
				document.getElementById(eid+"Options").innerHTML=xmlhttp.responseText;
				return;
			}
		}
		xmlhttp.open("POST",url,true);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		if(oi != null && _sid != null && pid != 0){
			var ins;
			ins = "i="+oi+"&s="+_sid+"&p="+pid;
			xmlhttp.send(ins);
		}else{
			xmlhttp.send(null);
		}
}
//END POLLING SYSTEM
