function gst()
{	if (!window.XMLHttpRequest && !window.ActiveXObject){alert("ERROR : Your browser do not support this site.\n[CODE : gstNA.ActiveXObject]");}
	if (!document.getElementById && !document.createElement){alert("ERROR : Your browser do not support this site.\n[CODE : gstNAdom.1]");}
}
gst.prototype.init = function()
{	this.toggleForm();this.upDown();this.toolTipInt();this.toggleRating();this.autoSuggest();this.moreSpace();
	mFa=document.getElementById('MfA');A = getElementsByAttribute("a", "href", "#");
	if(mFa)
	{	GmFa=gt.xmlHttp();GmFa.open('GET','http://www.ivotings.com/user/friends/data/raw',true);
		fAmA=document.getElementById('fAm').getElementsByTagName('a');
		GmFa.onreadystatechange=function()
								{	if(GmFa.readyState==4 && GmFa.status==200)
									{	data=eval('('+GmFa.responseText+')');mFa.innerHTML=data[0];
										for(i=1;i<fAmA.length+1;i++)
										{	fAmA[i-1].innerHTML = fAmA[i-1].innerHTML+' ('+data[i]+')';
											fAmA[i-1].onmousedown = new Function("setTimeout(function(){window.location.reload();},1000);");
										}
									}
								}
		GmFa.send(null);
	}
	for(i=0;i<A.length;i++)A[i].href="javascript:;";
	document.getElementById("header").removeChild(document.getElementById("preLoadCover"));
	document.getElementById("normalILsearch").onclick = gt.nILs;
	Fotr=document.getElementById("footer");
	if(Fotr)if(Fotr.offsetTop<500)document.getElementById("maincontainer").style.height='500px';
}
gst.prototype.chkImg = function (obj,nm)
{	validformFile = /(.jpg|.JPG|.jpeg|.JPEG|.gif|.GIF)$/;
	rturn = validformFile.test(obj.value);
	if(!rturn)gt.displayError("Invalid image format! Try Again!",7000);
	else if(!nm)gt.displayError("Please wait uploading picture!",9500); return rturn;
}
gst.prototype.nILs = function(e)
{	if(!e)var e=window.event;obj=e.target?e.target:e.srcElement;
	F = obj.parentNode.parentNode; 
	if(F.elements[0].value!=F.elements[0].title)F.submit();else gt.displayError('Please enter something to search',2000);
}
gst.prototype.xmlHttp = function()
{	if (window.XMLHttpRequest){xmlhttp = new XMLHttpRequest();}
	else if (window.ActiveXObject){xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
	return xmlhttp;
}
function showError()
{	obj = document.getElementById("tempDiv");
	objTop = parseInt(obj.style.top);
	if(objTop<0)
	{	objTop++;obj.style.top = objTop+"px";
		setTimeout("showError()",0);
	}
}
function hideError(t)
{	obj = document.getElementById("tempDiv");
	objTop = parseInt(obj.style.top);
	if(objTop>-85)
	{	objTop--; obj.style.top = objTop+'px';
		setTimeout("hideError(0)",t);	
	}
	else document.body.removeChild(obj);
}
function getElementsByAttribute(strTagName, strAttributeName, strAttributeValue){
	var oElm = document.body;
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)") : null;
	var oCurrent;
	var oAttribute;
	for(var i=0; i<arrElements.length; i++)
	{	oCurrent = arrElements[i];
		if(strAttributeName=="class"){if(oCurrent.className==strAttributeValue)arrReturnElements.push(oCurrent);}
		else{	oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);
		if(typeof oAttribute == "string" && oAttribute.length > 0)if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute)))arrReturnElements.push(oCurrent);}
	}
	return arrReturnElements;
}
gst.prototype.moreSpace = function()
{	c=document.getElementsByTagName("textarea");for(i=0;i<c.length;i++)
	if(c[i].className=='commentExt'){c[i].value=c[i].title;c[i].onfocus=gt.cF;c[i].onblur=gt.cB;}
}

gst.prototype.cF = function(e)
{	if(!e) var e=window.event;if(e.target)c=e.target;else if(e.srcElement)c=e.srcElement;
	c.style.zIndex='7';
	c.style.height='200px';
	c.style.overflow='auto';
	c.style.position='absolute';
	if(c.value==c.title)c.value="";
}

gst.prototype.cB = function(e)
{	if(!e) var e=window.event;if(e.target)c=e.target;else if(e.srcElement)c=e.srcElement;
	c.style.zIndex='0';
	c.style.height='33px';
	c.style.overflow='hidden';
	c.style.position="relative";
	if(c.value=="")c.value=c.title;
}

