
// JavaScript Document
window.onerror= function(){ }

function selectSubmitMode(mode)
{
   
    if(mode==0)
    {
        showDiv();
    }
    else
    {
        hideDiv();
    }
}
function hideDiv() { 
		document.getElementById('ordilocal').style.display = 'none';
		document.getElementById('formatnonum').style.display = 'block';
}

function showDiv() {
		document.getElementById('ordilocal').style.display = 'block';
		document.getElementById('formatnonum').style.display = 'none';
}

// used in cart
function shows(id, code, obj) {

        if(obj)
            obj.style.backgroundImage= "url(images/fr/media.jpg)";
		var toShow = document.getElementById(id+code);
		toShow.style.visibility = 'visible';
		
        var img    = document.getElementById(code);
        if(img){
            img.style.opacity=0.2;
			img.style.filter='alpha(opacity:20)'; //IE6
		}
		
        var title    = document.getElementById("title"+code);
        if(title){
            title.style.opacity=0.2;
			title.style.filter='alpha(opacity:20)'; //IE6
		}
}

function hides(id, code, obj) {
        if(obj)
            obj.style.backgroundImage= "none";
	var toHide = document.getElementById(id+code);
	toHide.style.visibility = 'hidden';
	
        var img = document.getElementById(code);
        if(img){
            img.style.opacity=1;
			img.style.filter='alpha(opacity:100)'; //IE6
		}
		
        var title = document.getElementById("title"+code);
        if(title){
            title.style.opacity=1;
			title.style.filter='alpha(opacity:100)'; //IE6
		}
}

function show(id, code, obj) {

        if(obj)
            obj.style.backgroundImage= "url(images/fr/mediatrans.gif)";
			var toShow = document.getElementById(id+code);
			toShow.style.visibility = 'visible';
	
        var img = document.getElementById(code);
       
	   if(img){
            img.style.opacity=0.2;
			img.style.filter='alpha(opacity:20)'; //IE6
		}
		
		var title = document.getElementById("title"+code);
       
	   if(title){
            title.style.opacity=0.2;
			title.style.filter='alpha(opacity:20)'; //IE6
		}
		
}

function hide(id, code, obj) {
        if(obj)
            obj.style.backgroundImage= "url(images/fr/media.jpg)";
	var toHide = document.getElementById(id+code);
	toHide.style.visibility = 'hidden';
	
        var img    = document.getElementById(code);
        if(img){
            img.style.opacity=1;
			img.style.filter='alpha(opacity:100)'; //IE6
		}
		
		var title = document.getElementById("title"+code);
        if(title){
            title.style.opacity=1;
			title.style.filter='alpha(opacity:100)'; //IE6
		}
}
function showMentions(show, hide)
{
	blockls    =   window.parent.document.getElementById('blocklegshow');
	pict       =   document.getElementById('pictransparent');
	showp      =   document.getElementById('showpic');
	hidep      =   document.getElementById('hidepic');
	mentions   =   document.getElementById('mentions');
	blocm      =   document.getElementById('blocmentions');

	if(!blockls || !pict || !showp || !hidep || !mentions || !blocm)
		return;

	if(mentions.style.display=='')
	{
		blockls.style.height    = '190px';
		showp.style.display		= 'none';
		pict.style.display		= 'block';
		hidep.style.display		= 'block';
		mentions.style.display	= 'block';
		blocm.style.display	    = 'block';
	}
	else if(mentions.style.display=='block')
	{
		blockls.style.height    = '40px';
		showp.style.display		= 'block';
		pict.style.display		= 'none';
		hidep.style.display		= 'none';
		mentions.style.display	= 'none';
		blocm.style.display	    = 'none';
	}
	else{
		blockls.style.height    = '190px';
		showp.style.display		= 'none';
		pict.style.display		= 'block';
		hidep.style.display		= 'block';
		mentions.style.display	= 'block';
		blocm.style.display	    = 'block';
	}
}

