// © ArchiTacTic.com 1999-2005
// Merci de conserver la notice de copyright si vous reutilisez ces fonctions.
//
//
window.defaultStatus = "";

function quel_type(){
 nav = "Inconnu";
 lan = "inconnue";
 ver = "0";   
  if (navigator.appName.indexOf("Netscape") != -1) 
  { nav = "NN";
    lan = navigator.language;
	 ver = navigator.appVersion.substring(0, 3);
  }
  if (navigator.appName.indexOf("Microsoft") != -1) 
  { nav = "IE";
    lan = navigator.systemLanguage;
    var i = navigator.appVersion.indexOf("MSIE");
    ver = navigator.appVersion.substring(i+5, i+8);
  }
//return (nav ver lan);
}

function CheckForFrames (LeftFrame,RightFrame,LangPref){
//alert ("RightFrame : "+RightFrame);
	if (document.layers && (self.innerHeight == 0 && self.innerWidth == 0)) return;
//	if (self.name == "Intro") return;
//	if (readCookie('frames') == "off") return;
	if (readCookie('frames') == "off") makeCookie('frames', 'on', 30, '/');
	if (!LangPref) (LangPref = readCookie('language'));
	if (!LangPref) (quel_type(), LangPref = lan);
	LangPref = LangPref.slice(0,2);
//	alert (LangPref);
	if ((top == self) || (parent.frames[0].name != "bar1")) {
  		makeCookie('frames', 'on', 30, '/');
		(LeftFrame&&RightFrame)?'':(RightFrame=location.href);//if no arguments, loads url in left frame
		var newURL = 'http://' + self.location.host
 + '/'+LangPref 
 + '/index.html?' 
 + (LeftFrame?LeftFrame +'&':'')+(RightFrame?RightFrame:'');

        if (document.images) top.location.replace(newURL);
        else top.location.href = newURL;
    	}  
}
function CheckFramePref (){
if (top == self){
	MyFrames ('off');
//alert ("wrong framepref");

	}
}
	
//functions used in search
function CheckForMemo (){

	if (top == self) {
//this part was put into addURL
//		var MemoWindow=open("","MemoWin","resizable=yes,width=225,height=450, left=0, top=0");
//		var lan = readCookie('language') ?  readCookie('language') : 'fr';
//		var PHPfile = '/'+lan+'/memo.php3';

//		MemoWindow.location = PHPfile;
//		MemoWindow.focus();
//		return MemoWindow;

		}
	else if (parent.frames[1].name == "menu2") {
				if (parent.menu2.document.title == "ArchiTacTic : Memo"){
			return true;
			}
		else{
			var lan = readCookie('language') ?  readCookie('language') : 'fr';
			var PHPfile = '/'+lan+'/memo.php';
			LoadFile('menu2',PHPfile);
			}
	}
}

function acURL(curHref,curTitle,curRealm){ //gets the url clicked and prints it in the top bar(curHref,curTitle,curRealm)

var TopBar;
if (parent.bar1) {
 TopBar = parent.bar1 
	}
else {
	var lan = readCookie('language') ?  readCookie('language') : 'fr';
	TopBar = OpenTopBar(lan);
}


//alert (TopBar.name);
	TopBar.document.Lien.URL.value=curHref;
	TopBar.document.Lien.Title.value = curTitle;
	TopBar.document.Lien.Realm.value = curRealm;
	var MAliste = TopBar.document.Lien.Site;
	var MAvisite = TopBar.newOpt(curTitle,curHref,curRealm);
	MAliste.options[MAliste.length]=MAvisite;


}

//functions used in bar1
function New(){ 

	var URLbox = document.Lien.Site;
   if (URLbox.selectedIndex > 0)

   window.open(URLbox.options[URLbox.selectedIndex].text);
   else {	
		if (URLbox.value)
//		alert (URLbox.value)
		window.open(URLbox.value);
		else alert ("Choisissez un lien exterieur d'abord");
		}
}
function GoSite (Input) {

var n=Input.selectedIndex;
var Iurl=Input.options[n].text;
var Ivalue=Input.options[n].value;
var Ititle=Ivalue.substring(0,Ivalue.indexOf('@'));
var Irealm=Ivalue.substring(Ivalue.indexOf('@')+1);
//alert (Ititle + Irealm);
	if (Iurl)
	document.Lien.URL.value=Iurl;
	document.Lien.Title.value=Ititle;
	document.Lien.Realm.value=Irealm;
//alert ("/cgi-bin/link.pl?URL="+Iurl+"&Realm="+Irealm+"&Title="+Ititle);
	parent.browser3.location="/cgi-bin/link.pl?URL="+Iurl+"&Realm="+Irealm+"&Title="+Ititle;
	return false;
}

//functions used in search.html

function LoadFile (FrameName,FileName){	//loads file in frame
	parent.frames[FrameName].location = FileName;
}

function OpenTopBar (lan){	//loads top bar
		var TopWindow=open('/'+lan+'/top.htm',"bar1","resizable=yes,width=900,height=50,left=0,top=0");
		TopWindow.focus();
		return (TopWindow)

}
	


