﻿document.write("<link rel=\"shortcut icon\" href=\"http://simg.gpotato.eu/common/favicon.ico\" />");

try
{
if(typeof HTMLElement != "undefined") {
	if(!HTMLElement.prototype.insertAdjacentElement) {
		HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode) {
			switch (where){
			case "beforeBegin":
				this.parentNode.insertBefore(parsedNode,this)
				break;
			case "afterBegin":
				this.insertBefore(parsedNode,this.firstChild);
				break;
			case "beforeEnd":
				this.appendChild(parsedNode);
				break;
			case "afterEnd":
				if (this.nextSibling) this.parentNode.insertBefore(parsedNode,this.nextSibling);
				else this.parentNode.appendChild(parsedNode);
				break;
			}
		}

		HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr) {
			var r = this.ownerDocument.createRange();
			r.setStartBefore(this);
			var parsedHTML = r.createContextualFragment(htmlStr);
			this.insertAdjacentElement(where,parsedHTML)
		}

		HTMLElement.prototype.insertAdjacentText = function(where,txtStr) {
			var parsedText = document.createTextNode(txtStr)
			this.insertAdjacentElement(where,parsedText)
		}
	}

	if(!HTMLElement.prototype.innerText) {
		HTMLElement.prototype.__defineGetter__("innerText", function() { return this.textContent; }); 
		HTMLElement.prototype.__defineSetter__("innerText", function(txt) { this.textContent = txt; }); 
	}

	if(!HTMLImageElement.prototype.nameProp) {
		HTMLImageElement.prototype.__defineGetter__("nameProp", function() { return this.src.substring(this.src.lastIndexOf("/") + 1); }); 
	}
}
}
catch(e)
{
}

function FnGetObjById(sID, obj)
{
	return obj.getElementById(sID);
}

function FnTrim(sStr)
{
	try
	{
		return sStr.replace(/(^[\s¡¡]+)|([\s¡¡]+$)/g, "");
	}
	catch(Exception)
	{
		return sStr;
	}
}

function FnGetLegnth(sStr)
{
	try
	{
		var nCnt = 0;
		var sTmp;

		for (i = 0; i < sStr.length; i++)
		{
			sTmp = escape(sStr.substring(i, i+1));
			if(sTmp.substring(1,2) == "u" )
				nCnt += 2;
			else
				nCnt += 1;
		}
		return nCnt;
	}
	catch(Exception)
	{
		return -1;
	}
}

function FnIsEmpty(obj)
{
	try
	{
		if(!obj)							return true;
		if(!obj.value)						return true;
		if(FnTrim(obj.value)	== "")		return true;

		return false;
	}
	catch(Exception)
	{
		return true;
	}
}

function FnChkEmail(s) 
{
	var sChk = "";
	var nCnt = 0;
	var nLen = s.length;
	var regDoNot = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
	var regMust = /^[-a-zA-Z0-9_]+@([-a-zA-Z0-9]+\.)+[a-zA-Z]{2,3}$/;

	if (s.indexOf(" ") != -1 || s.indexOf("<") != -1 || s.indexOf(">") != -1) {
		return false;
	}

	if (s.indexOf("@") == -1) {
		return false;
	}

	if (s.indexOf(".") == -1) {
		return false;
	}

	if (s.indexOf(".") - s.indexOf("@") == 1) {
		return false;
	}

	if (s.charAt(s.length-1) == ".") {
		return false;
	}

	if (s.charAt(s.length-1) == "@") {
		return false;
	}

	if (s.length < 7) {
		return false;
	}
	else {
		for (i = 0 ; i < nLen ; i++) {
			temp = s.substring(i,i+1);
			if ((temp == "@" && i < 2) || (temp == "." && i < 4)) {
				return false;
			}
			else {
				if (temp == "@" || temp == ".") sChk = sChk + temp;
			}
		}
		if (sChk.substring(0,2) == "@.") {
			if (!regDoNot.test(s) && regMust.test(s))
				return true;
			else
				return false;
		}
		else
			return false;
	}
}

