/*************************************************************************
  This code is the property of iquizshare.com, all rights reserved!
  This notice must be retained in the code as is!
  Please email admin@iquizshare.com for questions.
*************************************************************************/

var xmlHttp
var answer
var tagstr
var count=0
var wrong=0
var persession=15
var persessionid=8
var corr=0
var correctnum=4
var wrongnum=7
	var t4s='<font face="Arial Black" color="#ff9900">4</font>';
	var t3s='<font face="Arial Black" color="#ff9988">3</font>';
	var t2s='<font face="Arial Black" color="#ffff00">2</font>';
	var t1s='<font face="Arial Black" color="#00ff00">Go!</font>';
var catarray = new Array(persession);
var qarray = new Array(persession);
var c1array = new Array(persession);
var c2array = new Array(persession);
var c3array = new Array(persession);
var c4array = new Array(persession);
var answerarray = new Array(persession);
var swear_words_arr=new Array("fuck","bloody","fukk","sex","bitch","blow job","suck my cock","cocksuck","cock suck","your mother","shit","suck cox","fuk off","lick it all","fuking","fuk you","fuk me","fuc you","fuc me","fukyou","fukme","fucme","fucyou","fuking","fucing");

var tagcat
var tagidd
var dname
var player

function get_rdm(str)
{
    var ranNum= Math.floor(Math.random()*str)+1;
    return ranNum;
}
function showRuleId(q,idd,cat,n,c,p){
	//window.resizeTo(370,690);
	if (document.all && window.attachEvent) window.attachEvent("onload", fixWinIE);
	document.getElementById('rule').style.visibility = 'visible';
	tagstr = q
	tagcat = cat
	tagidd = idd
	dname=n
	player=p
	var t = setTimeout("hideRuleId()",5000);
	var t4 = setTimeout("updatesec(t4s)",1000);
	var t3 = setTimeout("updatesec(t3s)",2000);
	var t2 = setTimeout("updatesec(t2s)",3000);
	var t1 = setTimeout("updatesec(t1s)",4000);
}

