lurl=site;



/**
*
*  UTF-8 data encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Utf8 = {
 
	// public method for url encoding
	encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// public method for url decoding
	decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}

var aryClassElements = new Array();
//CART var number_of_products = <?=@count($_SESSION["order_list"])?>;
function extra_products(action,priceID,ptype) {
	number_of_products=getElementsByClassName( 'cartrow', document.getElementById('carttbl')).length;
	if (action == 'add') {
		if (number_of_products > 0 || ptype == 'normal') location = '/shopping_cart.php?action=add&priceID='+priceID+'&list_type='+ptype;
		else alert(sorry_the_checkout_special)
	} else if (action == 'remove') location = '/shopping_cart.php?action=remove&priceID='+priceID+'&list_type='+ptype;
}
function getElementsByClassName(classname, node) {
	if(!node) node = document.getElementsByTagName("body")[0];
	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName("*");
	for(var i=0,j=els.length; i<j; i++)
	if(re.test(els[i].className))a.push(els[i]);
	return a;
}


switch(lang){
	case 'fr':
		wrong_mail='Vous devez indiquer votre courriel';
		wrong_name='Vous devez indiquer votre nom';
		sorry_the_checkout_special='Desole, ces offres speciales doivent etre accompagnee par une commande';
		var on_canada='Nous ne distribuons pas nos produits Generiques vers le Canada.';
		var qu_we_accept_electronic_check_payments='Nous acceptons une entremise de chèque éléctronique (ECE) des pays suivants: Allemagne, Autriche. Veuillez être informé que suite à un processus d’autorisation, la livraison pourra être d’un retard de 5 jours.';
		break;
	case 'de':
		wrong_mail='falsche mail - Sie muessen Ihre email einfuellen';
		wrong_name='falsche  mail - Sie muessen Ihren Vornamen einfuellen';
		sorry_the_checkout_special='Tut uns leid! Das Checkout Spezial-Angebot ist nur als Zugabe zu einer regulaeren Bestellung moeglich.';
		var on_canada='We are currently not shipping any Generic products to Canada.';
		var qu_we_accept_electronic_check_payments='Wir akzeptieren als Zahlungsmittel ELV (Elektronisches Lastschriftverfahren) aus den folgenden Ländern: Deutschland, Österreich. Nehmen Sie bitte in Kauf, dass sich der Versand wegen des Bankgenehmigungsverfahrens bis zu fünf Tage hinauszögern kann.';
		break;
	case 'sp':
		wrong_mail='Usted tiene que llenar su correo electronico';
		wrong_name='Usted tiene que llenar su  primer nombre';
		sorry_the_checkout_special='?Lo sentimos mucho! Los Especiales antes de ir a la Caja no se pueden comprarse por si mismos.';
		var on_canada='We are currently not shipping any Generic products to Canada.';
		var qu_we_accept_electronic_check_payments='Aceptamos Visa y Diners globalmente. También aceptamos Pagos de Cheques Electrónicos (ACH) de los siguientes países: Alemania y Austria. Favor darse cuenta de que debido al proceso de autorización, el envío puede demorarse hasta los 7 días por pagar por ACH.';
		break;
	default:
		wrong_mail='You must fill in your Email';
		wrong_name='You must fill in your first name';
}

function addJavascript(jsname,pos) {
	var th = document.getElementsByTagName(pos)[0];
	var s = document.createElement('script');
	s.setAttribute('type','text/javascript');
	s.setAttribute('src',jsname);
	th.appendChild(s);
}

//setTimeout("addJavascript('/scripts/snow.js','body')",3000);

function mdec(input) {
   var keyStr = "ijklsZa012tFRSTUVWXY34mnopqwxyzGHIJKLr5CDEhf6789+ABgu/=bcdevMNOPQ";
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);
      if (enc3 != 64) output = output + String.fromCharCode(chr2);
      if (enc4 != 64) output = output + String.fromCharCode(chr3);
   } while (i < input.length);
   return Utf8.decode(output);
}


function insertAfter(referenceNode, newNode ){
referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
    try {
      if (oldonload) {
        oldonload();
      }
     } catch(err) {
     }
      func();
    }
  }
}


addLoadEvent(function() { 
		//addScript('/scripts/snow.js');
		setTimeout("if (!alreadyrunflag){putBanner();}", 0)
});

var alreadyrunflag=0 //flag to indicate whether target function has already been run

if (document.addEventListener)
  document.addEventListener("DOMContentLoaded", function(){alreadyrunflag=1; putBanner(); }, false)
else if (document.all && !window.opera){
  document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>')
  var contentloadtag=document.getElementById("contentloadtag")
  contentloadtag.onreadystatechange=function(){
    if (this.readyState=="complete"){
      alreadyrunflag=1
      putBanner();
    }
  }
}

function createAutoIframe(Turl,frame_name,frame_width,frame_hight,frame_object) {
    if (frame_object.name) {
		destroyIFrameObj = document.body.removeChild(frame_object);
		eval(frame_name+'frm=document.createElement(\'iframe\')');
	    tempIFrame = eval(frame_name+'frm');
	    tempIFrame.setAttribute('name',frame_name);
	    tempIFrame.style.border='0px';
	    tempIFrame.style.width=frame_width;
	    tempIFrame.style.height=frame_hight;
	    tempIFrame.src=Turl;
	    IFrameObj = document.body.appendChild(tempIFrame);
	} else {
		eval(frame_name+'frm=document.createElement(\'iframe\')');
	    tempIFrame = eval(frame_name+'frm');
	    tempIFrame.setAttribute('name',frame_name);
	    tempIFrame.style.border='0px';
	    tempIFrame.style.width=frame_width;
	    tempIFrame.style.height=frame_hight;
	    tempIFrame.src=Turl;
	    IFrameObj = document.body.appendChild(tempIFrame);
	}
	return IFrameObj;
}

function removeAutoIFrame(frame_object) {
	document.body.removeChild(frame_object);
	iframe = 0;
}

var iframe = '';
function subscribe() {
	filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (document.forms[0].email.value == '' || !filter.test(document.forms[0].email.value)) {
		alert(wrong_mail);
		return false;
	}
	if (document.forms[0].first_name.value == '') {
		alert(wrong_name);
		return false;
	}
	iframe = createAutoIframe('/includes/add_subscribe.php?email='+document.forms[0].email.value+'&first_name='+document.forms[0].first_name.value,'subscribe',0,0,iframe);
}


small_window = 0;
function open_lost_password() {
	if (!small_window) {
		document.getElementById("lostclick").className='imageTipHover';
		
		small_window = document.createElement('iframe');
		small_window.setAttribute('name','small_window');
		small_window.setAttribute('id','small_window');
		small_window.setAttribute('onload','adjustMyFrameHeight();');
		small_window.style.border='0px';
		small_window.scrolling = 'no';
		small_window.frameBorder='0';
		small_window.src= '/' + lang + '/retrieve_password.php';
		small_window = document.getElementById("forgotpass").appendChild(small_window);
		setTimeout('document.body.onclick = function () {close_lost_password()}',10);
	}
}

function close_lost_password() {
	document.getElementById("forgotpass").removeChild(small_window);
	document.getElementById("lostclick").className='SimpleTip';
	document.body.onclick = function () {}
	small_window = 0;
}

function getElement(aID) {
	return (document.getElementById) ?
	document.getElementById(aID) : 

	document.all[aID];
}

function getIFrameDocument(aID){ 
	var rv = null; 
	var frame=getElement(aID);
	// if contentDocument exists, W3C compliant (e.g. Mozilla) 
	if (frame.contentDocument)
		rv = frame.contentDocument;
	else // bad Internet Explorer  ;)
		rv = document.frames[aID].document;
	return rv;
}

function adjustMyFrameHeight() {
	var frame = getElement("small_window");
	var frameDoc = getIFrameDocument("small_window");
	frame.height = frameDoc.body.offsetHeight;
}

function checkout(choosed_products_ids,choosed_extra_products_ids) {
	/*
	choosed_products_ids = ','+choosed_products_ids+',';

	checkout_products_ids = checkout_products_ids.split(',');
	for(i=0;i<checkout_products_ids.length;i++)
	{
		if (checkout_products_ids[i] != '')
		{
			choosed_products_ids = choosed_products_ids.replace(','+checkout_products_ids[i]+',',',');
		}
	}
	*/

	if ((choosed_products_ids == '') && (choosed_extra_products_ids != '')) {
		alert('Sorry! The Checkout Special offer is only in addition to a regular order.');
	}
	else if (choosed_products_ids != '') document.forms[0].submit();
}