function FnChkNumber(sTxt)
{
	var objRegExp1 =/^[0-9]/;
	var sTmp
	sTxt = sTxt.toLowerCase();

	for(i=0;i<sTxt.length;i++){
		sTmp = sTxt.substring(i, i+1)
		if (!objRegExp1.test(sTmp)) {
			return false;
		}
	}
	return true;
}

function FnChkAlphaNum(sTxt)
{
	var objRegExp1 =/^[0-9]/;
	var objRegExp2 = /^[a-z]/;
	var sTmp
	sTxt = sTxt.toLowerCase();

	for(i=0;i<sTxt.length;i++){
		sTmp = sTxt.substring(i, i+1)
		if (!objRegExp1.test(sTmp)) {
			if (!objRegExp2.test(sTmp)) {
				return false;
			}
		}
	}
	return true;
}

function FnChkAlpha(sTxt)
{
	var objRegExp1 =/^[a-z]/;
	var sTmp
	sTxt = sTxt.toLowerCase();
	
	for(i=0;i<sTxt.length;i++){
		sTmp = sTxt.substring(i, i+1)
		if (!objRegExp1.test(sTmp)) return false;
	}
	return true;
}

function FnChkIncSpace(sTxt)
{
	var objRegExp1 =/^[a-z]/;
	var sTmp
	sTxt = sTxt.toLowerCase();

	for(i=0;i<sTxt.length;i++){
		sTmp = sTxt.substring(i, i+1)
		if (sTmp == " ") return true;
	}
	return false;
}

function FnGetObjXMLHttpRequest() 
{

    var objReq = false;
    if (window.XMLHttpRequest)
	{
        objReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) 
	{
        try 
		{
            objReq = new ActiveXObject("Msxml2.XMLHTTP");
        } 
		catch (e1) 
		{
            try
			{
                objReq = new ActiveXObject("Microsoft.XMLHTTP");
            } 
			catch (e2)
			{
                return null;
            }
        }
    }
    return objReq;
}

function FnSendHttpRequest(objReq, sUrl, sParam, sMethod, sTarget)
{
	FnShowStatus("V");
	objReq.open(sMethod, sUrl, true);
	objReq.onreadystatechange = FnReceiveCallBack(objReq, sTarget);
	objReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	objReq.setRequestHeader("Cache-Control","no-cache, must-revalidate");
	objReq.setRequestHeader("Pragma","no-cache");
	objReq.send(sParam);
}

function FnReceiveCallBack(objReq, sTarget) {

    return function () {
		switch (objReq.readyState) {
        case 0 :
        case 1 :
        case 2 :
        case 3 :
        break;
        case 4 :
            if (objReq.status == 200) {
				FnShowStatus("H");
				setTimeout(sTarget, 0);
            } else {
                alert("HTTP error: "+objReq.status);
            }
        break;
        }
    }
}


  /*=============================================================================
    use : flash write
    @Param : string Object URL, int Width, int Height[, string Variable, string Background Color, string Window Mode]
 =============================================================================*/
