
function init(iLang, iCur)
{
	//RotateRight(iLang, iCur);

	jQuery("#messageboard").css("width", jQuery("body").innerWidth() + "px");
	
	jQuery("body").scroll(function ()
				{
					jQuery("#messageboard").css("bottom", (jQuery("body").scrollTop() - 6) + "px");
				});
}

function chgImage(sId, sImg)
{
	//document.getElementById(sId).src = "images/" + sImg;
	
	document.getElementById(sId).src = sImg;
}

function chgBgImage(sId, sImg)
{
	jQuery("#"+sId).css("background-image", sImg);

	//document.getElementById(sId).src = "images/" + sImg;
}

function flashOut(o)
{
	jQuery(o).fadeTo("fast",0.5,function () {jQuery(o).fadeTo("fast",1)});
}

function flashIn(o)
{
	jQuery(o).fadeTo("fast",0.5,function () {jQuery(o).fadeTo("fast",0.0)});
}

var aImages;
var iSelectedImage = 0;
var iNbImages = 0;
var oImg;
									

function countNumImages()
{
	iC = 0;

	for (i = 0; i < aImages.length; i++)
	{
		if (aImages[i].length > 0)
		{
			iC++;
		}
	}

	return iC;
}

function animateViewer(sType)
{
	jQuery("#imageViewer").css("left",(jQuery(document).innerWidth()/2)-(jQuery("#imageViewer").width()/2));
	jQuery("#imageViewer").css("top", (window.screen.height/2)-(jQuery("#imageViewer").height()/2));

	switch (sType)
	{
		case "close":
			jQuery(oImg).attr("src","http://www.spytronic.com/produits/images/ajax-loader.gif");
			jQuery("#imageViewer").animate( {
							opacity:0,
							width:"100px",
							height:"100px",
							left:((jQuery(document).innerWidth()/2)-(100/2))+"px",
							top:((window.screen.height/2)-(100/2))+"px"
							}, 1000, 'swing', function () {
											jQuery(this).hide();
											});
			break;
		case "open":
			jQuery("#imageViewer").animate( {
							opacity:1,
							width:"700px",
							height:"660px",
							left:((jQuery(document).innerWidth()/2)-(700/2))+"px",
							top:((window.screen.height/2)-(660/2))+"px"
							}, 1000, 'swing', function () {
											jQuery(oImg).attr("src","http://www.spytronic.com/produits/images/"+aImages[iSelectedImage]);
											});
			break;
	}
}

function setImageByKey(iKey)
{
	jQuery(oImg).attr("src", "http://www.spytronic.com/produits/images/"+aImages[iKey]);
}

function showBackDrop()
{
	jQuery("#BD").width(jQuery("body").innerWidth());
	jQuery("#BD").height(jQuery("body").innerHeight());
	
	jQuery("#BD").show();
	jQuery("#BD").fadeTo("fast", 0.75);
}

function hideBackDrop()
{
	jQuery("#BD").fadeTo("normal",0);
	jQuery("#BD").hide();
}

function showViewer(aI)
{
	oImg = jQuery("#receptacle");

	aImages = aI;

	iNbImages = countNumImages();

	showBackDrop();
	
	animateViewer("open");
	//jQuery("#imageViewer").dialog();
}

function previousImage()
{
	t = iSelectedImage;
	
	if (--t < 0)
	{
		iSelectedImage = iNbImages - 1;
	}
	
	setImageByKey(iSelectedImage);
}

function nextImage()
{
	t = iSelectedImage;
	
	if (++t > iNbImages)
	{
		iSelectedImage = 0;
	}
	
	setImageByKey(iSelectedImage);
}

function closeViewer()
{
	animateViewer("close");

	hideBackDrop();
}

function enlargeImage()
{
	jQuery("#bgcover").width(jQuery(document).innerWidth());
	jQuery("#bgcover").height(jQuery(document).innerHeight());
	
	jQuery("#bgcover").show("fast");
	jQuery("#bgcover").fadeTo("fast", 0.75);
	
	jQuery("#bigimg").css("left",(jQuery(document).innerWidth()/2)-(jQuery("#bigimg").width()/2));
	jQuery("#bigimg").css("top", (window.screen.height/2)-(jQuery("#bigimg").height()/2));

	jQuery("#bigimg").show("scale",{percentage: 100, from: {width:1,height:1} },1000);
}

