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;
	}
 
}


function extra_products(action,priceID,ptype,coupon) {
	if ( coupon === undefined ) copadd="";
	else copadd="&couponID="+coupon;
	number_of_products=getElementsByClassName( 'cartrow', document.getElementById('carttbl')).length;
	if (action == 'add') {
		if (!(number_of_products > 0) && ptype != 'normal') alert(sorry_the_checkout_special);
		else location = '/shopping_cart.php?action=add&priceID='+priceID+'&list_type='+ptype+copadd;
	} else if (action == 'remove') location = '/shopping_cart.php?action=remove&priceID='+priceID+'&list_type='+ptype+copadd;
}

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');
});

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;
}
	 
/********************
this function recieve two vars one is the string of ids of all the checkout available products and the second is a string of ids of all the order list of the user we remove all the ids of the checkout products from the order list string and if at the and the string is empty its mean that the user have only checkout products in the order list. and the opposite.....
********************/
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();
}
function func1() { 
	if(document.getElementById('ptitlede').type == 'undefinde') return;
	var mySpan = document.getElementById('ptitlede').innerHTML;
	if(mySpan != 'Viagra' && mySpan != 'Cialis'  && mySpan != 'Levitra' && mySpan != 'Sildenafil Citrate' && mySpan != 'Vardenafil'){
		//alert('Im Moment koennen wir nur Bestellungen fuer folgende Produkte entgegennehmen:  Sildenafil Citrate, Vardenafil und Markenprodukte wie Viagra, Cialis und Levitra. Fuer weitere Informationen kontaktieren Sie bitte unseren Kundenservice unter: service@generik4u.com  Vielen Dank fuer Ihr Verstaendnis Das G4U Team')
	}
} 
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;
}

function adjustMyFrameHeight() {
	var frame = getElement("small_window");
	var frameDoc = getIFrameDocument("small_window");
	frame.height = frameDoc.body.offsetHeight;
}

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');
}
