var hW = null;
var hWc = "f";
function kk_viewMerchant(u, i, p){
op = 'scrollbars=yes,toolbar=yes,location=yes,directories=yes,menubar=yes,resizable=yes,status=yes,width=800,height=500';
u="/ctl/go/modulesGo?merchantId="+i+"&url="+escape(u)+p;
merchant=open(u,'',op);
}

function kk_viewMerchant2(){
op = 'scrollbars=yes,toolbar=yes,location=yes,directories=yes,menubar=yes,resizable=yes,status=yes,width=800,height=500';
var url = kk_recomposeUrl(kk_viewMerchant2.arguments);
merchant=open(url,'',op);
}

function kk_viewMerchant3(encoded){
op = 'scrollbars=yes,toolbar=yes,location=yes,directories=yes,menubar=yes,resizable=yes,status=yes,width=800,height=500';
var url = kk_decode64(encoded);
merchant=open(url,'',op);
}

function kk_afficheCommande(u){
w = (document.all ? screen.width : screen.width) * 0.9;
h = (document.all ? screen.height : screen.height-150) * 0.9;
op = 'scrollbars=yes,toolbar=yes,location=yes,directories=yes,menubar=yes,resizable=yes,status=yes,width=' + w + ',height=' + h + ',screenX=0,screenY=0,top=0,left=0';
com=open(u,'',op);
}

// Displays the page given by a splitted URL
function kk_afficheCommande2()
{
    w = (document.all ? screen.width : screen.width) * 0.9;
    h = (document.all ? screen.height : screen.height-150) * 0.9;
    op = 'scrollbars=yes,toolbar=yes,location=yes,directories=yes,menubar=yes,resizable=yes,status=yes,width=' + w + ',height=' + h + ',screenX=0,screenY=0,top=0,left=0';
    var url = kk_recomposeUrl(kk_afficheCommande2.arguments);
    com=open(url,'',op);
}

// Displays the page given by an URL encoded using Base64
function kk_afficheCommande3(encoded)
{
    w = (document.all ? screen.width : screen.width) * 0.9;
    h = (document.all ? screen.height : screen.height-150) * 0.9;
    op = 'scrollbars=yes,toolbar=yes,location=yes,directories=yes,menubar=yes,resizable=yes,status=yes,width=' + w + ',height=' + h + ',screenX=0,screenY=0,top=0,left=0';
    var url = kk_decode64(encoded);
    com=open(url,'',op);
}

function kk_popup(u){
w = (document.all ? screen.width : screen.width) * 0.9;
h = (document.all ? screen.height : screen.height) * 0.9;
op = 'scrollbars=yes,toolbar=no,location=no,directories=no,menubar=no,resizable=yes,status=yes,width=' + w + ',height=' + h + ',screenX=0,screenY=0,top=0,left=0';
com=open(u,'',op);
}

function kk_help(u,t,w,h,f){
hurl = "/ctl/do/popup";
if (f == "yes") hurl+="?frameset=yes&url=";
else hurl+="?url=";
if (hWc = "t" || hW == null){
hW = window.open("","title","width=" + w + ",height=" + h+",top=0,left=0,screenX=0,screenY=0,resizable=yes,scrollbars=no,toolbar=no,location=no,directories=no,menubar=no");
hWc = "f";}
if (hWc == "f"){
hW.location.href = hurl + u;
hW.resizeTo(w, h);}
hW.focus();}


function kk_closeHelp(){
if (hWc == "f"){
hWc = "t";
hW = null; }}

function kk_respop(u,n,w,h){
pop = window.open(u,n,"width=" + h + ",height=" + w + ",location=no,menubar=no,resizable=yes");
pop.focus; }

function kk_respop2(){
var n = arguments[0];
var w = arguments[1];
var h = arguments[2];

var tab=new Array();
var j=0;
for (i = 3; i < arguments.length; i++) {
	tab[j]=arguments[i];
	j++;
}

var url = kk_recomposeUrl(tab);
pop = window.open(url,n,"width=" + h + ",height=" + w + ",location=no,menubar=no,resizable=yes");
pop.focus; 
}

function kk_respop(u,n,w,h){
pop = window.open(u,n,"width=" + h + ",height=" + w + ",location=no,menubar=no,resizable=yes");
pop.focus; 
}

function kk_checkQuery(f)
{
        var query = f.elements['siteSearchQuery'].value;
        // Refuse if there are only ponctuation signs
        
          
        if (query.match(/^[ +-]*$/) && !query.match(/^[ ]*$/) || (query.match(/^[ ]*$/) && f.elements['catId']==null)) {
                alert(PsEnterKeyword);
                return false;
        } else {
 	if (query.match(/^[ ]*$/)) {
        f.elements['siteSearchQuery'].value="";
        }  
                return true;
        }
}