function showRule(str){
	window.resizeTo(370,690);
	if (document.all && window.attachEvent) window.attachEvent("onload", fixWinIE);

	if(str == "mix"){ 
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/iphonequiziconpng.png\">";
	}else if(str == "SAT"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/sat_icon.gif\">";
	}else if(str == "history"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/history_icon.gif\">";
	}else if(str == "entertainment"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/entertainment_icon.gif\">";
	}else if(str == "math"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/math_icon.gif\">";
	}else if(str == "madmath"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/madmath_icon.gif\">";
	}else if(str == "sports"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/sport_icon.gif\">";
	}else if(str == "science"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/science_icon.gif\">";
	}else if(str == "movie"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/movie_icon.gif\">";
	}else if(str == "geography"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/geography_icon.gif\">";
	}else if(str == "disney"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/disney_icon.gif\">";
	}else if(str == "harry_potter"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/spell_icon.gif\">";
	}else if(str == "music"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/music_icon.gif\">";
	}else if(str == "simpsons_movie"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/simpsons_icon.gif\">";
	}else if(str == "animal"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/animal_icon.gif\">";
	}else if(str == "2008"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/2008_icon.gif\">";
	}else if(str == "SuperMath"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/SuperMath_icon.gif\">";
	}else if(str == "beer"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/beer_icon.gif\">";
	}else if(str == "halo"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/halo_icon.gif\">";
		document.getElementById("questionbox").style.background= "url('images/halo_bg.gif')";
	}else if(str == "caveman"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/caveman_icon.gif\">";
		document.getElementById("questionbox").style.background= "url('images/caveman_bg.gif')";
	}else if(str == "world_series"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/world_series_icon.gif\">";
		document.getElementById("questionbox").style.background= "url('images/world_series_bg.jpg')";
	}else if(str == "Halloween"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/halloween_icon.gif\">";
		document.getElementById("questionbox").style.background= "url('images/halloween_bg.gif')";
	}else if(str == "stock"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/stock_icon.gif\">";
		document.getElementById("questionbox").style.background= "url('images/stock_bg.jpg')";
	}else if(str == "superhero"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/superhero_icon.gif\">";
		document.getElementById("questionbox").style.background= "url('images/superhero_bg.gif')";
	}else if(str == "Christmas"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/Christmas_icon.gif\">";
		document.getElementById("questionbox").style.background= "url('images/Christmas_bg.jpg')";
	}else if(str == "JetLi"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/jetli_icon.gif\">";
		document.getElementById("questionbox").style.background= "url('images/jetli_bg.jpg')";
	}else if(str == "friends"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/friends_icon.gif\">";
		document.getElementById("questionbox").style.background= "url('images/friends_bg.jpg')";
	}else if(str == "valentine"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/valentine_icon.gif\">";
		document.getElementById("questionbox").style.background= "url('images/valentine_bg.jpg')";
	}else if(str == "snl"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/snl_icon.gif\">";
		document.getElementById("questionbox").style.background= "url('images/snl_bg.gif')";
	}else if(str == "lost"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/lost_icon.gif\">";
		document.getElementById("questionbox").style.background= "url('images/lost_bg.gif')";
	}else if(str == "office"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/office_icon.gif\">";
		document.getElementById("questionbox").style.background= "url('images/office_bg.jpg')";
	}else if(str == "Saint_Patrick"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/St_Patrick_icon.gif\">";
		document.getElementById("questionbox").style.background= "url('images/St_Patrick_bg.jpg')";
	}else if(str == "harrypotter"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/harrypotter_icon.gif\">";
		document.getElementById("questionbox").style.background= "url('images/harrypotter_bg.jpg')";
	}else if(str == "olympic"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/olympic_icon.gif\">";
		document.getElementById("questionbox").style.background= "url('images/olympic_bg.jpg')";
	}else if(str == "president"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/president_icon.gif\">";
	}else if(str == "tricky"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/tricky_icon.gif\">";
	}else if(str == "SouthPark"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/southpark_icon.gif\">";
	}else if(str == "House"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/house_icon.gif\">";
	}else if(str == "physics"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/physics_icon.gif\">";
	}else if(str == "biology"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/biology_icon.gif\">";
	}else if(str == "friday"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/friday_icon.gif\">";
	}else if(str == "MontyPython"){
		document.getElementById("qtype").innerHTML="<img height=38 width=38 src=\"images/montypython_icon.gif\">";
	}
	document.getElementById('rule').style.visibility = 'visible';
	tagstr = str
	var t = setTimeout("hideRule()",5000);
	var t4 = setTimeout("updatesec(t4s)",1000);
	var t3 = setTimeout("updatesec(t3s)",2000);
	var t2 = setTimeout("updatesec(t2s)",3000);
	var t1 = setTimeout("updatesec(t1s)",4000);
}

function fixWinIE() {
}


function hideRule(){
	document.getElementById('rule').style.visibility = 'hidden';
	showUser(tagstr);
}

function hideRuleId(){
	document.getElementById('rule').style.visibility = 'hidden';
	showUserId(tagstr,tagidd,tagcat);
}

function updatesec(sec){
		document.getElementById("ct").innerHTML=sec;	
}

function insertUser(obj){
	alert("obj");
}

function backtohome(){
	window.location = "http://iquizshare.com/iphone/";
	return true;
}

function reloadpage(url){
window.location = url;
}

function showUser(str)
 {
 count=0;
 catarray = new Array(persession);
 qarray = new Array(persession);
 c1array = new Array(persession);
 c2array = new Array(persession);
 c3array = new Array(persession);
 c4array = new Array(persession);
 answerarray = new Array(persession);
 xmlHttp=GetXmlHttpObject()
 if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request")
  return
  } 
 var url="getQuestion.php"
 url=url+"?q="+str+"&c="+persession
 url=url+"&sid="+Math.random()
 xmlHttp.onreadystatechange=stateChanged 
 xmlHttp.open("GET",url,true)
 xmlHttp.send(null)
 }

