function doSearchAlpha(select_obj) {
    if (select_obj) {
        if (select_obj.options[select_obj.selectedIndex].value) {
            document.location.href = '/index.php?pg=products_listing&alpha=' + select_obj.options[select_obj.selectedIndex].value;
        }
    }
}

function doSearchPlatform(select_obj) {
    if (select_obj) {
        if (select_obj.options[select_obj.selectedIndex].value) {
            document.location.href = '/index.php?pg=products_listing&p=' + select_obj.options[select_obj.selectedIndex].value;
        }
    }
}

function doSearchGenre(select_obj) {
    if (select_obj) {
        if (select_obj.options[select_obj.selectedIndex].value) {
            document.location.href = '/index.php?pg=products_listing&g=' + select_obj.options[select_obj.selectedIndex].value;
        }
    }
}

//Open Popup Window
function pop(pg,id,id_screenshot){
	if(pg != undefined || pg != undefined || id != undefined) {
		var strURL;
		var attrib;
		var left = 100;
		var top = 100;
		var w;
		if (w) w.close();//close window first, if its there, in case we need to resize it...

		if(pg == 'friend'){ //Send to a Friend
		    strURL = "/index.php?pp=friend&id=" + id;
			attrib = "width=800,height=500,scrollbars=no,resizable=yes,left=" + left + ",top=" + top + "";
		}
		else if(pg == 'screenshots'){ // Products screenshots
			if (id_screenshot != undefined) {
				strURL = "/index.php?pp=screenshots&type=product&id=" + id + "&screenshotID=" + id_screenshot + "&popup=1";
				attrib = "width=750,height=500,scrollbars=no,resizable=yes,left=" + left + ",top=" + top + "";
			}
		}
		else if(pg == 'contests'){ //Contest Pictures
		    if (id_screenshot != undefined) {
		        strURL = "/index.php?pp=screenshots&type=contest&id=" + id + "&screenshotID=" + id_screenshot;
			    attrib = "width=760,height=500,scrollbars=no,resizable=yes,left=" + left + ",top=" + top + "";
			}
		}
		else if(pg == 'contests_rule'){ //Contest Rules
		    strURL = "/index.php?pp=contest&id=" + id + "&show_rules";
			attrib = "width=760,height=600,scrollbars=yes,resizable=yes,left=" + left + ",top=" + top + "";
		}
		else if(pg == 'download'){ //Download
		    strURL = "/index.php?pp=download&id=" + id;
			attrib = "width=950,height=450,scrollbars=yes,resizable=yes,left=" + left + ",top=" + top + "";
		}
		else if(pg == 'news'){ //News
			if (id_screenshot != undefined) {
				strURL = "/index.php?pp=screenshots&type=news&&id=" + id + "&screenshotID=" + id_screenshot;
				attrib = "width=760,height=500,scrollbars=yes,resizable=yes,left=" + left + ",top=" + top + "";
			}
		}
		else{
			return false;
		}
		w = window.open("http://" + document.domain + strURL,"atarifr",attrib);
		w.focus();
	}
	else{
		return false;
	}
}

//Popup
var initHeight = 300;
var nb_load_img = 0;
var heightResized = 0;
function changeImage(path) {
    var img = document.getElementById('big_screenshot');
    if (img) {
        img.src = path;
    }
}
function adjustHeight() {
    var img = document.getElementById('big_screenshot');
    if (img) {
        h = img.height;
        if ((h > initHeight)
        && (heightResized == 0)) {
            window.resizeBy(0, h - initHeight);
            heightResized = h - initHeight;
        }
        else if (nb_load_img > 0) {
            if (h < initHeight) {
                window.resizeBy(0, -heightResized);
                heightResized = 0;
            }
        }
    }
}
function OnLoadImage() {
    var img = document.getElementById('big_screenshot');
    if (img) {
        adjustHeight();
        nb_load_img++;
    }
}

// ----------------------------------------------------------------------------
// "account" page
//
// On change birthday
// in the account page
function changeBirthDay(ServerYear, ServerMonth, ServerDay, minorAge) {

    if (document.forms.length > 0) {
        var y = document.forms[0].Year;
        var m = document.forms[0].Month;
        var d = document.forms[0].Day;
        var age = 0;

        if (y && m && d) {
            var yInt = parseInt(y.options[y.selectedIndex].value);
            var mInt = parseInt(m.options[m.selectedIndex].value);
            var dInt = parseInt(d.options[d.selectedIndex].value);

            if (!isNaN(yInt)
            && !isNaN(mInt)
            && !isNaN(dInt)) {
                if ((ServerDay >= dInt
                && ServerMonth == mInt)
                || ServerMonth > mInt) {
                // Birthday is already passed, in the current year
                    age = ServerYear - yInt;
                }
                else {
                // Birthday is not passed, in the current year
                    age = ServerYear - yInt - 1;
                }

                if (age > 0) {
                    var h1 = document.getElementById('header_info');
                    var c1 = document.getElementById('content_info');
                    var f1 = document.getElementById('footer_info');

                    var h2 = document.getElementById('header_games');
                    var c2 = document.getElementById('content_games');
                    var f2 = document.getElementById('footer_games');

                    if (h1 && c1 && f1
                    && h2 && c2 && f2) {
                        var display = (age < minorAge ? 'none' : 'block');

                        h1.style.display = display;
                        c1.style.display = display;
                        f1.style.display = display;
                        h2.style.display = display;
                        c2.style.display = display;
                        f2.style.display = display;
                    }
                }
            }
        }
    }
}
// ----------------------------------------------------------------------------


// ----------------------------------------------------------------------------
// "newsletters" page
//
// Manage ToolTip Text
var offsetxpoint = 20; //Customize x offset of tooltip
var offsetypoint = 60; //Customize y offset of tooltip
var enabletip = false
var tipObject = null;

