
var xhr = false;
var xhrl = false;
var leftarea = "";
var leftarea2 = "2";


var rightarea = '';
var rightarea2 = "2";


area="";



function initAll(area) {


       var areaSplit = area.split('&');
       var leftareaUF = areaSplit[0];
       leftarea = leftareaUF.replace("#!", "");
       rightarea = areaSplit[1];

      

       if(!leftarea && !rightarea)
           {
                 window.location.hash = "#!overview&communityreviews";
           }

       else if(leftarea == null)
           {
                leftarea = "overview";
           }

       else if(rightarea == null)
           {
                rightarea = "communityreviews";
           }


       
      


       if(leftarea != leftarea2)
           {
                document.getElementById("overview").className = "leftmenuitem";
        document.getElementById("features").className = "leftmenuitem";
        document.getElementById("video").className = "leftmenuitem";
        document.getElementById("screenshots").className = "leftmenuitem";
               if(leftarea=='overview' || leftarea=='')
            {
                leftarea = "overview";               
                document.getElementById("overview").className = "leftmenuitemcurrent";
               
		makeRequestLeft();
            }
            
            if(leftarea=='features')
                {

                    leftarea = "features";
                    document.getElementById("features").className = "leftmenuitemcurrent";
                    makeRequestLeft();
                }

            if(leftarea=='video')
                {
                    leftarea = "video";
                    document.getElementById("video").className = "leftmenuitemcurrent";
                    makeRequestLeft();
                }

            if(leftarea=='screenshots')
                {
                    leftarea = "screenshots";
                    document.getElementById("screenshots").className = "leftmenuitemcurrent";
                    makeRequestLeft();
                }
           }


       if(rightarea != rightarea2)
           {
                 document.getElementById("communityreviews").className = "rightmenuitem";
                 document.getElementById("postareview").className = "rightmenuitem";
               if(rightarea=='communityreviews' || !rightarea)
                {
                    rightarea = "communityreviews";
                    document.getElementById("communityreviews").className = "rightmenuitemcurrent";
                    makeRequestRight();
                }

                if(rightarea=='postareview')
                {
                    rightarea = "postareview";
                    document.getElementById("postareview").className = "rightmenuitemcurrent";

                    makeRequestRight();
                    
                }
           }
        

          
	document.getElementById("overview").onclick = function()
{
                leftarea = "overview";
               
		
                window.location.hash = "#!" + leftarea + "&" + rightarea;
                 initAll(window.location.hash)
		return false;
}
	
	document.getElementById("features").onclick = function ()
{
                leftarea = "features";
              
		
                 window.location.hash = "#!" + leftarea + "&" + rightarea;

                initAll(window.location.hash)
		return false;
}
        document.getElementById("video").onclick = function() {
                leftarea = "video";
              
		
               window.location.hash = "#!" + leftarea + "&" + rightarea;
                initAll(window.location.hash)
		return false;
	}
        document.getElementById("screenshots").onclick = function() {
		leftarea = "screenshots";
               
		
                window.location.hash = "#!" + leftarea + "&" + rightarea;
                 initAll(window.location.hash)
		return false;
	}
        document.getElementById("communityreviews").onclick = function() {
		rightarea = "communityreviews";
              
		
                 window.location.hash = "#!" + leftarea + "&" + rightarea;
                  initAll(window.location.hash)
		return false;
	}
        document.getElementById("postareview").onclick = function() {
		rightarea = "postareview";
              
		
               window.location.hash = "#!" + leftarea + "&" + rightarea;
                initAll(window.location.hash)
		return false;
	}

       
      leftarea2 = leftarea;
      rightarea2 = rightarea;
            
}

function makeRequestLeft() {
	if (window.XMLHttpRequest) {
		xhrl = new XMLHttpRequest();
              
	}
	else {
		if (window.ActiveXObject) {
			try {
				xhrl = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) { }
		}
	}

	if (xhrl)
        {          
                    xhrl.onreadystatechange = showContentsLeft;
                    var simulatorName = document.getElementById("simulatorName").innerHTML;
                    xhrl.open("GET", "/includes/public/"+leftarea+".php?simulatorName="+simulatorName, true);
                    xhrl.send(null);
        }         
   	else
        {
                    document.getElementById("leftinfo").innerHTML = "Sorry, but I couldn't create an XMLHttpRequest";             
	}
}

function showContentsLeft() {
	if (xhrl.readyState == 4) {
		if (xhrl.status == 200) {
			var outMsg = xhrl.responseText;
                     
		}
		else {
			var outMsg = "There was a problem with the request " + xhrl.status;
		}
                
                    document.getElementById("leftinfo").innerHTML = outMsg;
                  
                   
                              
                       
	}
            
}



function makeRequestRight() {
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
                
                

	}
	else {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) { }
		}
	}

	if (xhr)
        {
                    var simulatorName = document.getElementById("simulatorName").innerHTML;
                    xhr.onreadystatechange = showContentsRight;
                    xhr.open("GET", "/includes/public/"+rightarea+".php?simulatorName="+simulatorName, true);
                    xhr.send(null);
        }
   	else
        {
                    document.getElementById("rightcontent").innerHTML = "Sorry, but I couldn't create an XMLHttpRequest";
	}
}

function showContentsRight() {
	if (xhr.readyState == 4) {
		if (xhr.status == 200) {
			var outMsg = xhr.responseText;

		}
		else {
			var outMsg = "There was a problem with the request " + xhr.status;
		}

                    document.getElementById("rightcontent").innerHTML = outMsg;

                    

	}

}

function reviewPagination(page) {

        
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();

//Send the proper header infomation along with the request
	

	}
	else {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) { }
		}
	}

	if (xhr)
        {
                    params = "reviewpage="+page;
                    xhr.onreadystatechange = showContentsReviewPagination;
                    xhr.open("POST", "/includes/public/reviewPagination.php", true);
                    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                    xhr.setRequestHeader("Content-length", params.length);
                    xhr.setRequestHeader("Connection", "close");
                    xhr.send(params);
        }
   	else
        {
                    document.getElementById("pagedReviewsSurround").innerHTML = "Sorry, but I couldn't create an XMLHttpRequest";
	}
}

function showContentsReviewPagination() {
	if (xhr.readyState == 4) {
		if (xhr.status == 200) {
			var outMsg = xhr.responseText;
                          document.getElementById("pagedReviewsSurround").innerHTML = outMsg;

		}
		else {
			var outMsg = "There was a problem with the request " + xhr.status;
		}

                  



	}

}




