function gme_init() {
//get game code for page
gmea = ge('gme');
var nme = gmea.name;

//get main tab div and links
var tab_area = ge('tabs')
var atags = gt(tab_area, 'a')

for (var i = 0; i < atags.length; i++) {
atags[i].onclick = function() {
	redirect_function(this.getAttribute('class'),nme)
	return false;
	}
	
atags[i].onmouseover = function() {
	var clas = this.getAttribute('class').substr(4,3)
	if(clas == 'imp' || clas == 'rev') {
	var clas = 'my'+clas;
	}
	ge(clas).style.visibility="visible";
	}

atags[i].onmouseout = function() {
	var clas = this.getAttribute('class').substr(4,3)
	if(clas == 'imp' || clas == 'rev') {
	var clas = 'my'+clas;
	}
	ge(clas).style.visibility="hidden";
	}	
}

/////////////////////////
//change urls for news area
newsa = ge('news_area');
tgs = newsa.getElementsByTagName('a');

//get game code from html tag
gmea = ge('gme');
var nme = gmea.name;

//change urls to javascript for ajax
for (var i = 0; i < tgs.length; i++) {

nhf = ge(tgs[i].id)
nhf.href = "javascript:story('" + tgs[i].id + "', '" + nme + "')"

//////
}


}
addLoadEvent(gme_init)


function redirect_function(func, gme) {
var clsstr = func.substr(4,3);

if(clsstr == 'imp') {
imp(gme)
} else if(clsstr == 'rev') {
myrev(gme)
} else if(clsstr == 'dis') {
dis(gme)
} else if(clsstr == 'pro') {
pro(gme)
}

}




function fold_up(ID) {

lb_ID = "lb"+ID;
as_ID = "as"+ID;

document.getElementById(lb_ID).className="lb_area_u";

document.getElementById(as_ID).className="switch_u";
document.getElementById(as_ID).href="javascript:fold_down('"+ID+"')";

//delete up switch and replace with down
var mdiv=document.getElementById(as_ID);
while(mdiv.hasChildNodes() == true)
{
mdiv.removeChild(mdiv.childNodes[0]);
}

var addimg = document.createElement('img');
addimg.setAttribute("src", "images/gme/dn_switch.png");
addimg.className="dnsw_IMG";
mdiv.appendChild(addimg);

}

function fold_down(ID) {

lb_ID = "lb"+ID;
as_ID = "as"+ID;

document.getElementById(lb_ID).className="lb_area";

document.getElementById(as_ID).className="switch_d";
document.getElementById(as_ID).href="javascript:fold_up('"+ID+"')";
//delete down switch and replace with up

var mdiv=document.getElementById(as_ID);
while(mdiv.hasChildNodes() == true)
{
mdiv.removeChild(mdiv.childNodes[0]);
}

var addimg = document.createElement('img');
addimg.setAttribute("src", "images/gme/up_switch.png");
addimg.className="upsw_IMG";
mdiv.appendChild(addimg);
}

function fold_up_pt(ID) {

lb_ID = "lb"+ID;
as_ID = "as"+ID;

document.getElementById(lb_ID).className="lb_area_pt_u";
document.getElementById('ptBG').className="ptBG_IMG_u";

document.getElementById(as_ID).className="switch_u";
document.getElementById(as_ID).href="javascript:fold_down_pt('"+ID+"')";

//delete up switch and replace with down
var mdiv=document.getElementById(as_ID);
while(mdiv.hasChildNodes() == true)
{
mdiv.removeChild(mdiv.childNodes[0]);
}

var addimg = document.createElement('img');
addimg.setAttribute("src", "images/gme/dn_switch.png");
addimg.className="dnsw_IMG";
mdiv.appendChild(addimg);
}

function fold_down_pt(ID) {

lb_ID = "lb"+ID;
as_ID = "as"+ID;

document.getElementById(lb_ID).className="lb_area_pt_d";
document.getElementById('ptBG').className="ptBG_IMG";

document.getElementById(as_ID).className="switch_d";
document.getElementById(as_ID).href="javascript:fold_up_pt('"+ID+"')";

//delete down switch and replace with up
var mdiv=document.getElementById(as_ID);
while(mdiv.hasChildNodes() == true)
{
mdiv.removeChild(mdiv.childNodes[0]);
}

var addimg = document.createElement('img');
addimg.setAttribute("src", "images/gme/up_switch.png");
addimg.className="upsw_IMG";
mdiv.appendChild(addimg);
}