function kk_go(u) {document.location.href=u;}

function kk_go2() {
	var url = kk_recomposeUrl(kk_go2.arguments);
	document.location.href=url;
}

function kk_go3(encoded) {
	var url = kk_decode64(encoded);
	document.location.href=url;
}

function kk_goFromFrame(u) {parent.location.href=u;}

function kk_go2FromFrame() {
	var url = kk_recomposeUrl(kk_go2FromFrame.arguments);
	kk_goFromFrame(url);
}

function kk_go3FromFrame(encoded) {
	var url = kk_decode64(encoded);
	kk_goFromFrame(url);
}

function kk_printpop(u,n,w,h){
	pop = window.open(u,"","width=" + h + ",height=" + w + ",top=0,left=0,screenX=0,screenY=0,resizable=yes,scrollbars=yes,toolbar=yes,location=no,directories=no,menubar=no");
	pop.focus;
}

function kk_mailPage()
{
        var url = "" + document.URL;
        var browser = whichBrowser();
        if (browser == "mozilla") {
        	url = kk_replace(url, "&", "%2526"); // encode both '&' to '%26' and '%' to '%25'
        } else { // default (ie)
        	url = kk_replace(url, "&", "%26"); // encode '&' to '%26'
        }
        var mailStr = "mailto:?subject=" + document.title + "&body=" + url;
        location.href = mailStr;
}

function kk_replace(expr,a,b)
{
	var i = 0;
	while (i != -1) {
		i = expr.indexOf(a, i);
		if (i >= 0) {
			expr = expr.substring(0,i) + b + expr.substring(i + a.length);
			i += b.length;
		}
	}
	return expr;
}