function ClearAll () {
	document.category.type_act.selectedIndex=0;
	document.category.type_con.selectedIndex=0;
	document.category.type_ent.selectedIndex=0;
	document.category.type_ins.selectedIndex=0;
	document.category.type_ser.selectedIndex=0;
}
function GoCat (i,x) {	//opens category in left window
	parent.menu2.location=i;
	var tri="type_"+x.value.substring(0,3);
	ClearAll () ;
	document.category.elements[tri].selectedIndex=1;
}

function SearchCat (num,y) { //selects the appropriate radio button, and sends the data to search

	var z=y.selectedIndex;
	ClearAll () ;
	y.selectedIndex=z;
	document.category.Realm[num].checked=1;
	if (y.options[z].value == "topten"){
		document.category.Realm[num].click();
	}
	else {
		document.category.RawCat2.value = y.options[z].text;
		document.category.Cat2.value = y.options[z].value;
		document.category.SearchType.value = "Cat2";
		document.category.submit();
	}
}
function SearchAllCat (x) {	//gets all sites
	var tri="type_"+x.value.substring(0,3);
	ClearAll () ;
	document.category.elements[tri].selectedIndex=1;
	document.category.RawCat2.value = "tous";
	document.category.Cat2.value = "";
	document.category.SearchType.value = "Cat2";
	document.category.submit();
	}
function SearchTop (x) {	//gets top sites
	var tri="type_"+x.value.substring(0,3);
	ClearAll () ;
	document.category.elements[tri].selectedIndex=1;
	document.category.SearchType.value = "TopTen";
	document.category.submit();
}
function SearchSubCat (v,w) {
	z=w.selectedIndex;
	w.selectedIndex=z;
//	document.subcategory.RawCat3.value = w.options[z].text;//version with only 1 subcategory
//	document.subcategory.RawCat2.value = w.options[z].text;
	(z<1) ? (document.subcategory.Cat2.value = v): (document.subcategory.Cat2.value = v+w.options[z].value);
	document.subcategory.submit();
}
//////////cookies section
function MyVersion (Version) {
var z=Version.selectedIndex;
var lan=Version.options[z].value;
makeCookie('language', lan, 30, '/');
top.location='/'+lan+'/';
//	return false;
}

function MyFrames (Pref) {
//alert (Pref);
makeCookie('frames', Pref, 30, '/');
}

function Vcount(){
var N = readCookie('VT');
isNaN(N) ? (N='O') : N++;
//alert (N);
makeCookie('VT', N, 30, '/');
}

function makeCookie(Name,Value,Expiry,Path,Domain,Secure) {
if (Expiry != null && !isNaN(Expiry)) {
	var datenow = new Date();
	datenow.setTime(datenow.getTime() + Math.round(86400000*Expiry));
	Expiry = datenow.toGMTString();
	}
 
Expiry = (Expiry) ? '; expires='+Expiry : '';
Path = (Path)?'; path='+Path:'';
Domain = (Domain) ? '; domain='+Domain : '';
Secure = (Secure) ? '; secure' : '';

document.cookie = Name + '=' + escape(Value) + Expiry + Path + Domain + Secure; //Make the cookie!
}

function readCookie(Name) {
var cookies = ' ' + document.cookie;//Copy your cookies
if (cookies.indexOf(' ' + Name + '=') == -1) return null;//Whoops, no cookie!
var start = cookies.indexOf(' ' + Name + '=') + (Name.length + 2);//Jump to start of cookie
var finish = cookies.substring(start,cookies.length);//Get a count from the cookies
finish = (finish.indexOf(';') == -1) ? cookies.length : start + finish.indexOf(';');//Find end of cookie

return unescape(cookies.substring(start,finish));
}
/////////VOTE SECTION
function CreateVoteWindow() {
//VoteWindow=open("","VoteWin","scrollbars=no,width=270,height=270");
VoteWindow=open("","VoteWin","resizable=yes,width=270,height=270");
}

function ChangeLang(lang){
(lang == "en") ? (oldlang = 'fr') :  (oldlang = 'en');
makeCookie('language', lang, 30, '/');
lang1 = readCookie('language');
//alert ("language = "+lang1);
var myMenu = parent.menu2.location;
var myBrowser = parent.browser3.location;
var RE = new RegExp("/"+oldlang+"/");

myMenu = myMenu.pathname.replace(RE,"/"+lang+"/");
//alert (document.Lien.Site.value);
//(document.Lien.Site.value =="") ? (myBrowser= myBrowser.pathname.replace(RE,"/"+lang+"/")) : (myBrowser=parent.location.pathname.replace(RE,"/"+lang+"/"));
(lang=="fr") ? (myBrowser= "/cgi-bin/search/search.pl?set:lang=french") : (myBrowser= "/cgi-bin/search/search.pl?set:lang=english");
	
parent.location.replace("/"+lang+"/index.html?"+myMenu+"&"+myBrowser);

//CheckForFrames(myMenu, myBrowser, lang);

}

