Tfont = new Array();
Tfont_type = new Array();


function font(id,id_categorie,nom)
{
	this.id = id;
	this.id_categorie = id_categorie;
	this.nom = nom;
}

function font_type(id,id_font,nom)
{
	this.id = id;
	this.id_font = id_font;
	this.nom = nom;
}

function get_font(sens)
{
	id_categorie = document.laforme.id_categorie.options[document.laforme.id_categorie.selectedIndex].value
	document.laforme.id_font.length = 0
	add_option(0,0,"Typefaces","id_font");
	if (navigator.userAgent.indexOf("Mac")!=-1) add_option(1,0,"------------","id_font");
	else add_option(1,0,"--------------------","id_font");
	for (j=0; j< Tfont.length;j++) {
		if (id_categorie == 0) {
			add_option((j+2),Tfont[j].id + "_" + Tfont[j].id_categorie,Tfont[j].nom,"id_font");
		}
		else {
			if (Tfont[j].id_categorie == id_categorie) add_option((j+2),Tfont[j].id + "_" + Tfont[j].id_categorie,Tfont[j].nom,"id_font");
		}
	}

	//if (id_categorie == 0) document.laforme.id_categorie.selectedIndex = 0;
	document.laforme.id_font.selectedIndex = 0;
	get_font_type(sens);
}

function get_font_type(sens)
{
	str_id_font = document.laforme.id_font.options[document.laforme.id_font.selectedIndex].value
	pos = str_id_font.indexOf("_")
	id_font = str_id_font.substring(0,pos);
	id_categorie = str_id_font.substring(pos+1,str_id_font.length);
	if ((sens == 1) && (id_categorie != 0)) get_categorie(id_categorie)
	document.laforme.id_font_type.length = 0
	add_option(0,0,"Styles","id_font_type");

	if (navigator.userAgent.indexOf("Mac")!=-1) add_option(1,0,"------------","id_font_type");
	else add_option(1,0,"--------------------","id_font_type");
	
	if (id_font != 0) {
		for (j=0; j< Tfont_type.length;j++) {
			if (Tfont_type[j].id_font == id_font) add_option((j+2),Tfont_type[j].id,Tfont_type[j].nom,"id_font_type");
		}
	}
	else {
		//add_option(2,0,"Select a typeface","id_font_type");
		document.laforme.id_font.selectedIndex = 0;
	}
	document.laforme.id_font_type.selectedIndex = 0;
}

function get_categorie(id)
{
	if (id != 0) {
		for(i=0;i<document.laforme.id_categorie.options.length;i++) {
			if (document.laforme.id_categorie.options[i].value==id) document.laforme.id_categorie.selectedIndex = i;
		}
	}
	else document.laforme.id_categorie.selectedIndex = 0;
}

function add_option(val,id,libelle,champ_form)
{
	ch_option = "option" + val;
	ch_option = new Option(libelle,id);

	document.laforme.elements[champ_form].options[document.laforme.elements[champ_form].length] = ch_option;
	
}

function font_infos(id,letype)
{
	if (letype == 0) adr = "info_font.php?id=" + id;
	else adr = "info_designer.php?id=" + id;
	newrub = window.open(adr,"infos",'scrollbars=0,screenX=0,screenY=0,status=1,location=0, menubar=0,toolbar=0,resizable=0,width=283,height=355');

}

function go_font(id_categorie,id_font) {
	top.opener.location = "index.php?id_categorie=" + id_categorie + "&id_font=" + id_font;
}

function add_card_it(id,produit,prix,val,Fid,id_type)
{
	
	if (NS6) {
		back_url = "trans_aff_txt.php?id_type=" + id_type + "&str=" + document.laforme.str.value;
		back_url = escape(back_url)	
		document.getElementById("Fbuffer").src = "../ordering/change_caddy.php?navig=1&lemode=1&id=" + val + id + "&produit=" + produit + "&prix=" + prix + "&Fid=" + Fid + "&letype=" + val + "&back_url=" + back_url;
		//document.getElementById("Fbuffer1").src = "../ordering/change_caddy.php?navig=1&lemode=1&id=" + val + id + "&produit=" + produit + "&prix=" + prix + "&Fid=" + Fid + "&letype=" + val;
	}
	else parent.Fbuffer1.location = "../ordering/change_caddy.php?navig=1&lemode=1&id=" + val + id + "&produit=" + produit + "&prix=" + prix + "&Fid=" + Fid + "&letype=" + val;
}

function add_card(id,produit,prix,val,Fid)
{
	
	if (NS6) document.getElementById("Fbuffer1").src = "../ordering/change_caddy.php?navig=1&lemode=1&id=" + val + id + "&produit=" + produit + "&prix=" + prix + "&Fid=" + Fid + "&letype=" + val + "&back_url=";
	else parent.Fbuffer1.location = "../ordering/change_caddy.php?navig=1&lemode=1&id=" + val + id + "&produit=" + produit + "&prix=" + prix + "&Fid=" + Fid + "&letype=" + val;
}

var liste_code = new Array();
liste_code = new Array(92,94,96,123,124,125,126,128,131,132,133,134,135,136,137,138,139,140,142,145,146,147,148,149,150,151,152,153,154,155,156,158,159,161,162,164,165,166,167,168,169,170,172,174,175,176,177,178,179,180,181,182,183,184,185,186,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,8364);

function replace_all(string,text,by) {
	re = text;
	if (re == "ü") by = "u";
	if (re == "û") by = "u";
	if (re == "ù") by = "u";
	if (re == "ï") by = "i";
	if (re == "î") by = "i";
	if (re == "à") by = "a";
	if (re == "ä") by = "a";
	if (re == "â") by = "a";
	if (re == "ö") by = "o";
	if (re == "ô") by = "o";
	if (re == "é") by = "e";
	if (re == "è") by = "e";
	if (re == "ê") by = "e";
	
	while (string.indexOf(text) != -1) {
	   string=string.replace(re, by);
	}

	

    return string;
}



function load_str(id_type)
{
	str = document.laforme.str.value;
	car = String.fromCharCode(92);
	str = str.replace(car,'');
	str = str.replace(car,'');
	str = str.replace(car,'');
	str = str.replace(car,'');
	str = str.replace(car,'');
	str = str.replace(/\+/g, ' ');
	str = replace_all(str,String.fromCharCode(252),' ')
	/*var chaine="ü";
	for (var i=0; i<chaine.length; i++) {
	alert("Code ASCII de "+chaine.charAt(i)+"="+chaine.charCodeAt(i));
	}*/

	for (j=0;j<124;j++) {
		str = replace_all(str,String.fromCharCode(liste_code[j]),' ')
	}
	str = replace_all(str,'€',' ');
	document.laforme.str.value = str;
	str = escape(str)
	str = escape(str)
	if (NS6) {
		document.getElementById("Fbuffer").src = "trans_aff_txt.php?id_type=" + id_type + "&str=" + str;
	}
	else {
		parent.Fbuffer.location = "trans_aff_txt.php?id_type=" + id_type + "&str=" + str;
	}
	
	/*document.laforme.target = "Fbuffer";
	document.laforme.action = "trans_aff_txt.php?id_type=" + id_type;
	document.laforme.submit();*/
}


function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function