//code for my impression area
function imp(gme) {
mp = ge('imp_area');
imp_http(gme)
}

function imp_http(gme) {

mp = ge('imp_area');

//start ajax call shortcut
ajax_call()
  
 var url = 'http://www.gamerzlink.com/templates/ajax/myimp.php?gme='+gme+'&Date='+escape(new Date());
  http_request.onreadystatechange = alertContents;
    http_request.open('GET', url, true);
 http_request.send(null);

    function alertContents() {

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
//grab returning XML data
comment_l = http_request.responseXML.getElementsByTagName('imp');

for(i=0; i<comment_l.length; i++){
 id = comment_l[i].getAttribute('id')

 cID = comment_l[i].getElementsByTagName('cID')[0].firstChild.nodeValue;
 comment = comment_l[i].getElementsByTagName('comment')[0].firstChild.nodeValue;
 btitle = comment_l[i].getElementsByTagName('btitle')[0].firstChild.nodeValue;
 posted = comment_l[i].getElementsByTagName('posted')[0].firstChild.nodeValue;
 tme = comment_l[i].getElementsByTagName('tme')[0].firstChild.nodeValue;

//delete area
if (mp.hasChildNodes())
{
while( mp.firstChild ) {
    //delete all the stat info 
    mp.removeChild( mp.firstChild );
}
}

did = "imp"+id;
sid = "sp_"+id; 

//new main div
var impti = dce('div');
impti.id = did;
mp.appendChild(impti);

//div for imp title bar
	var tbar = dce('div');
	tbar.className = "imp_title";
	impti.appendChild(tbar);

		tbar.appendChild(document.createTextNode(id+'. '));
		b2 = dce('b')
		b2.appendChild(document.createTextNode(btitle));
		tbar.appendChild(b2);
	
		tbar.appendChild(dce('br'));
	
		spn = dce('span')
   		spn.appendChild(document.createTextNode('Posted on '+posted+' @ '+tme));
		spn.className="blog_imp";
		spn.id = sid;
   		tbar.appendChild(spn);

p1 = dce('p');
p1.className="bcomment";
p1.innerHTML = comment;
impti.appendChild(p1);

jumpScroll()
 }//end for
 
            } else {
                alert('There was a problem with the request.');
            }
        }
    }
}//end imp_http
//end of code for my impression area


//code for my review area
function myrev(gme) {
mp = ge('imp_area');
rev_http(gme)
}


function rev_http(gme) {

mp = ge('imp_area');

//start ajax call shortcut
ajax_call()
  
 var url = 'http://www.gamerzlink.com/templates/ajax/imp_mrev.php?gme='+gme+'&Date='+escape(new Date());
  http_request.onreadystatechange = alertContents;
    http_request.open('GET', url, true);
 http_request.send(null);
 
    function alertContents() {

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
//grab returning XML data
comment_l = http_request.responseXML.getElementsByTagName('rev');

for(i=0; i<comment_l.length; i++){
 id = comment_l[i].getAttribute('id')

 gname = comment_l[i].getElementsByTagName('gname')[0].firstChild.nodeValue;
 gr_rate = comment_l[i].getElementsByTagName('gr_rate')[0].firstChild.nodeValue;
 m_rate = comment_l[i].getElementsByTagName('m_rate')[0].firstChild.nodeValue;
 gp_rate = comment_l[i].getElementsByTagName('gp_rate')[0].firstChild.nodeValue;
 ov_rate = comment_l[i].getElementsByTagName('ov_rate')[0].firstChild.nodeValue;
 posted = comment_l[i].getElementsByTagName('posted')[0].firstChild.nodeValue;
 main_text = comment_l[i].getElementsByTagName('main_text')[0].firstChild.nodeValue;

//delete area
if (mp.hasChildNodes())
{
while( mp.firstChild ) {
    //delete all the stat info 
    mp.removeChild( mp.firstChild );
}
}
 
//new main div
var impti = dce('div');
mp.appendChild(impti);

//line for name and posted
b1 = dce('b')
b1.appendChild(document.createTextNode('Reviewed By: '));
impti.appendChild(b1);

impti.appendChild(document.createTextNode(gname));
impti.appendChild(document.createTextNode(' | '));

b2 = dce('b')
b2.appendChild(document.createTextNode('Posted: '));
impti.appendChild(b2);

impti.appendChild(document.createTextNode(posted));

//div for rev bar
	var rvbar = dce('div');
	rvbar.className = "rev_bar";
	impti.appendChild(rvbar);

		spn = dce('span')
   		spn.appendChild(document.createTextNode('Graphics: '));
		spn.className="rev_span";
   		rvbar.appendChild(spn);
		rvbar.appendChild(document.createTextNode(gr_rate));

		spn2 = dce('span')
   		spn2.appendChild(document.createTextNode('Music/Sound: '));
		spn2.className="rev_span";
   		rvbar.appendChild(spn2);
		rvbar.appendChild(document.createTextNode(m_rate));

		spn3 = dce('span')
   		spn3.appendChild(document.createTextNode('Gameplay: '));
		spn3.className="rev_span";
   		rvbar.appendChild(spn3);
		rvbar.appendChild(document.createTextNode(gp_rate));
	
		spn4 = dce('span')
   		spn4.appendChild(document.createTextNode('Overall: '));
		spn4.className="rev_span";
   		rvbar.appendChild(spn4);
		rvbar.appendChild(document.createTextNode(ov_rate));

p1 = dce('p');
p1.className="bcomment";
p1.innerHTML = main_text;
impti.appendChild(p1);




rev_http2(gme)
jumpScroll()
 }//end for
 
            } else {
                alert('There was a problem with the request.');
            }
        }
    }

}//end rev_http
//end of code for my review area

