var XMLHTTP = null;
var uscripts = new Array();
    uscripts["gametable2"] = "/tabledata2.php?table=";
    uscripts["articleprevdata"] = "/articleprevdata.php?id=";
    uscripts["articleprev"] = "/articleprevdata.php?showClose=no&id=";
    uscripts["movie"] = "/countmovie.php?id=";	
    uscripts["demotable"] = "/demotabledata.php?table=";
    uscripts["userrating"] = "/userrating.php?gameid=";
    uscripts["contrating"] = "/contrating.php?";
var curscript = "";
var loadimage = '/pics/loadingAnimation.gif';

if(window.XMLHttpRequest) {
	XMLHTTP = new XMLHttpRequest();
} else if(window.ActiveXObject) {
	try {
		XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (ex) {
		try {
			XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (ex) {
		
		}
	}
}

function getAjaxData(i, script) {
	if (XMLHTTP.readyState < 4) {
		XMLHTTP.abort();
	}
	curscript = script;
	var d = document.getElementById(curscript);
	d.innerHTML = "<table width=100% height=100%><tr><td align=center valign=center height=100% width=100%><img src='"+loadimage+"'/></td></tr></table>";
	XMLHTTP.open("GET", uscripts[script]+i);
	XMLHTTP.onreadystatechange = putData;
	XMLHTTP.send(null);
}

function doAjaxCall(i, script) {
	if (XMLHTTP.readyState < 4) {
		XMLHTTP.abort();
	}
	curscript = script;
	XMLHTTP.open("GET", uscripts[script]+i);
	XMLHTTP.send(null);
}	

function putData() {
	if(XMLHTTP.readyState == 4 && XMLHTTP.responseText != '') {
		var d = document.getElementById(curscript);
		d.innerHTML = XMLHTTP.responseText;
	}
}

function setMenuActive(elem) {
	for (var i=0; i < menus.length; ++i)
		 if(menus[i] == elem) {
			menus[i].style.backgroundImage = hover_menu;	
		 } else {
			menus[i].style.backgroundImage = norma_menu;	
		 }
}

function changeTab(id1, id2) {
		tab1 = document.getElementById(id1);
		tab2 = document.getElementById(id2);
		tab1.style.display = "block";
		tab2.style.display = "none";
	}

var marked_row = new Array;

var focus=0;
function onFocusSearch() {
	if(focus == 0) {
		focus = 1;
		document.search.searchstring.value='';
	}
}

function onBlurSearch() {
	if(focus > 0) {
		focus=0;
		document.search.searchstring.value='Spieletitel';
	}	
}

function checkAndSubmit() {
        var text = document.comment.opinion.value;
        if(text.length<20) {
                alert("Dein Kommentar muss mindestens 20 Zeichen lang sein!");
                return false;
        } else {
                var woerter = text.split(" ");
                if(woerter.length < 3) {
                        alert("Dein Kommentar muss wenigstens 3 Wörter enthalten.");
                } else {
        		document.comment.submit();
        	}
        }
}

function setCellColor(theCell, theAction, theDefaultColor, theHighlightColor)
{
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    if (typeof(window.opera) == 'undefined'
        && typeof(theCell.getAttribute) != 'undefined') {
        currentColor = theCell.getAttribute('bgcolor');
	if(currentColor==null) {
		currentColor=theDefaultColor;
	}
        domDetect    = true;
    }
    else {
        currentColor = theCell.style.backgroundColor;
        domDetect    = false;
    }
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && theHighlightColor != '') {
            newColor = theHighlightColor;
        }
    }
    else if (currentColor.toLowerCase() == theHighlightColor.toLowerCase()) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
    }

    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
               theCell.setAttribute('bgcolor', newColor, 0);
        }
        // 5.2 ... with other browsers
        else {
              theCell.style.backgroundColor = newColor;
        }
    } // end 5

    return true;
} // end of the 'setCellColor()' function 
 
function setPointer(theRow, theRowNum, theAction, theDefaultColor, theHighlightColor, theMarkColor)
{
    var theCells = null;
    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((theHighlightColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
	if(currentColor==null) {
		currentColor=theDefaultColor;
	}
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && theHighlightColor != '') {
            newColor              = theHighlightColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == theHighlightColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (theHighlightColor != '')
                                  ? theHighlightColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

function showTest(link) {
	if(link != "") {
		document.location.href='?flap=5&r=14&file=showTest.php&id='+link;
	}
}