function ObFlashWrite(sObjURL, nWidth, nHeight, sVars, sBgColor, sWinMod){
	
	var sObjId = sObjURL.split("/")[sObjURL.split("/").length-1].split(".")[0];
	if(sVars == null) sVars = '';
	if(sBgColor == null) sBgColor = '#FFFFFF';
	if(sWinMod == null) sWinMod = 'transparent';

	// flash code definition
	var flashStr= "	<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'";
		flashStr+="			codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0'";
		flashStr+="			width='" + nWidth +"'";
		flashStr+="			height='" + nHeight + "'";
		flashStr+="			id='" + sObjId + "'";
		flashStr+="			align='middle'>";

		flashStr+="		<param name='allowScriptAccess' value='always' />";
		flashStr+="		<param name='movie' value='" + sObjURL + "' />";
		flashStr+="		<param name='FlashVars' value='" + sVars + "' />";
		flashStr+="		<param name='wmode' value='" + sWinMod + "' />";
		flashStr+="		<param name='menu' value='false' />";
		flashStr+="		<param name='quality' value='high' />";
		flashStr+="		<param name='bgcolor' value='" + sBgColor + "' />";
	
	
		flashStr+="		<embed src='" + sObjURL + "'";
		flashStr+="		       flashVars='" + sVars + "'";
		flashStr+="		       wmode='" + sWinMod + "'";
		flashStr+="		       menu='false'";
		flashStr+="		       quality='high'";
		flashStr+="		       bgcolor='" + sBgColor + "'";
		flashStr+="		       width='" + nWidth + "'";
		flashStr+="		       height='" + nHeight + "'";
		flashStr+="		       name='" + sObjId + "'";
		flashStr+="		       align='middle'";
		flashStr+="		       allowScriptAccess='always'";
		flashStr+="		       type='application/x-shockwave-flash'";
		flashStr+="		       pluginspage='http://www.macromedia.com/go/getflashplayer' />";
		flashStr+=" </object>";

	// flash code print
	document.write(flashStr);
}

var objDivStatus			= null;

function FnShowStatus(sType)
{
	objDivStatus		= FnGetObjById("DivStatus",			document);
	objDivStatus.style.display = (sType == "H") ? "none":"block";
}

/*==========================================================================
	Focusing specific form
==========================================================================*/
function FnFocusingForm(obj, sclassName)
{
	obj.className = sclassName;
	obj.focus();
}

function FnGetObjById(sID, obj){
	if(!obj) obj = document;

	return document.getElementById(sID);
}

/*=============================================================================
	use : flash write
  @Param : string Object URL, int Width, int Height[, string Variable, string Background Color, string Window Mode]
=============================================================================*/
function ObFlashWrite(sObjURL, nWidth, nHeight, sVars, sBgColor, sWinMod){
	
	var sObjId = sObjURL.split("/")[sObjURL.split("/").length-1].split(".")[0];
	if(sVars == null) sVars = '';
	if(sBgColor == null) sBgColor = '#FFFFFF';
	if(sWinMod == null) sWinMod = 'transparent';

	// flash code definition
	var flashStr= "	<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'";
		flashStr+="			codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0'";
		flashStr+="			width='" + nWidth +"'";
		flashStr+="			height='" + nHeight + "'";
		flashStr+="			id='" + sObjId + "'";
		flashStr+="			align='middle'>";

		flashStr+="		<param name='allowScriptAccess' value='always' />";
		flashStr+="		<param name='movie' value='" + sObjURL + "' />";
		flashStr+="		<param name='FlashVars' value='" + sVars + "' />";
		flashStr+="		<param name='wmode' value='" + sWinMod + "' />";
		flashStr+="		<param name='menu' value='false' />";
		flashStr+="		<param name='quality' value='high' />";
		flashStr+="		<param name='bgcolor' value='" + sBgColor + "' />";
	
	
		flashStr+="		<embed src='" + sObjURL + "'";
		flashStr+="		       flashVars='" + sVars + "'";
		flashStr+="		       wmode='" + sWinMod + "'";
		flashStr+="		       menu='false'";
		flashStr+="		       quality='high'";
		flashStr+="		       bgcolor='" + sBgColor + "'";
		flashStr+="		       width='" + nWidth + "'";
		flashStr+="		       height='" + nHeight + "'";
		flashStr+="		       name='" + sObjId + "'";
		flashStr+="		       align='middle'";
		flashStr+="		       allowScriptAccess='always'";
		flashStr+="		       type='application/x-shockwave-flash'";
		flashStr+="		       pluginspage='http://www.macromedia.com/go/getflashplayer' />";
		flashStr+=" </object>";

	document.write(flashStr);
}