function rev_http2(gme) {

//start ajax call shortcut
ajax_call()
  
 var url = 'http://www.gamerzlink.com/templates/ajax/imp_mrev2.php?gme='+gme;
  http_request.onreadystatechange = alertContents;
    http_request.open('GET', url, true);
 http_request.send(null);
 

 function alertContents() {

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {

results = http_request.responseText;
p1.innerHTML = results;
p1.innerHTML += "<br /><br /><a href=\"javascript:jumptop()\" class=\"itop\">Top</a>";
 
            } else {
                alert('There was a problem with the request.');
            }
        }
    }

}//end rev_http
//end of code for my review area


function dis(gme) {

mp = ge('imp_area');

//start ajax call shortcut
ajax_call()
  
 var url = 'http://www.gamerzlink.com/templates/ajax/dis.php?pg='+gme+'&Date='+escape(new Date());
  http_request.onreadystatechange = alertContents;
    http_request.open('GET', url, true);
 http_request.send(null);

    function alertContents() {

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
//grab returning XML data
comment_l = http_request.responseXML.getElementsByTagName('imp');

//delete area
if (mp.hasChildNodes())
{
while( mp.firstChild ) {
    //delete all the stat info 
    mp.removeChild( mp.firstChild );
}
}

string ="<p class=\"imp_top\">This is a area where members can discuss anything about this game.  Only members can start topics, but anyone can post a comment.</p>";

for(i=0; i<comment_l.length; i++){
 id = comment_l[i].getAttribute('id')

 cID = comment_l[i].getElementsByTagName('cID')[0].firstChild.nodeValue;
 name = comment_l[i].getElementsByTagName('name')[0].firstChild.nodeValue;
 comment = comment_l[i].getElementsByTagName('comment')[0].firstChild.nodeValue;
 btitle = comment_l[i].getElementsByTagName('btitle')[0].firstChild.nodeValue;
 posted = comment_l[i].getElementsByTagName('posted')[0].firstChild.nodeValue;
 tme = comment_l[i].getElementsByTagName('tme')[0].firstChild.nodeValue;
 mtotal = comment_l[i].getElementsByTagName('mtotal')[0].firstChild.nodeValue;
 
did = "imp"+id;
sid = "sp_"+id; 
hid = "hc_"+id;

string += "<div id=\""+did+"\">";
string += "<div class=\"imp_title\" onclick=\"javascript:dis2('"+id+"', '"+comment_l.length+"', '"+gme+"', '"+cID+"')\" onmouseover=\"this.style.background='#2C3E4F'\" onmouseout=\"this.style.background='#425C77'\">";
string += "<span class=\"comm\">"+mtotal+"<span> Comments</span></span>";
string += "<span class=\"snum\">"+id+".</span> <b>"+btitle+"</b><br />";
string += "<span class=\"blog_imp\">Posted by "+name+" on "+posted+" @ "+tme+"</span>";
string += "</div>";
string += "<p class=\"bcomment\"><span style=\"display:none;\" id=\""+sid+"\">"+comment+"</span></p>";
string += "<div id=\""+hid+"\"></div>";
string += "</div>";

 }//end for
 
 mp.innerHTML = string;
 jumpScroll()
            } else {
                alert('There was a problem with the request.');
            }
        }
    }
} //end dis