function checkPwdConfirm(theForm)
{
//	theForm = document.messageForm;
	if(!theForm)
		return;
	fp = theForm.s_pwd.value;
	sp = theForm.s_pwd2.value;
	p = document.getElementById("pwderrror");
	if(!sp)	 return;
	if(fp==sp)
	{
		p.style.color = "#00CC00";
		p.innerHTML = "&nbsp;<strong>ok</strong>";
	}
	else
	{
		p.style.color = "#cc0000";
		p.innerHTML = "&nbsp;<strong>X</strong>";
	}

}
function closeAndGotoDownload()
{
	alert("goto");
	setTimeout(function() { alert('close');closeLayer('winLayer', 'maskLayer'); } , 1000);
//	window.parent.document.location = "downloads.php?id=<?php echo $gOrderCode ?>";
}

function checkUQ(yoursearch)
{
	if(document.searchForm.query.value.length==0)
	{
		document.searchForm.query.value = 	yoursearch;
		return false;
	}
	else
		return true;
}
function searchKeyword(evt, yoursearch)
{
	if(evt.keyCode == 13)
	{
		if(checkUQ(yoursearch)==false)
			return false;
		document.searchForm.submit();
	}
}
function searchFor(yoursearch)
{
    if(document.searchForm.query)
    {
        document.searchForm.query.value = yoursearch;
        document.searchForm.submit();
    }
    
}
function swapImageStatus(obj)
{
	var f	= obj.src.toString();
	if(f.indexOf("_on.")!=-1)
		f	= f.replace("_on.","_off.");
	else
		f	= f.replace("_off.","_on.");
	obj.src = f;
}
function checkCgv(obj, img)
{
	if(obj.checked)
		document.getElementById("okbtn").innerHTML = '<a href="javascript:document.orderForm.submit()" ><img src="graphics/'+img+'" alt="ok" /></a>';
	else
		document.getElementById("okbtn").innerHTML = '<img src="graphics/'+img+'" alt="ok" />';
}
function popupCentrer(page, name, largeur,hauteur,options) {
  var top=(screen.height-hauteur)/2;
  var left=(screen.width-largeur)/2;
  return window.open(page,name,"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}
function popupCgv()
{
var option		= 'menubar=no,scrollbars=yes,statusbar=no,resizable=yes';
popupCentrer('cgv.php','popupcgv', 650,650, option);	
}
function launchSearch(ifId)
{
	var sValue		= trim(getSearchValue(ifId));
	if(document.searchForm && sValue.length)
	{
		if(document.searchForm.query)
		{
			document.searchForm.query.value = sValue;
			document.searchForm.submit();
		}
	}
}
function getSearchValue(ifId)
{
	var theIframe 	= document.getElementById(ifId);
	var theForm 	= getIframeContentObject(theIframe).keywordForm;

	var searchValue = '';
	for(i = 0 ; i < theForm.elements.length; i++)
	{
		if(theForm.elements[i].type == "checkbox" && theForm.elements[i].checked)
			searchValue += theForm.elements[i].value +" ";
	}	
	return searchValue;	
}

/*---------------------------- CART FUNCTIONS --------------------------------------*/
function showCart(show,hide)
{
	
        var content = document.getElementById('maindisplay');
        var thumbdisp = document.getElementById('thumbdisplay');
	var cart    = document.getElementById('cartdisplay');
	var clic    = document.getElementById('showhidelightbox');
	var pic     = document.getElementById('piclightbox');
	var pich    = document.getElementById('piclightboxhidden');
	var upd     = document.getElementById('updates');
       
       if(document.rubForm)
        {
                 
            var rubbForm        = document.rubForm;
            var thumbAreSmall   = rubbForm.rthumbqty.selectedIndex == 1;
            
        }
        else
            var thumbAreSmall  = false;
	
        if(!content || !cart || !clic )
		return;
        
        var extended = false;

	if(cart.style.display=='block' )
	{
		content.style.width             = '910px';
		cart.style.display		= 'none';
                if(thumbdisp)
                    thumbdisp.style.width       = "100%";
		if(upd)
                    upd.style.display		= 'block';
		if(pic)
                    pic.style.display		= 'none';
		if(pich)
                    pich.style.display		= 'block';
		window.parent.document.getElementById("prociframe").src = 'cartstatus.php?display=0';
                extended = true;
	}
	else
	{
		content.style.width             = '626px';
		cart.style.display		= 'block';
                 if(thumbdisp)
                    thumbdisp.style.width       = "588px";
		if(upd)
                    upd.style.display		= 'none';
		if(pic)
                    pic.style.display		= 'block';
		if(pich)
                    pich.style.display		= 'none';
              
		window.parent.document.getElementById("prociframe").src = 'cartstatus.php?display=1';
                extended = false;
	}
       
        /*
        if(document.searchForm)
        {
            if(thumbAreSmall)
                var qty = extended ? 35 : 25;    // small thumbs
            else
                var qty = extended ? 24 : 16;    // big thumbs
            
            document.searchForm.thumbqty.value = qty;
            
            updateThumbQtyInSession(qty );
            if(document.location.toString().indexOf("pictures.php")!=-1)
            {
                //setTimeout("document.location.reload()",1000);
                setTimeout("document.searchForm.submit();",250);
            }
            else
                changeDisplay();
        }*/
         
	
}
function cartDisplay(status)
{
	 
	var content = window.parent.document.getElementById('maindisplay');
        var thumbdisp = window.parent.document.getElementById('thumbdisplay');
	var cart    = document.getElementById('cartdisplay');
	var clic    = document.getElementById('showhidelightbox');
	var pic     = document.getElementById('piclightbox');
	var pich    = document.getElementById('piclightboxhidden');
	var upd     = document.getElementById('updates');
	if(!content || !cart || !clic)
		return;
           
	if(status)
	{
		content.style.width             = '910px';
		cart.style.display		= 'none';
                if(thumbdisp)
                    thumbdisp.style.width           = "100%";
		if(upd)
                    upd.style.display		= 'block';
		if(pic)
                    pic.style.display		= 'none';
		if(pich)
                    pich.style.display		= 'block';
	}
	else
	{
		content.style.width             = '626px';
		cart.style.display		= 'block';
                if(thumbdisp)
                    thumbdisp.style.width       = "588px";
		if(upd)
                    upd.style.display		= 'none';
		if(pic)
                    pic.style.display		= 'block';
		if(pich)
                    pich.style.display		= 'none';
	}
}
/*__________________________________________________________________________________*/
function putThisPageInCart()
{
	selectAllItem(document.thumbnaillist, true);
	putSelectedItemInLightbox();
}

/*----- SELECT/UNSELECT ALL THUMBNAIL ITEMS ----*/
function selectAllItem(theForm, check)
{
	if(!theForm)
		return;
	for(var i = 0; i < theForm.elements.length; i++)
	{
		var obj = theForm.elements[i];
		if(obj.type == "checkbox")
			obj.checked = check
	}
	var chk = check ? "images/checkboxon.gif" : "images/checkboxoff.gif";
	var obs = document.getElementsByTagName('img');
	if(obs)
	{
		for(i = 0; i < obs.length; i++)
		{
			if(obs[i].src.toString().indexOf('images/checkbox') != -1)
				obs[i].src = chk;
		}
	}
	   	
	if(document.getElementById('removeItemId'))
		document.getElementById('removeItemId').style.visibility = check ? "visible" : "hidden";
	if(document.getElementById('querylink'))
		document.getElementById('querylink').innerHTML = check ? "la selection" : "tout";
}
/*------------------------------------------------*/
function updateInput(obj)
{
	if(document.getElementById(obj.name))
		document.getElementById(obj.name).value = obj.checked ? 1 : 0;
}
/*
function showTopicList()
{
	var submenu		= document.getElementById('submenu');
	
	var tpcList	= document.getElementById('topiclist');
	var tpcTop 		= document.getElementById('topiclisttop');
	var tcpMiddle	= document.getElementById('topiclistmiddle');
	var tcpBot		= document.getElementById('topiclistbot');
	var cart	= document.getElementById("cartcontent");
	if(!tpcTop || !tcpMiddle || !tcpBot)
		return;
	
	if(tcpMiddle.offsetHeight == 0)
	{
		tpcTop.style.backgroundImage = 'url(images/topiclist_top.gif)';
		tpcList.style.height	= "180px";
		tcpMiddle.style.display	= "block";
		tcpBot.style.display	= "block";
		submenu.style.height	= "155px";
		var filter 	= document.getElementById("toppart");
		if(filter)
			filter.style.display = "none";
		if(cart)
			cart.style.top		 = "448px";
	}
	else
	{
		tpcTop.style.backgroundImage = 'url(images/topiclist_closed.gif)';
		tpcList.style.height	= "auto";
		tcpMiddle.style.display	= "none";
		tcpBot.style.display	= "none";
		submenu.style.height	= "auto";
		if(cart)
			cart.style.top		 = "290px";
	}
}*/
function handleInputTextFieldValue(field,text)
{
	
	if(field)
	{
		if( (field.value == 'votre recherche') ||  (field.value == 'your search') )
			field.value = text;
	}
	return;	
	var page	= document.location;
	if(page.toString().indexOf("pictures.php")!=-1 || page.toString().indexOf("account")!=-1 || page.toString().indexOf("index.php")!=-1)
	{
		var filter 	= document.getElementById("submenu");
		var cart	= document.getElementById("cartcontent");
		if(filter)
			filter.style.display = "block";	
		if(cart)
			cart.style.top		 = "375px";
	}
	else if(page.toString().indexOf("topic")!=-1)
	{
		var filter 	= document.getElementById("toppart");
		var cart	= document.getElementById("cartcontent");
		if(filter)
			filter.style.display = "block";	
		if(cart)
			cart.style.top		 = "448px";

		var tcpMiddle	= document.getElementById('topiclistmiddle');
		if(tcpMiddle.offsetHeight != 0)
		{
			var tpcList	= document.getElementById('topiclist');
			var tpcTop 		= document.getElementById('topiclisttop');
			var tcpBot		= document.getElementById('topiclistbot');
			tpcTop.style.backgroundImage = 'url(images/topiclist_closed.gif)';
			tpcList.style.height	= "auto";
			tcpMiddle.style.display	= "none";
			tcpBot.style.display	= "none";	
		}
		else
		{
			var submenu		= document.getElementById('submenu');
			submenu.style.height	= "155px";
		}
	}
	else if(page.toString().indexOf("index.php")!=-1)
	{
		var homeswf = document.getElementById("animation");
		var filter	= document.getElementById("searchfilters");
		if(homeswf)
			homeswf.style.width = "738px";
		if(filter)
			filter.style.display = "block";	
	}
	else if(page.toString().indexOf("lightbox.php")!=-1)
	{
		var submenu 	= document.getElementById("submenu");
		var filter	= document.getElementById("searchfilters");
		if(filter)
		{
			filter.style.display 	= "block";	
			submenu.style.height	= "156px";
		}
	}
}
function hideSearchOptions()
{
	
	if(document.location.toString().indexOf("pictures.php")!=-1)
	{
		var filter 	= document.getElementById("submenu");
		var cart	= document.getElementById("cartcontent");
		if(filter)
			filter.style.display = "none";	
		if(cart)
			cart.style.top		 = "225px";
	}
}

function changeThumbQty(qty)
{
        val = changeUrlNumericValue(document.location.toString(), "page", 1);
	val = changeUrlNumericValue(val, "thumbqty", qty);
	
	if(val)
	{
		//document.searchForm.submit()
		document.location = val
	}
}
function gotoPage(url, page, minpage, maxpage)
{
	if(page<minpage || page>maxpage)
		return false;
	newUrl = changeUrlNumericValue(url, "page", page);
	
	document.location =  newUrl ;
}

function checkPageField(page, minpage, maxpage, msg)
{
	if(isNumber(page)==false || page <= 0)
	{
		alert(msg);
		return false;
	}
	else
		gotoPage(document.location.toString(), page, minpage, maxpage);
}
function enableSendButton(obj, buttonId)
{
	button = document.getElementById(buttonId);
	if(!button)
		return false;
	button.disabled	= !trim(obj.value).length;
}
function changeUrlNumericValue(qstring, tag, value)
{
	if(qstring.indexOf("&"+tag) != -1)
	{
		reg  = /&page=[0-9]+/;
		var regexp = new RegExp("&"+tag+"=[0-9]+", "g");
		qstring = qstring.replace(regexp, "");
	}
	else if(qstring.indexOf(tag) != -1)
	{
		var regexp = new RegExp(tag+"=[0-9&]+", "g");
		qstring = qstring.replace(regexp, "");
	}
	if(qstring != "?")
		qstring += "&"+tag+"="+value;
	else if(qstring.length)
		qstring += "&"+tag+"="+value;
	else
		qstring += "&"+tag+"="+value;
	qstring = qstring.replace(".php&", ".php?");
	qstring = qstring.replace(".php?&", ".php?");
	return qstring;
}
function clickSearchInTopic(topic)
{
	obj = document.getElementById("askforsearch");
	if(obj.style.backgroundImage.toString().indexOf("searchrestopicon.gif") == -1)
	{
		obj.style.backgroundImage = 'url("images/searchrestopicon.gif")';
		document.getElementById("ctopic").value = topic;
	}
	else
	{
		obj.style.backgroundImage = 'url("images/searchrestopicoff.gif")';
		document.getElementById("ctopic").value = 0;
	}
}
var keepUQ = '';	// global keep user query;
function clickSearchInRes()
{
	obj = document.getElementById("askforsearch");
	qs = document.searchForm.query;
	if(obj.style.backgroundImage.toString().indexOf("searchreson.gif") == -1)
	{
		obj.style.backgroundImage = 'url("images/searchreson.gif")';
		document.getElementById("cinres").value = 1;
		if(qs)
		{
			keepUQ		= qs.value;
			qs.value 	= '';
		}
	}
	else
	{
		obj.style.backgroundImage = 'url("images/searchresoff.gif")';
		document.getElementById("cinres").value = 0;
		if(qs)
			qs.value 	= keepUQ;
	}

}

function clickCheckbox(obj, img, id, site)
{
	var s 		= obj.src + '';
	if(!site)
		site = '';
	theInput 	= document.getElementById(id); 			// this is the hidden input
	
	if(s.indexOf('on.gif')!=-1)
	{
		obj.src = "images"+site+"/"+img+"off.gif";
		if(theInput)
		{
			if(theInput.type == "checkbox")
				theInput.checked = false;
			else
				theInput.value 		= 0;
		}
	}
	else
	{
		obj.src = "images"+site+"/"+img+"on.gif";
		if(theInput)
		{
			if(theInput.type == "checkbox")
				theInput.checked = true;
			else
				theInput.value = 1;
		}
	}
	if(document.getElementById("selectall") && id!='selectall')
		document.getElementById("selectall").src =  "images"+site+"/"+img+"off.gif";
}

function clickChkBtn(obj, img1, img2)
{
	obj.src = "images/"+img1+"on.gif";
	setTimeout(function(){updateImage(obj,img2);}, 500);
}
function updateImage(obj, img)
{
	obj.src = "images/"+img+"off.gif";
}
function checkRtrPwdForm(theForm)
{
	if( (theForm.s_email.value.length < 2) || (theForm.s_email.value.indexOf("@") ==-1) || (theForm.s_email.value.indexOf(".") ==-1) )
	{
		alert("Merci de renseigner le champs avec une adresse mail valide");
		return false; 
	}
	else
		document.retrievepwdForm.submit();
}
function isNumber(s)
{
	return !isNaN(s)
}
function trim(s)
{
	return s.replace(/(?:^\s+|\s+$)/g, "");
} 
function isFadeCapable()
{
	browser = getBrowser();
	topic  = document.location.toString().indexOf("topic.php") != -1;
	safari = (browser.indexOf("Safari") != -1) && (browser.indexOf("Apple") != -1);
	if(safari /*&& topic*/)
	{
		return false;
		
	}
	else
	{
		return browser.toLowerCase().indexOf("msie") == -1;
	}
}
function getBrowser()
{
	return (navigator.userAgent);
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	return browser+" "+version;
}
function getIframeContentObject(iframe)
{
	if(iframe.contentDocument)
		return iframe.contentDocument;
	else if(iframe.Document)
		return iframe.Document;
	else
		return null;
}