gst.prototype.autoSuggest = function()
{	f = document.contestRate;
	if(f){n=f.name;n.value=n.title;n.onkeyup=new Function(' var tT=setTimeout("gt.suggestions()",1000)');n.onkeypress=new Function(' var tT=clearTimeout(tT)');
	n.onfocus = function(){if(n.value==n.title)n.value="";}
	n.onblur = function(){if(n.value=="")n.value=n.title;setTimeout(function(){D=document.getElementById('sugTempDiv');if(D)D.style.display='none';},2000);}}
}

gst.prototype.chkSuggestions = function()
{	f = document.contestRate; xmlhttp = gt.xmlHttp();
	cEr = document.getElementById("contextError").getElementsByTagName("div");
	if(f.id.value=="")cEr[0].innerHTML="<span style='color:#eb3e2e;font-weight:bold'>Item does not exist. Setup a new item <a href=\"javascript:gt.lightBoxOpen('contest/create');\" style='color:#eb3e2e;font-weight:bold'>here</a></span>";else cEr[0].innerHTML="&nbsp;";
	if(f.rate.value=="")cEr[1].innerHTML="Please rate it!";else cEr[1].innerHTML="&nbsp;";
	if(f.rate.value!="" && f.id.value!="")
	{	I = f.getElementsByTagName("input");
		r = "comment="+encodeURI(f.comment.value)+"&";
		for(i=0;i<I.length;i++){r = r+I[i].name+'='+I[i].value+'&';}
		xmlhttp.open('POST', "http://www.ivotings.com/contest/rate", true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.onreadystatechange = function() 
		{ if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
			{	data=eval('(' + xmlhttp.responseText + ')');
				document.getElementById("contextNote").innerHTML = data["r"];
				if(data["rc"])
				{/*	tgt=document.getElementById("contextError");for(i=0;i<data.rc.length;i++)
					{	a = document.createElement("a"); a.href="#"+data.rc[i].id;
						a.appendChild(document.createTextNode(data.rc[i].name));
						tgt.appendChild(a);tgt.appendChild(document.createTextNode(',  '));
					}
				*/}
			}
		}
		xmlhttp.send(r);
		for(i=0;i<I.length;i++){I[i].value="";}f.comment.value="";//f.comment.parentNode.getElementsByTagName("span")[0].innerHTML="";
		A = f.getElementsByTagName("a");for(i=0;i<A.length;i++){if(A[i].className=="selected")A[i].className="";}
		D = document.getElementById("sugTempDiv").getElementsByTagName("div");
		for(i=0;i<D.length;i++){if(D[i].innerHTML==f.name.value)D.removeChild(D[i].parentNode.parentNode);}
	}
}
gst.prototype.suggestions = function()
{	obj = document.contestRate.name;
	if(obj.getAttribute("autocomplete")=="on")
	{	if(obj.value=='')return false;obj.className="loading";
		Dt = document.getElementById("sugTempDiv");
		if(Dt)
		{	Dt.style.display="block"; D = Dt.getElementsByTagName("div")[0];
		}
		else
		{	D = document.createElement("div");
			Dt = document.createElement("div");Dt.className = "sugg w300 whtbg bdr4 fl pad13";Dt.id = "sugTempDiv";
			iA = document.createElement("img");iA.src = "http://www.ivotings.com/public/images/chooseitem.jpg";
			iB = document.createElement("img");iB.src = "http://www.ivotings.com/public/images/createitem.jpg";iB.style.cursor = "pointer";
			iB.onclick = new Function("gt.lightBoxOpen('contest/create')");
			Dt.appendChild(D);Dt.appendChild(iB);obj.parentNode.appendChild(Dt);
		}
		dIn = D.getElementsByTagName("div");
		for(i=0;i<dIn.length;i++){if(dIn[i].className == "temp")dIn[i].style.display="none";}
		dIn = document.getElementById(obj.value);
		if(dIn){dIn.style.display="block";obj.className="";}
		else{Z=document.createElement("div");Z.id=obj.value;Z.className="temp";D.appendChild(Z);
			obj.setAttribute("autocomplete","off");	var Sd=gt.xmlHttp();
			Sd.open('GET', "http://www.ivotings.com/contest/suggestions/for/"+obj.value, true);
			Sd.onreadystatechange=function(){if(Sd.readyState==4 && Sd.status==200)
			{obj.setAttribute("autocomplete","on");expenD(Sd.responseText,obj.value);obj.className="";}}
			Sd.send(null);}
		obj.focus();
	}
}
function expenD(d,v) 
{	data=null;if(d.length>0)data=eval('('+d+')');
	if(data && v)for(i=0;i<data.length;i++)
	{	U = document.createElement("div"); U.className = "pad10 w298 fl sugestionbg bdr4 mt10";
		dP = document.createElement("div"); dP.className = "w280 fl"; 
		dA = document.createElement("div"); dA.className = "wauto fl ft16 cp"; dA.appendChild(document.createTextNode(data[i].n));
		dA.onclick = new Function('gt.selectVal("'+data[i].n+'","'+data[i].i+'")');
		dB = document.createElement("div"); dB.className = "wauto fr mr5"; dB.appendChild(document.createTextNode(data[i].v+" ratings"));
		dP.appendChild(dA); dP.appendChild(dB); 
		dC = document.createElement("div"); dC.className = "w280 fl mt5"; 
		if(data[i].t)for(j=0;j<data[i].t.length;j++)
		{	A = document.createElement("a"); A.href = "http://www.ivotings.com/tag/"+data[i].t[j]; A.target = "_blank";
			A.appendChild(document.createTextNode(data[i].t[j]));
			if(data[i].t.length>(j+1))A.appendChild(document.createTextNode(", "));
			dC.appendChild(A);
		}	U.appendChild(dP); U.appendChild(dC);
		document.getElementById(v).appendChild(U);
	}
	if(!data && v)
	{	U = document.createElement("div"); U.className = "pad10 w298 fl sugestionbg bdr4 mt10";
		dP = document.createElement("div"); dP.className = "w280 fl";
		dP.appendChild(document.createTextNode("Your search - '"+v+"' - did not match any result."));
		U.appendChild(document.createTextNode("Try again."));
		U.appendChild(dP);document.getElementById(v).appendChild(U);
	}
	
}
gst.prototype.sure = function(m)
{	this.wrap(); m = confirm(m); this.lightBoxClose(); return m;
}
gst.prototype.selectVal = function(t,i)
{	document.contestRate.name.value = t;
	document.contestRate.id.value = i;
	D=document.getElementById('sugTempDiv');if(D)D.style.display='none';
}
gst.prototype.toggleRating = function()
{	rateUp = getElementsByAttribute("div","class","ratesup");
	for(i=0;i<rateUp.length;i++)
	{	rateUp[i].parentNode.getElementsByTagName("a")[1].onclick = gt.rateUp;
		rateUp[i].onclick = gt.rateUp;
	}
}
gst.prototype.rateUp = function(e)
{	gt.displayError('Login required to post comment and rating!',5000);}
gst.prototype.lightBoxOpen = function(url)
{	this.wrap();
	obj = document.getElementById(url);
	if(obj){obj.style.display="block";}
	else{
	pg = document.createElement('div');
	pg.id = url;
	pg.className = "lBc";
	pg.innerHTML = '<img src="http://www.ivotings.com/public/images/loading.gif" alt="Loading.." style="padding:99px">';
	document.body.appendChild(pg);
	pg.style.left = (document.body.offsetWidth/2)-(pg.offsetWidth)+"px";
	lBO=gt.xmlHttp();lBO.open('GET', "http://www.ivotings.com/"+url, true);
	lBO.onreadystatechange=function(){if(lBO.readyState==4 && lBO.status==200)pg.innerHTML=lBO.responseText;gt.toggleRating();}
	lBO.send(null);
		}
}
gst.prototype.wrap = function()
{	w = document.getElementById("wrap");
	if(w){w.style.display="block";}
	else
	{	w = document.createElement('div');
		w.id = "wrap";
		w.className = "lB";
		document.body.appendChild(w);
	}	return w
}
gst.prototype.putTags = function(a,ab)
{	a = document.getElementById(a);
	if(a.value!="")
	{	b = document.getElementById(ab);
		s = document.createElement("span");s.id = "t"+a.value;
		i = document.createElement("input"); i.name = ab+"[]"; i.type = "hidden"; i.value = a.value;
		m = document.createElement("img"); m.src = "http://www.ivotings.com/public/images/del.gif"; m.align = "absmiddle";
		m.onclick = new Function("document.getElementById('"+ab+"').removeChild(document.getElementById('t"+a.value+"'));");
		s.appendChild(i);s.appendChild(document.createTextNode(a.value+" "));s.appendChild(m);s.appendChild(document.createElement("br"));
		b.appendChild(s);
		a.value = "";
	}
}
gst.prototype.lightBoxClose = function(url)
{	if(url)document.getElementById(url).style.display = "none";
	document.getElementById("wrap").style.display = "none";
}
gst.prototype.toggleLogin = function()
{	s = document.getElementById('search');
	l = document.getElementById('login');
	if(s.style.display=="none")
	{	s.style.display="block";
		l.style.display="none";
	}
	else
	{	s.style.display="none";
		l.style.display="block";
	}
}
gst.prototype.toggleForm = function()
{	F = document.getElementsByTagName("form");
	for(i=0;i<F.length;i++)
	{	if(F[i].title=="toggleValues")
		{	var I = F[i].getElementsByTagName("input");
			for(j=0;j<I.length;j++)
			{
				if(I[j].title!="")
				{	I[j].value = I[j].title;
					I[j].onfocus = I[j].onblur = this.toggleFValue;
				}
			}
		}
	}
}
function objShow(id,h)
{
	obj = document.getElementById(id);
	oH = parseInt(obj.style.height);
	if(oH<h)
	{	oH = oH+5;
		obj.style.height = oH+"px";
		setTimeout("objShow('"+obj.id+"',"+h+")",0);
	}
}
function objHide(id)
{
	obj = document.getElementById(id);
	oH = parseInt(obj.style.height);
	if(oH>0)
	{	oH = oH-5;
		obj.style.height = oH+"px";
		setTimeout("objHide('"+obj.id+"')",0);
	}
	else
	{	obj.style.display="none";
	}
}
gst.prototype.showHide = function(id,h)
{	obj=document.getElementById(id);objS=getElementsByAttribute("*", "slide")
	for(i=0;i<objS.length;i++)
	{	oBjT=null;
		if(objS[i].getAttribute("slide")==id)tgt = objS[i];
		else oBjT=document.getElementById(objS[i].getAttribute("slide")); 
		if(oBjT)oBjT.style.display="none";
	}
	if(obj)
	{	if(obj.style.display=="none")
		{	obj.style.display="block";
			obj.style.height = 0;	objShow(obj.id,h);
			tgt.innerHTML = tgt.innerHTML.replace(/Show/, "Hide");
		}
		else
		{	objHide(obj.id);
			tgt.innerHTML = tgt.innerHTML.replace(/Hide/, "Show");
		}	
	}
	else
	{alert("ERROR : Invalid ID passed to slide attribute.\n[CODE : gstNAobj.slide]")}
}
gst.prototype.upDown = function() 
{	objS = getElementsByAttribute("*", "slide")
	for(i=0;i<objS.length;i++)if(!objS[i].onclick)
	{	objS[i].style.cursor = "pointer";
		obj = document.getElementById(objS[i].getAttribute('slide'));
		if(obj){obj.style.overflow = "hidden";
		objS[i].onclick=new Function("gt.showHide('"+obj.id+"',"+obj.offsetHeight+")");
		obj.style.display="none";}
	}
}
gst.prototype.fav = function(id)
{	xmlhttp = gt.xmlHttp();xmlhttp.open('GET', "http://www.ivotings.com/contest/fav/select/"+id, true);xmlhttp.send(null);
	cN = document.getElementById("contextNote"); A = cN.getElementsByTagName("a")[0];
	cN.innerHTML = "Added to favorite! Go to "; cN.appendChild(A);
}
gst.prototype.processLogout = function()
{	this.displayError("Processing logout..",2000);
	setTimeout(function(){window.location.href="http://www.ivotings.com/user/logout/";},2000)
}
gst.prototype.displayError = function(msg,time)
{	obj = document.getElementById("tempDiv");
	if(obj)document.body.removeChild(obj);
	D = document.createElement('div');
	D.innerHTML = "<div style=\"background:url(http://www.ivotings.com/public/images/msgL.gif) no-repeat left bottom; cursor:pointer\"><div style=\"background:url(http://www.ivotings.com/public/images/msgR.gif) no-repeat right bottom; padding:0 17px \"><div style=\"background:#ff7c0c url(http://www.ivotings.com/public/images/msgC.gif) repeat-x bottom; padding:10px 5px 20px 5px; color:#FFFFFF;font-size:14px;\">"+msg+"</div></div></div>";
	D.style.position = "fixed";
	D.style.top = "-85px";
	D.onclick = hideError;
	if(document.width)
	{dW = document.width;}else
	{dW = document.body.clientWidth;}
	pL = parseInt(dW/2)-msg.length;
	D.style.left = pL+'px';
	D.id = "tempDiv";
	document.body.appendChild(D);
	showError();
	hideError(parseInt(time));
}
gst.prototype.toolTipInt = function()
{	l=getElementsByAttribute("*","tip");for(i=0;i<l.length;i++)if(l[i].getAttribute("tip")!=null)l[i].onmouseover=l[i].onmouseout=this.toolTip;
}
gst.prototype.toolTip = function(e)
{	if(!e)var e=window.event;obj=e.target?e.target:e.srcElement;
	if(e.type=="mouseover")
	{	x=document.createElement('span');x.className="tooltip";
		x.innerHTML = "<span class=\"top\"></span><span class=\"middle\">"+obj.getAttribute("tip")+"</span><span class=\"bottom\"></span>";obj.appendChild(x);
	}
	if(e.type=="mouseout")
	{	s = obj.getElementsByTagName("span");
		for(i=0;i<s.length;i++)if(s[i].className=="tooltip")obj.removeChild(s[i]);
	}
}
gst.prototype.toggleFValue = function(e)
{	if(!e)var e=window.event;obj=e.target?e.target:e.srcElement;
	if(e.type=="focus" && obj.value==obj.title)obj.value="";
	else if(obj.value=="")obj.value=obj.title;
	
}
function chkName(obj)
{	s = obj.parentNode.getElementsByTagName("span")[0];
	xmlhttp = gt.xmlHttp();
	xmlhttp.open('GET', "http://www.ivotings.com/"+obj.title+"/suggestions/name/"+obj.value, true);
	xmlhttp.onreadystatechange = function() 
	{	if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{	data = eval('(' + xmlhttp.responseText + ')');
			
			if(data.name==null)
			{	s.className = "hint"; s.innerHTML="Ok."; return true;
			}else
			{	obj.value=""; obj.focus();
				s.className = "error"; s.innerHTML="Name already exist"; return false;
			}
			data=null;
		}
	}
	xmlhttp.send(null);
}
function postNewContest()
{		gt.lightBoxClose('contest/create');
	gt.displayError('Oops! Login required to post an item!',5000);
	}
function addC(obj)
{	D = obj.parentNode.getElementsByTagName("div")[0];xmlhttp = gt.xmlHttp();
	if(!D){	D = document.createElement("div");	D.className = "suggB";	obj.parentNode.appendChild(D);}
	D.style.display = "block";	allCvrS = D.getElementsByTagName("div");
	for(i=0;i<allCvrS.length;i++){allCvrS[i].style.display="none";}
	Cvr = document.getElementById(obj.value);
	if(Cvr) Cvr.style.display = "block";
	else
	{	xmlhttp.open('GET', "http://www.ivotings.com/"+obj.id+"/suggestions/fetch/all/for/"+obj.value, true);
		xmlhttp.onreadystatechange = function() 
		{	if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
			{	Cvr = document.createElement("div"); Cvr.id = obj.value;
				if(xmlhttp.responseText.length>0)
				{	data = eval('(' + xmlhttp.responseText + ')'); A = document.createElement("span");
					A.appendChild(document.createTextNode("Please pick one below:")); Cvr.appendChild(A);
					for(i=0;i<data.length;i++)
					{	A = document.createElement("a");A.href = "javascript:;";A.appendChild(document.createTextNode(data[i].n));
						A.onclick = new Function('selectC("'+data[i].n+'","'+data[i].i+'","'+obj.id+'")');Cvr.appendChild(A);
				}	}
				else
				{	Cvr.appendChild(document.createTextNode("Item does not exist!"));
				}	
				D.appendChild(Cvr);
			}
		}
		xmlhttp.send(null);
	}
}
function putC(img)
{	obj=document.getElementById(img.title);i=obj.title;n=obj.value;obj.title=obj.value='';
	if(i){S=document.createElement("span");S.id=img.title+i;S.appendChild(document.createTextNode(n));
	I=document.createElement("img");I.src="http://www.ivotings.com/public/images/del.gif";I.align = "absmiddle";
	A=document.createElement("a");A.href = "javascript:;";A.onclick=new Function('removeC("'+img.title+i+'")');A.appendChild(I);
	I=document.createElement("input");I.value=i;I.name=img.alt;I.type="hidden";S.appendChild(I);S.appendChild(A);
	document.getElementById("cContainer").appendChild(S);}
}
function removeC(id)
{	document.getElementById("cContainer").removeChild(document.getElementById(id));
}
function selectC(n,i,id)
{	obj = document.getElementById(id); obj.title = i;	obj.value = n;
	allCvrS = obj.parentNode.getElementsByTagName("div"); for(i=0;i<allCvrS.length;i++){allCvrS[i].style.display="none";}
}
var gt=new gst;