function dis2(id, len, gme, cID) {
hc = ge('hc_'+id)

//close any open comments and delete sub_comments
for(i=0; i<len; i++){
i2 = i+1;
ge('sp_'+i2).style.display="none";

hc_d = ge('hc_'+i2)
//delete sub_comments area to hide
if (hc_d.hasChildNodes())
{
while( hc_d.firstChild ) {
    //delete all the stat info 
    hc_d.removeChild( hc_d.firstChild );
}
}

}
//open selected comment
ge('sp_'+id).style.display="inline";

//get related comments and insert them.
//start ajax call shortcut
ajax_call()
  
 var url = 'http://www.gamerzlink.com/templates/ajax/dis2.php?pg='+gme+'&cID2='+cID+'&Date='+escape(new Date());
  http_request.onreadystatechange = alertContents;
    http_request.open('GET', url, true);
 http_request.send(null);

    function alertContents() {

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
//grab returning XML data
comment_l = http_request.responseXML.getElementsByTagName('imp');

if(comment_l.length == 0){
string2 = "";
related = gme+"_"+cID;
} else {
string2 = "<h3 class=\"bh3\">User Comments...</h3>";
}

for(i=0; i<comment_l.length; i++){
 id = comment_l[i].getAttribute('id')

 cID = comment_l[i].getElementsByTagName('cID')[0].firstChild.nodeValue;
 related = comment_l[i].getElementsByTagName('related')[0].firstChild.nodeValue;
 name = comment_l[i].getElementsByTagName('name')[0].firstChild.nodeValue;
 scomment = comment_l[i].getElementsByTagName('scomment')[0].firstChild.nodeValue;
 posted = comment_l[i].getElementsByTagName('posted')[0].firstChild.nodeValue;
 tme = comment_l[i].getElementsByTagName('tme')[0].firstChild.nodeValue;

string2 += "<div class=\"s_posted\">";
string2 += "<span class=\"snum\">"+id+".</span> <span class=\"blog_imp_s\" id=\"$sid\">Posted by "+name+" on "+posted+" @ "+tme+"</span>";
string2 += "</div>";
string2 += "<p class=\"scomment\">"+scomment+"</p>";

}//end for

//insert comment form
string2 += "<div id=\"imp_form_area\">"
string2 += "<img src=\"images/gme/form_head.gif\" class=\"fhead_IMG\" alt=\"\" />";

string2 += "<div><p class=\"bot_pfp\">Share what you think about this, enter your comment about this topic.  Let us know what you think.  Login or join us to keep track of your comments.</p><br />";
string2 += "<form>";
string2 += "<input type=\"hidden\" name=\"pg\" value=\""+gme+"\" />";
string2 += "<input type=\"hidden\" name=\"related\" value=\""+related+"\" />";
string2 += "<div id=\"com_inputs\">";
string2 += "<label for=\"realname\">Name:</label><input type=\"text\" name=\"name_c\" id=\"name_c\" value=\"\" size=\"30\" maxlength=\"100\" onblur=\"form_off('name_c')\" onfocus=\"form_on('name_c')\" /><br />";
string2 += "<label for=\"email\">E-mail Address:</label><input type=\"text\" name=\"email\" id=\"email\" value=\"\" size=\"30\" maxlength=\"100\" onblur=\"form_off('email')\" onfocus=\"form_on('email')\" /><br />";
string2 += "<label for=\"message\">Comment:</label><textarea name=\"comment\" id=\"comment\" cols=\"50\" rows=\"5\" wrap=\"virtual\"  onblur=\"form_off('comment')\" onfocus=\"form_on('comment')\"></textarea>";
string2 += "</div><br />";
string2 += "<div id=\"com_sub\"><span><input type=\"button\" value=\"Leave Comment\" class=\"lbtn\" onmouseover=\"this.className='lbtn lbtnhov'\" onmouseout=\"this.className='lbtn'\" onclick = \"sub_com_add(this.form, '"+id+"')\" /></span></div>";

string2 += "</form></div>";
string2 += "<img src=\"images/gme/form_bot.gif\" class=\"fbot_IMG\" alt=\"\" />";
string2 += "</div>";

hc.innerHTML = string2;

} else {
            alert('There was a problem with the request.');
            }
        }
}

}//end dis2