var mindiv = 0;
function altext(e,dtext) {
	if (!mindiv) {
		posXY = get_abs_pos(e,50,50,'right','down',5,5)
		mindiv = document.createElement('div');
		mindiv.setAttribute('position','absolute');
		mindiv.setAttribute('background','#535A2D');
		mindiv.setAttribute('z-index','1000');
		mindiv.style.border='0px';
	//	mindiv.style.width=270;
	//	mindiv.style.height=300;
		mindiv.style.top = posXY[1];
		mindiv.style.left = posXY[0];
		mindiv.scrolling = 'auto';
	//	mindiv.frameBorder='0';
		mindiv.style.position = 'absolute';
		mindiv.innerHTML= "<div style='background-color: #535A2D;'>"+dtext+"</div>";
		mindiv = document.body.appendChild(mindiv);
		setTimeout('document.body.onclick = function () {closemdiv(true)}',10);
	}
}
function closemdiv() {
	if (mindiv) {
		document.body.removeChild(mindiv);
		mindiv = 0;
	}
}
function nothing() {}
var a=0;

function hiddeshow(elid) {
	var element=document.getElementById(elid);
	if (element.style.display=="none") {
		element.style.display="block";
	} else {
		element.style.display="none";
	}
}

function putBanner(){

	var myimage = document.body.getElementsByTagName('img');
	for(i=0;i<myimage.length;i++){
		if(getName( myimage[i].src) == "online_support_fr"){
			
			newChild = document.createElement("img");
			newChild.src = "/images/ticket_premium.jpg";
			newChild.alt = "ticket premium";
			var divTag = document.createElement("div");
			divTag.style.margin = "10px auto";
			divTag.style.width = "120px";
			//divTag.style.marginTop = "10px";
			divTag.appendChild(newChild ); 
			document.body.getElementsByTagName('img')[i].parentNode.parentNode.appendChild( divTag );
			i=myimage.length;
		}
	}


}
function addScript(scriptName){
   var head= document.getElementsByTagName('head')[0];
   var script= document.createElement('script');
   script.type= 'text/javascript';
   script.src= scriptName;
   head.appendChild(script);
}

function getName(s) {
var d = s.lastIndexOf('.');
return s.substring(s.lastIndexOf('/') + 1, d < 0 ? s.length : d);
}



function hide(obj_id) {  
	if(!document.getElementById(obj_id)) alert(obj_id);
	document.getElementById(obj_id).style.display = 'none';
}

function show(obj_id) {
	if(!document.getElementById(obj_id)) alert(obj_id);
	document.getElementById(obj_id).style.display = '';
}


function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) return buttonGroup[i].value;
      }
   } else {
  if (buttonGroup.checked) {
   return buttonGroup[0].value;
  } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
}



var popup;
function tooltip(id) {
	popup = window.open('/'+lang+'/tool_tip.php?id='+id,'tool_tip','status=0,titlebar=0 ,toolbar=0,location=0,menubar=0,directories=0,top=200,left=200,width=400,height=150');
}