function showUserId(tagstr,tagidd,tagcat)
 {
 persession = persessionid;
 count=0;
 catarray = new Array(persession);
 qarray = new Array(persession);
 c1array = new Array(persession);
 c2array = new Array(persession);
 c3array = new Array(persession);
 c4array = new Array(persession);
 answerarray = new Array(persessionid);
 xmlHttp=GetXmlHttpObject()
 if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request")
  return
  } 
 var url="getQuestion.php"
 url=url+"?q="+tagstr+"&c="+persession+"&id="+tagidd+"&cat="+tagcat
 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"){
 var xmlDoc=xmlHttp.responseXML;
 for(var i=0; i<persession; i++){
	 catarray[i]=xmlDoc.getElementsByTagName("cat")[i].childNodes[0].nodeValue+" multiple choice";
	 qarray[i] = xml_replace(xmlDoc.getElementsByTagName("question")[i].childNodes[0].nodeValue);
	 c1array[i]=xml_replace(xmlDoc.getElementsByTagName("c1")[i].childNodes[0].nodeValue);
	 c2array[i]=xml_replace(xmlDoc.getElementsByTagName("c2")[i].childNodes[0].nodeValue);
	 c3array[i]=xml_replace(xmlDoc.getElementsByTagName("c3")[i].childNodes[0].nodeValue);
	 c4array[i]=xml_replace(xmlDoc.getElementsByTagName("c4")[i].childNodes[0].nodeValue);
	 answerarray[i]=xmlDoc.getElementsByTagName("answer")[i].childNodes[0].nodeValue;
	 //alert(qarray[i]);
	 //alert(c1array[i]);
	 //alert(c2array[i]);
	 //alert(c3array[i]);
	 //alert(c4array[i]);
	 //alert(answerrray[i]);
	 //alert(i);
	 //alert(persession);
 }
 nextq();
 }else{
 }

} 

function nextq(){
 if(count==persession){
		document.getElementById("cat").innerHTML="";
		document.getElementById("question").innerHTML="";
		document.getElementById('move4moola').style.visibility = 'hidden';
		document.getElementById('ads').style.visibility = 'visible';
		var return_value
		var catstr
		if(tagstr=="doc"){
			if(player == "Dr. Cool"){
				return_value = prompt("Congratulations! Input your name for the latest-score list!","Dr. Cool");
				catstr = dname;
				showCheck("<table border=0 cellspacing=10><tr><td class='button'><a href='http://iquizshare.com/iphone/quiz.php?q="+tagstr+"&c="+persession+"&id="+tagidd+"&cat="+tagcat+"&name="+dname+"&player="+player+"'><font color='green'>Try</font> Again</a></td><td></td><td class='button'><a href='http://iquizshare.com/iphone/iphonequiz.php'><font color='red'>New</font> Quiz</a></td></tr></table>");
			}else{
				return_value = player;
				catstr = dname;
				showCheck("<table border=0 cellspacing=10><tr><td class='button'><a href='http://iquizshare.com/iphone/quiz.php?q="+tagstr+"&c="+persession+"&id="+tagidd+"&cat="+tagcat+"&name="+dname+"&player="+player+"'><font color='green'>Try</font> Again</a></td><td></td><td class='button'><a href='http://iquizshare.com/iphone/iphonequiz.php'><font color='red'>New</font> Quiz</a></td></tr></table>");
			}
		}else{
			return_value = prompt("Congratulations! Input your name for the latest-score list!","Dr. Cool");
			catstr = tagstr;
			showCheck("<table border=0 cellspacing=10><tr><td class='button'><a href='http://iquizshare.com/iphone/quiz.php?q="+tagstr+"'><font color='green'>Try</font> Again</a></td><td></td><td class='button'><a href='http://iquizshare.com/iphone'><font color='red'>New</font> Quiz</a></td></tr></table>");
		}

		for(var i=0; i<swear_words_arr.length; i++){
			for(var j=0; j<(return_value.length); j++){
				if(swear_words_arr[i]==return_value.substring(j,(j+swear_words_arr[i].length)).toLowerCase()){
					return_value = "Not Cool";
				}
			}
		}
		//alert(return_value+catstr)
		 var mn = corr * 1000;
		 var url="getTopten.php"
		 url=url+"?q="+return_value+"&cat="+catstr+"&score="+mn;
		 url=url+"&sid="+Math.random()
		 //alert(url)
		 xmlHttp.onreadystatechange=backtohome 
		 xmlHttp.open("GET",url,false)
		 xmlHttp.send(null)
		return;		
 }
 var dct = count + 1;
 var qct= dct + " of " + persession;
 document.getElementById("qct").innerHTML=qct;
 document.getElementById("cat").innerHTML=catarray[count];
 document.getElementById("question").innerHTML=qarray[count];
 document.getElementById("c1").innerHTML=c1array[count];
 document.getElementById("c2").innerHTML=c2array[count];
 document.getElementById("c3").innerHTML=c3array[count];
 document.getElementById("c4").innerHTML=c4array[count];
 answer=answerarray[count];
 count=count+1;
}