function FnGetObjByClassName(element, tagname, classname) {
	var alldescendants = (element || document.body).getElementsByTagName(tagname);
	for(var i=0; i<alldescendants.length; i++) {
		if(classname == null || alldescendants[i].className.indexOf(classname) > -1) {
			return alldescendants[i];
		}
	}
	return null;
}

function FnGetArrByClassName(element, tagname, classname) {
	var descendants = new Array();
	var alldescendants = (element || document.body).getElementsByTagName(tagname);
	for(var i=0; i<alldescendants.length; i++) {
		if(classname == null || alldescendants[i].className.indexOf(classname) > -1) {
			descendants.push(alldescendants[i]);
		}
	}
	return descendants;
}

function FnSWFLoad(filename, widths, heights, menus, plays, loops, id)
{
	var sTags = "";

	sTags += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
	sTags += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"';
	sTags += 'width="'+widths+'" height="'+heights+'" id="'+id+'" align="middle">';
	sTags += '<param name="wmode" value="transparent" />';
	sTags += '<param name="movie" value="'+filename+'" />';
	sTags += '<param name="quality" value="high" />';
	sTags += '<param name="allowScriptAccess" value="always" />';
	sTags += '<param name="menu" value="'+menus+'" />';
	sTags += '<param name="play" value="'+plays+'" />';
	sTags += '<param name="loop" value="'+loops+'" />';
	sTags += '<embed src="'+filename+'" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer"';
	sTags += 'type="application/x-shockwave-flash" width="'+widths+'" height="'+heights+'" name="'+id+'" align="middle"></embed>';
	sTags += '</object>';
	document.write(sTags);
}

function FnGetCommonHtml(sUrl)
{
	var objReq = FnGetObjXMLHttpRequest();

	objReq.open("GET", sUrl, false);
	objReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	objReq.setRequestHeader("Cache-Control","no-cache, must-revalidate");
	objReq.setRequestHeader("Pragma","no-cache");
	objReq.send("");

	document.write(objReq.responseText);
}

function FnOpenViewer(sUrl, nW, nH)
{
	try
	{
		var w=window.open(sUrl, "VIEWER", "modal=1, width=" + nW + ", height=" + nH);
	}
	catch(e)
	{
		var w=window.open(sUrl, "VIEWER", "modal=1, width=" + nW + ", height=" + nH);
		w.focus();
	}
}


String.prototype.trim = function() {
	return this.replace(/(^[\s　]+)|([\s　]+$)/g, "").replace(/　/g, "");
}

String.prototype.padLeft = function(nTotalWidth, sPaddingChar) {
	var sRtnVal = this.toString();
	var nRtnLen = sRtnVal.length;

	if(nRtnLen < nTotalWidth) {
		for(var i = 0; i < nTotalWidth - nRtnLen; i++)
			sRtnVal = sPaddingChar + sRtnVal;
	}

	return sRtnVal;
};

String.prototype.padRight = function(nTotalWidth, sPaddingChar) {
	var sRtnVal = this.toString();
	var nRtnLen = sRtnVal.length;

	if(nRtnLen < nTotalWidth) {
		for(var i = 0; i < nTotalWidth - nRtnLen; i++)
			sRtnVal = sRtnVal + sPaddingChar;
	}

	return sRtnVal;
};

function getFormTitle(obj, sTitle) {
	if(sTitle == null) sTitle = "";

	if(obj.parentNode.previousSibling.innerText)
		return obj.parentNode.previousSibling.innerText;
	else if(obj.parentNode.previousSibling.previousSibling.innerText)
		return obj.parentNode.previousSibling.previousSibling.innerText;
	else
		return sTitle;
}

function IsEmptyForm(obj, sTitle, objFocus) {
	if(obj.value.trim() == "") {
		if(sTitle == null || sTitle == "")
			sTitle = getFormTitle(obj, "The value");
		
		alert(sTitle + " is required.");
		
		if(objFocus) objFocus.focus();
		else obj.focus();
		
		return true;
	}
	else {
		return false;
	}
}