function hideImage()
{
	jQuery("#bgcover").fadeOut("normal");
	jQuery("#bigimg").fadeOut("fast");
}

function replaceImage(oImgSrc)
{
	jQuery("#main-image").fadeOut("normal",function () {
		sTempS = jQuery(oImgSrc).attr("src");
		sTempB = jQuery("#main-image").attr("src");
		
		jQuery(oImgSrc).attr("src", sTempB);
		jQuery("#main-image").attr("src", sTempS);
		
		jQuery("#main-image").fadeIn("normal");
	});
}

function validateEmail(iLang)
{
	oForm = jQuery("#form-small-newsletter");

	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

	var address = jQuery(":input[name=EMAIL]").attr("value");

	if(reg.test(address) == false) {
		
		switch (iLang)
		{
			case 0:
				alert('- Invalid Email Address');
				break;
			case 1:
				alert('- Adresse courriel invalide');
				break;
		}		
	}
	else
	{
		//alert("(c) Spytronic Inc.");
		oForm.submit();
	}
}

function validateLogin(iLang)
{
	oForm = jQuery("#form-login");

	sMsg = "";

	if (jQuery("#form-login :input[name=USER]").attr("value").length == 0)
	{
		switch (iLang)
		{
			case 0:
				sMsg += "- Please enter a user name.\n";
				break;
			case 1:
				sMsg += "- Veuillez entrer le nom d'usager.\n";
				break;
		}
	}
	
	if (jQuery("#form-login :input[name=PASS]").attr("value").length == 0)
	{
		switch (iLang)
		{
			case 0:
				sMsg += "- Please enter the password.\n";
				break;
			case 1:
				sMsg += "- Veuillez entrer le mot de passe.\n";
				break;
		}
	}
	
	if (sMsg.length != 0)
	{
		alert(sMsg);	
	}
	else
	{
		oForm.submit();
		//alert("(c) Spytronic Inc.");
	}
}

function validateCaptcha(iLang)
{
	oForm = jQuery("#form-captcha");
	
	if ($(":input[name=CAPTCHACODE]").attr("value").length == 0)
	{
		switch (iLang)
		{
			case 0:
				alert("- Please enter the code");
				break;
			case 1:
				alert("- Veuillez entrer le code");
				break;
		}
	}
	else
	{
		oForm.submit();
	}
}

function validateUnsubscription(iLang)
{
	oForm = jQuery("#form-unsubscribe-newsletter");
	
	if ($(":input[name=EMAIL]").attr("value").length == 0)
	{
		switch (iLang)
		{
			case 0:
				alert("- Please enter the email for unsubscription");
				break;
			case 1:
				alert("- Veuillez entrer le courriel de désabonnement");
				break;
		}
	}
	else
	{
		oForm.submit();
	}
}

G_OLDCOLOR = "";

function highlightBgOver(sId)
{
	G_OLDCOLOR = jQuery("#"+sId+" > tr").css("background-color");
	//jQuery("#"+sId+" > tr").removeClass("background-color", "transparent");
	jQuery("#"+sId+" > tr").css("background-image", "url(images/gris-opacity50.png)");
}


function highlightBgOut(sId)
{
	jQuery("#"+sId+" > tr").css("background-image", "none");
	jQuery("#"+sId+" > tr").css("background-color", G_OLDCOLOR);
}

function toggleAnswer(o, sSrcTag)
{
	switch (sSrcTag)
	{
		case 'div':
			switch (jQuery(o).next('span').text())
			{
				case "+":
					jQuery(o).next('span').text("-");
					break;
				case "-":
					jQuery(o).next('span').text("+");
					break;
			}
			break;
		case 'span':
			switch (jQuery(o).text())
			{
				case "+":
					jQuery(o).text("-");
					break;
				case "-":
					jQuery(o).text("+");
					break;
			}
			break;
	}
 
	jQuery(o).next('div').toggle();
}


function ServiceAjusterTexte(sType)
{
	switch (sType)
	{
		case 'S':
			jQuery("#C_SPY_ServicesPages *").css("font-size", "12px");
			break;
		case 'M':
			jQuery("#C_SPY_ServicesPages *").css("font-size", "14px");
			break;
		case 'L':
			jQuery("#C_SPY_ServicesPages *").css("font-size", "16px");
			break;
	}
}