function GetXmlHttpObject()
 { 
 var objXMLHttp=null
 if (window.XMLHttpRequest)
  {
  objXMLHttp=new XMLHttpRequest()
  }
 else if (window.ActiveXObject)
  {
  objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
 return objXMLHttp
 }
 
 function checknext(st){
 	if(st==answer){
 		corr = corr + 1;
 		var fd = 'c'+st;
 		document.getElementById(fd).innerHTML='<font color="#00ff00">$1,000</font>';
 		var attributes = {
        	points: { to: [135, 42], control: [ [180, 42],[240, 42] ] }
    	};
		var anim = new YAHOO.util.Motion("win", attributes);
    	anim.animate();
    	document.getElementById("win").innerHTML="$" + corr + "," + "000";
 		var correctstr = "<img id='cor' src='images/correct"+get_rdm(correctnum)+".gif' border='black'>";
 		showCheck(correctstr);
		attributes = {
        	points: { to: [139, 130], control: [ [20, 65],[135, 2],[300, 65],[129, 135] ] }
    	};
    	anim = new YAHOO.util.Motion("cor", attributes);
    	anim.animate();
 		var t=setTimeout("clearA()",2000);
 	}
 	else{
 		wrong = wrong + 1;
 		var wrongstr = "<img id='wro' src='images/wrong"+get_rdm(wrongnum)+".gif' border='black'>";
 		showCheck(wrongstr);
		var attributes = {
        	points: { to: [139, 130], control: [ [300, 65],[135, 2],[20, 65],[149, 135] ] }
    	};
    	var anim = new YAHOO.util.Motion("wro", attributes);
    	anim.animate();
 		bleed();
 		for(var i=1; i<=4; i++){
 			if(i!=answer){
 				fd = 'c'+i;
 				document.getElementById(fd).innerHTML='';
 			}
 		}
 		var t=setTimeout("clearA()",1800);
 	}
 }
 
 function showCheck(str){
 	document.getElementById("check").innerHTML=str;
 }
  function clearA(){
 	document.getElementById("check").innerHTML="";
 	if(wrong < 3){
	 	nextq();
	}else{
		document.getElementById("cat").innerHTML="";
		document.getElementById("question").innerHTML="";
		document.getElementById("sessionend").innerHTML="<img src='images/over.gif'><br><font color='red'>Game Over</font>";
		if(tagstr=="doc"){
			showCheck("<table border=0 cellspacing=10><tr><td class='button'><a href='http://iquizshare.com/iphone/quiz.php?q="+tagstr+"&c="+persession+"&id="+tagidd+"&cat="+tagcat+"&name="+dname+"&player="+player+"'><font color='green'>Try</font> Again</a></td><td></td><td class='button'><a href='http://iquizshare.com/iphone/iphonequiz.php'><font color='red'>New</font> Quiz</a></td></tr></table>");
		}else{
			showCheck("<table border=0 cellspacing=10><tr><td class='button'><a href='http://iquizshare.com/iphone/quiz.php?q="+tagstr+"'><font color='green'>Try</font> Again</a></td><td></td><td class='button'><a href='http://iquizshare.com/iphone'><font color='red'>New</font> Quiz</a></td></tr></table>");
		}
		document.getElementById('sessionend').style.visibility = 'visible';
		document.getElementById('move4moola').style.visibility = 'hidden';
		document.getElementById('ads').style.visibility = 'visible';		
	}
 }
 
 function bleed() {
 	var w = 120 - wrong * 40;
    var attributes = {
    	width: { to: w }
    };
    var anim = new YAHOO.util.Anim('bloodmeter', attributes, 1, YAHOO.util.Easing.easeOut);
    anim.animate();
}

function updateUser(str){
	if (document.all && window.attachEvent) window.attachEvent("onload", fixWinIE);
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
  	}
	var url="getTopten.php"
	url=url+"?q="+str
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=collectUser 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
 
function collectUser() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		xmlDoc=xmlHttp.responseXML;
		var htmcode = '<table border=0 class="winnerlist">';
		var ll = xmlDoc.getElementsByTagName("name").length;
		var g;
		for(g = 0; g < ll; g++){
			 var ttname="<td>"+xmlDoc.getElementsByTagName("name")[g].childNodes[0].nodeValue+"</td>";
			 var ttcat="<td>"+xmlDoc.getElementsByTagName("cat")[g].childNodes[0].nodeValue+"</td>";
			 var ttscore="<td>"+xmlDoc.getElementsByTagName("score")[g].childNodes[0].nodeValue+"</td>";
			 htmcode = htmcode+"<tr>"+ttname+ttcat+ttscore+"</tr>";
		}
		htmcode = htmcode + '</table><div class="winner1"></div>';
		document.getElementById("winnerlist").innerHTML=htmcode;
	}
} 

  function menuswitch(obj) {
    var idiv=obj.href.split('#')[1];
    if(idiv=='quiz'){
		document.getElementById('qod').style.visibility = 'visible';
		document.getElementById('quiz').style.visibility = 'visible';
		//document.getElementById('score').style.visibility = 'hidden';
		document.getElementById('about').style.visibility = 'hidden';
	}
    if(idiv=='score'){
		document.getElementById('quiz').style.visibility = 'hidden';
		document.getElementById('qod').style.visibility = 'hidden';
		//document.getElementById('score').style.visibility = 'visible';
		document.getElementById('about').style.visibility = 'hidden';
	}
    if(idiv=='about'){
		document.getElementById('quiz').style.visibility = 'hidden';
		document.getElementById('qod').style.visibility = 'hidden';
		//document.getElementById('score').style.visibility = 'hidden';
		document.getElementById('about').style.visibility = 'visible';
	}
  }
  
  function xml_replace(strValue) {
	str = new String(strValue);
	str = str.replace(/\\/g,"");
	str = str.replace(/\[lt\]/g,"&lt;");
	str = str.replace(/\[gt\]/g,"&gt;");
	str = str.replace(/\[amp\]/g,"&");
	str = str.replace(/\[plus\]/g,"+");
	str = str.replace(/\[u\]/g,"<u>");
	str = str.replace(/\[i\]/g,"<i>");
	str = str.replace(/\[b\]/g,"<b>");
	str = str.replace(/\[\/u\]/g,"</u>");
	str = str.replace(/\[\/i\]/g,"</i>");
	str = str.replace(/\[\/b\]/g,"</b>");
	str = str.replace(/\[code\]/g,"<code>");
	str = str.replace(/\[quote\]/g,"\"");
	str = str.replace(/\[\/code\]/g,"</code>");
	str = str.replace(/\[\/quote\]/g,"\"");
	str = str.replace(/\[url\](.*)\[\/url\]/g,"<a href=\"$1\">$1</a>");
	str = str.replace(/\[img\](.*)\[\/img\]/g,"<img src=\"$1\">");
	//str = str.replace(//g,"</code>");
	//str = str.replace(/[url]/g,"<a href=>");
	//str = str.replace(/[img]/g,"<img src=>");
	str = str.replace(/\[br\]/g,"<br>");
	return str;
  }