function sub_com_add(frm, id) {

gme = frm.elements[0].value;
rela = frm.elements[1].value;
nme = frm.elements[2].value;
eml = frm.elements[3].value;
cmt = frm.elements[4].value;

//email validation/////
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(eml)){
} else {
eml = "";
}
///////////
//make sure all fields are filled in and change style accordingly
if("" == nme || "" == eml ||"" == cmt)
{
main = ge('imp_form_area');

main.getElementsByTagName('p')[0].firstChild.data = "Oops, please make sure to fill out the entire form if you want to submit a comment. Dont worry, all e-mail addresses are kept private.";
main.getElementsByTagName('p')[0].style.fontWeight = "bold";

if (cmt == "")
{
 gcom = ge('comment');
 gcom.style.backgroundColor = "#F3D0D0";
 gcom.onkeypress = function () { cval('comment');  }
 gcom.onfocus = "";

}
if (eml == "")
{
 gcom = ge('email');
 gcom.style.backgroundColor = "#F3D0D0";
 gcom.onkeypress = function () { cval('email');  }
 gcom.onfocus = "";
}
if (nme == "")
{
 gcom = ge('name_c');
 gcom.style.backgroundColor = "#F3D0D0";
 gcom.onkeypress = function () { cval('name');  }
 gcom.onfocus = "";
}

} else {
httpr(gme, rela, nme, eml, cmt)
}//end if
}//end sub_com_add

//function to add sub_comment to database after verification
function httpr(gme, rela, nme, eml, cm) {
ajax_call()

var url = 'http://www.gamerzlink.com/templates/ajax/leave_com.php';

    http_request.onreadystatechange = alertContents;
    http_request.open('POST', url, true);
    http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http_request.send('gme=' + gme + '&rela=' + rela + '&nme=' + nme + '&eml=' + eml + '&cmt=' + cmt);

function alertContents() {

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {

main = ge('imp_form_area');

if (main.hasChildNodes())
{
while( main.firstChild ) {
    //delete all
    main.removeChild( main.firstChild );
}
}

string2 = "<img src=\"images/gme/form_head.gif\" class=\"fhead_IMG\" alt=\"\" />";
string2 += "<div><p class=\"bot_pfp\">Thanks for leaving a comment!</p><br />";
string2 += "<img src=\"images/gme/form_bot.gif\" class=\"fbot_IMG\" alt=\"\" />";

main.innerHTML = string2;

            } else {
                alert('There was a problem with the request.');
            }
        }
    }

	
	
}//end httpr

function pro(gme) {
mp = ge('imp_area');

//delete area
if (mp.hasChildNodes())
{
while( mp.firstChild ) {
    //delete all the stat info 
    mp.removeChild( mp.firstChild );
}
}

//start ajax call shortcut
ajax_call()

 var url = 'http://www.gamerzlink.com/templates/ajax/pros_cons.php?gme='+gme+'&Date='+escape(new Date());
  http_request.onreadystatechange = alertContents;
    http_request.open('GET', url, true);
 http_request.send(null);

    function alertContents() {

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
			
			mp.innerHTML = http_request.responseText;
 
            } else {
                alert('There was a problem with the request.');
            }
        }
    }
jumpScroll()
}//end pro function
//end of code for my pros area

//form style changes
function form_on(ID) {
ge(ID).style.backgroundColor = "#FFFFF0";
}

function form_off(ID) {
ge(ID).style.backgroundColor = "";
}

function cval(gID) {
gcom = ge(gID);
gcom.style.backgroundColor = "#FFFFF0";
gcom.onfocus = function () { form_on(gID); }
}

//function to scroll page
function jumpScroll() {
   	window.scroll(0,600); // horizontal and vertical scroll targets
}

//function to scroll page
function jumptop() {
   	window.scroll(0,0); // horizontal and vertical scroll targets
}



function attempt_cycle(fimp) {
var f1 = fimp.elements[0].value;
var f2 = fimp.elements[1].value;
var sdiv = ge('stat_area');

ajax_call()
var url = 'http://www.gamerzlink.com/templates/php/attempt_cycle.php';
http_request.onreadystatechange = alertContents;
http_request.open('POST', url, true);
http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http_request.send('gme=' + f1 + '&ts=' + f2);

function alertContents() {
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
			delete_stuff(sdiv)
			var string = http_request.responseText;
			sdiv.innerHTML = string;
            } else {
                alert('There was a problem with the request.');
            }
        }
}

}