function IsDiffForm(obj1, obj2, sTitle1, sTitle2) {
	if(obj1.value.trim() != obj2.value.trim()) {
		if(sTitle1 == null || sTitle1 == "")
			sTitle1 = getFormTitle(obj1, "The value1");

		if(sTitle2 == null || sTitle2 == "")
			sTitle2 = getFormTitle(obj2, "the value2");
			
		alert(sTitle1 + " must be same as " + sTitle2 + ".");
		obj1.focus();
		return true;
	}
	else {
		return false;
	}
}

function removeBlankChild(obj) {
	if(obj.options[0].value == "")
		obj.options[0].parentNode.removeChild(obj.options[0]);
}

function addHandler(id, eventName, handler, elem)
{
    var elem = elem||document.getElementById(id);
    
    if( id == "window") elem = window;
    
    if( null == elem || typeof( elem ) == 'undefined' )
        return;    
    
    if (elem.addEventListener)
    {
        elem.addEventListener(eventName, handler, false);
    }
    else if (elem.attachEvent)
    {
        elem.attachEvent("on" + eventName, handler);
    }
    else
    {
        var origHandler = elem["on" + eventName];
        if (origHandler)
        {
            var h = new object();
            h.origHandler = origHandler;
            h.newHandler = handler;
            h.both = new function(e) { this.origHandler(e); this.handler(e); };
            elem["on" + eventName] = h.both;
        }
        else
        {
            elem["on" + eventName] = handler;
        }
    }
}

if (window.jQuery!=undefined)
{
        $(function()
        {
            initMenu();
            PreCache("http://simg.gpotato.eu/www/fr/index/sub_bg_left.png");
            PreCache("http://simg.gpotato.eu/www/fr/index/sub_bg_right.png");
            PreCache("http://simg.gpotato.eu/www/common/sprites/vertical_sprite.png");
            
            $("a").click(function()
            {
                $(this).blur();
            });
        });
}
function PreCache(img)
{
    var img_obj= new Image();
    img_obj.src=img;
}

function initMenu()
{
    $("#Td5").hover(function()
    {
        $("#SubMenu").stop(true, true).css({ "opacity": 0, "display": "block" }).fadeTo("fast", 0.88);
    },
    function()
    {
        $("#SubMenu").stop(true, true).fadeOut(100);
        selectedItem.deselect();
    });

    var menuImages = $("#TblMenu a img"),
        selectedItem = {
            _id: null,
            init: function()
            {
                var select = this;
                menuImages.each(function()
                {
                    select.download(select.toggle("#" + $(this).attr("id"), "on"));
                });
                return this;
            },
            select: function(id)
            {
                var select = this;
                select.deselect();
                select._id = "#" + id;
                this.set("on");
            },
            deselect: function()
            {
                var selected = this._id;
                if (selected != null)
                {
                    this.set("off");
                }
            },
            download: function(src)
            {
                var img = new Image();
                img.src = src;
            },
            set: function(option)
            {
                $(this._id).attr("src", this.toggle(this._id, option));
            },
            toggle: function(id, option)
            {
                var src = $(id).attr("src");
                return src != null ? src.replace(new RegExp("\_" + (option == "off" ? "on" : "off") + "\.", "i"), "_" + option + ".") : "";
            }
    }.init();

    $("#SubMenuTd ul").hover(function()
    {
        selectedItem.select($(this).attr("class"));
    });
    menuImages.hover(function()
    {
        selectedItem.select($(this).attr("id"));
    });
}
function ShowNewsIframe(){
    $("#content_loader").css("visibility","hidden");
    $("#news_content").css("visibility","visible");
}
function HideNewsIframe(){
    $("#news_content").css("visibility","hidden");
    $("#content_loader").css("visibility","visible");
}