// return "ie", "opera", "mozilla" or "firefox".
// add other ones if necessary
function kk_whichBrowser() {
    // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();
    var appVer = navigator.appVersion.toLowerCase();

    // *** BROWSER VERSION ***

    var is_minor = parseFloat(appVer);
    var is_major = parseInt(is_minor);

    var is_opera = (agt.indexOf("opera") != -1);
    var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
    var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
    var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
    var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
    var is_opera6 = (agt.indexOf("opera 6") != -1 || agt.indexOf("opera/6") != -1);
    var is_opera7 = (agt.indexOf("opera 7") != -1 || agt.indexOf("opera/7") != -1);
    var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);
    var is_opera6up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5);
    var is_opera7up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5 && !is_opera6);

    // Note: On IE, start of appVersion return 3 or 4
    // which supposedly is the version of Netscape it is compatible with.
    // So we look for the real version further on in the string
    // And on Mac IE5+, we look for is_minor in the ua; since 
    // it appears to be more accurate than appVersion - 06/17/2004

    var is_mac = (agt.indexOf("mac")!=-1);
    var iePos  = appVer.indexOf('msie');
    if (iePos !=-1) {
       if(is_mac) {
           var iePos = agt.indexOf('msie');
           is_minor = parseFloat(agt.substring(iePos+5,agt.indexOf(';',iePos)));
       }
       else is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
       is_major = parseInt(is_minor);
    }

    // ditto Konqueror
                                      
    var is_konq = false;
    var kqPos   = agt.indexOf('konqueror');
    if (kqPos !=-1) {                 
       is_konq  = true;
       is_minor = parseFloat(agt.substring(kqPos+10,agt.indexOf(';',kqPos)));
       is_major = parseInt(is_minor);
    }                                 

    var is_getElementById   = (document.getElementById) ? "true" : "false";
    var is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false";
    var is_documentElement = (document.documentElement) ? "true" : "false";

    var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
    var is_khtml  = (is_safari || is_konq);

    var is_gecko = ((!is_khtml)&&(navigator.product)&&(navigator.product.toLowerCase()=="gecko"))?true:false;
    var is_gver  = 0;
    if (is_gecko) is_gver=navigator.productSub;

    var is_moz   = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
                    (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
                    (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
                    (is_gecko) && 
                    ((navigator.vendor=="")||(navigator.vendor=="Mozilla")||(navigator.vendor=="Debian")));
    var is_fb = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
                 (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
                 (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
                 (is_gecko) && (navigator.vendor=="Firebird"));
    var is_fx = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
                 (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
                 (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
                 (is_gecko) && (navigator.vendor=="Firefox"));
    if ((is_moz)||(is_fb)||(is_fx)) {
       var is_moz_ver = (navigator.vendorSub)?navigator.vendorSub:0;
       if(!(is_moz_ver)) {
           is_moz_ver = agt.indexOf('rv:');
           is_moz_ver = agt.substring(is_moz_ver+3);
           is_paren   = is_moz_ver.indexOf(')');
           is_moz_ver = is_moz_ver.substring(0,is_paren);
       }
       is_minor = is_moz_ver;
       is_major = parseInt(is_moz_ver);
    }
   var is_fb_ver = is_moz_ver;
   var is_fx_ver = is_moz_ver;

    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)
                && (!is_khtml) && (!(is_moz)) && (!is_fb) && (!is_fx));

    // Netscape6 is mozilla/5 + Netscape6/6.0!!!
    // Mozilla/5.0 (Windows; U; Win98; en-US; m18) Gecko/20001108 Netscape6/6.0
    // Changed this to use navigator.vendor/vendorSub - dmr 060502   
    // var nav6Pos = agt.indexOf('netscape6');
    // if (nav6Pos !=-1) {
    if ((navigator.vendor)&&
        ((navigator.vendor=="Netscape6")||(navigator.vendor=="Netscape"))&&
        (is_nav)) {
       is_major = parseInt(navigator.vendorSub);
       // here we need is_minor as a valid float for testing. We'll
       // revert to the actual content before printing the result. 
       is_minor = parseFloat(navigator.vendorSub);
    }

    var is_nav2 = (is_nav && (is_major == 2));
    var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && is_minor >= 4);  // changed to is_minor for
                                                // consistency - dmr, 011001
    var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );

    var is_nav6   = (is_nav && is_major==6);
    var is_nav6up = (is_nav && is_minor >= 6);

    var is_nav5   = (is_nav && is_major == 5 && !is_nav6); // checked for ns6
    var is_nav5up = (is_nav && is_minor >= 5);

    var is_nav7   = (is_nav && is_major == 7);
    var is_nav7up = (is_nav && is_minor >= 7);

    var is_ie   = ((iePos!=-1) && (!is_opera) && (!is_khtml));
    var is_ie3  = (is_ie && (is_major < 4));

    var is_ie4   = (is_ie && is_major == 4);
    var is_ie4up = (is_ie && is_minor >= 4);
    var is_ie5   = (is_ie && is_major == 5);
    var is_ie5up = (is_ie && is_minor >= 5);
    
    var is_ie5_5  = (is_ie && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5_5up =(is_ie && is_minor >= 5.5);
	
    var is_ie6   = (is_ie && is_major == 6);
    var is_ie6up = (is_ie && is_minor >= 6);

    // KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
    // or if this is the first browser window opened.  Thus the
    // variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.

    var is_aol   = (agt.indexOf("aol") != -1);
    var is_aol3  = (is_aol && is_ie3);
    var is_aol4  = (is_aol && is_ie4);
    var is_aol5  = (agt.indexOf("aol 5") != -1);
    var is_aol6  = (agt.indexOf("aol 6") != -1);
    var is_aol7  = ((agt.indexOf("aol 7")!=-1) || (agt.indexOf("aol7")!=-1));
    var is_aol8  = ((agt.indexOf("aol 8")!=-1) || (agt.indexOf("aol8")!=-1));

    var is_webtv = (agt.indexOf("webtv") != -1);
       
    var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)); 
    var is_AOLTV = is_TVNavigator;

    var is_hotjava = (agt.indexOf("hotjava") != -1);
    var is_hotjava3 = (is_hotjava && (is_major == 3));
    var is_hotjava3up = (is_hotjava && (is_major >= 3));

    // end new

    //var ie = is_ie || is_ie3 || is_ie4 || is_ie4up || is_ie5 || is_ie5_5 || is_ie5up || is_ie5_5up || is_ie6 || is_ie6up; // default
    var opera = is_opera || is_opera2 || is_opera3 || is_opera4 || is_opera5 || is_opera6 || is_opera7 || is_opera5up || is_opera6up || is_opera7up;
    var mozilla = is_moz;
    var firefox = is_fx;

    var browser = "ie"; // default
    if (opera) {
    	browser = "opera";
    } else if (mozilla) {
    	browser = "mozilla";
    } else if (firefox) {
    	browser = "firefox";
    }
    return browser;
}

function kk_toggle (div_id)
{
    div = document.getElementById(div_id);
    if( div.style.display == 'none' )
      kk_expand(div_id);
    else
      kk_collapse(div_id);
}

function kk_collapse ( div_id)
{
    div = document.getElementById(div_id);
    div.style.display = 'none';
}

function kk_expand ( div_id)
{
    div = document.getElementById(div_id);
    div.style.display = '';
}

function kk_loadFinished (image)
{
	w = image.width;
	h = image.height;
	nW = w + 100;
	nH = h + 200;
	nH = nH + 65;
    if(nW < 250) nW = 250;
	window.resizeTo(nW,nH);
}