function isIE() {
    return document.all;
}

function isNS6() {
    return document.getElementById && !document.all;
}

function setToolTip(onObject, divObjectID, TheText, Color, Width){
    if (isIE()) {
        var divObject = document.all[divObjectID];
    }
    else if (isNS6()) {
        var divObject = document.getElementById(divObjectID);
    }
    if (divObject) {
        if (isIE() || isNS6()) {
            if (typeof Width != "undefined")
                divObject.style.width = Width + 'px';

            if (typeof Color != "undefined" && Color != "")
                divObject.style.backgroundColor = Color;

            divObject.innerHTML = TheText;
            tipObject = divObject;
            onObject.onmousemove = MoveToolTip;

            enabletip = true;
        }
    }
    else
        tipObject = null;
    return false;
}

function IETrueBody() {
    return (document.compatMode && document.compatMode!="BackCompat") ?
            document.documentElement : document.body;
}

function GetLeft(obj) {
    if (obj.offsetParent)
        return obj.offsetLeft + GetLeft(obj.offsetParent);
    else
        return obj.offsetLeft;
}
function GetTop(obj) {
    if (obj.offsetParent)
        return obj.offsetTop + GetTop(obj.offsetParent);
    else
        return obj.offsetTop;
}

function MoveToolTip(e) {

    if ((enabletip) && (tipObject)) {

        var curX = (isNS6()) ? e.pageX : event.clientX + IETrueBody().scrollLeft;
        var curY = (isNS6()) ? e.pageY : event.clientY + IETrueBody().scrollTop;

        if (tipObject.parentNode) {
            curX -= GetLeft(tipObject.parentNode);
            curY -= GetTop(tipObject.parentNode);
        }

        tipObject.style.left = curX + offsetxpoint + 'px';
        tipObject.style.top = curY + offsetypoint + 'px';

        tipObject.style.visibility = 'visible';

    }

}

function HideToolTip(onObject, divObjectID){
    if (isIE()) {
        var divObject = document.all[divObjectID];
    }
    else if (isNS6()) {
        var divObject = document.getElementById(divObjectID);
    }

    onObject.onmousemove = null;

    if (divObject) {
        if (isIE() || isNS6()) {
            divObject.style.visibility = 'hidden';
            enabletip = false;
        }
    }
    else
        tipObject = null;
}

// ----------------------------------------------------------------------------


// ----------------------------------------------------------------------------
// "newsletters" page
//
// Manage dynamic search with HTTP request made by Javascript
var liveSearchReq = false;
var timeoutLaunched = null;
var liveSearchLast = '';
var completeProductName = '';
var liveInit = false;

var targetObject = null;        // an input text
var resultObject = null;        // a div
var resultListObject = null;    // an ul object, resultObject 's child
var selectedLIObject = null;    // an li object, resultListObject 's child
var productIDObject = null;     // an input hidden to store the productID

var prefixRequestPage = '';     // an request passed to the GET
                                // example : "/livesearch.php?q="
                                // The end will be completed with the search value

// on !IE we only have to initialize it once
if (window.XMLHttpRequest) {
	liveSearchReq = new XMLHttpRequest();
}

function liveSearchHideDelayed() {

	window.setTimeout('liveSearchHide()', 400);
}

function liveSearchHide() {

    if (resultObject)
    	resultObject.style.display = 'none';
}

function liveSearchStart(
    inputObject,
    resultObjectID,
    resultListObjectID,
    productIDObjectID,
    prefix) {

	if (timeoutLaunched) {
		window.clearTimeout(timeoutLaunched);
	}

	targetObject = inputObject;
	resultObject = document.getElementById(resultObjectID);
	resultListObject = document.getElementById(resultListObjectID);
	productIDObject = document.getElementById(productIDObjectID);

	prefixRequestPage = prefix;
	timeoutLaunched = window.setTimeout('liveSearchDoSearch()', 200);
}

function liveSearchDoSearch() {

    if ((targetObject) && (prefixRequestPage != '')) {

    	if (liveSearchLast != targetObject.value) {

    	    if (completeProductName != targetObject.value) {
                // Reinit the productID value, if the textbox product name value has changed
                productIDObject.value = '';
            }

        	if (liveSearchReq && liveSearchReq.readyState < 4) {
        		liveSearchReq.abort();
        	}
        	if (targetObject.value == '') {
        		liveSearchHide();
        		return false;
        	}
        	if (window.XMLHttpRequest) {
        	// branch for IE/Windows ActiveX version
        	}
        	else if (window.ActiveXObject) {
        		liveSearchReq = new ActiveXObject('Microsoft.XMLHTTP');
        	}
        	liveSearchLast = targetObject.value;
        	
        	liveSearchReq.onreadystatechange= liveSearchProcessReqChange;
        	liveSearchReq.open('GET', prefixRequestPage + targetObject.value);
        	liveSearchReq.send(null);
    	}

    }
}

function liveSearchProcessReqChange() {

	if (liveSearchReq.readyState == 4) {
		if (resultObject)
		    resultObject.style.display = 'block';

		if (resultListObject) {
		    resultListObject.innerHTML = liveSearchReq.responseText;    // should be a response in <li></li><li></li> format

		    if (resultListObject.innerHTML == '') {
		        liveSearchHide();
		    }
		}
	}
}

function doSelect(obj, productID) {

    if (targetObject) {
        targetObject.value = obj.innerHTML;
        completeProductName = targetObject.value;

        if (productIDObject) {
            productIDObject.value = productID;
        }
        liveSearchHide();
    }

    return false;
}
// ----------------------------------------------------------------------------