lurl=''+document.location;
rurl=''+document.referrer;
var lang='en';
lres=lurl.match(document.domain+'/(en|de|fr|sp|uk|he|ru)/');
if(lres) lang=lres[1];
else {
	rres=rurl.match(document.domain+'/(en|de|fr|sp|uk|he|ru)/');
	if(rres) lang=rres[1];
}

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';
		break;
	case 'de':
		wrong_mail='falsche mail - Sie muessen Ihre email einfuellen';
		wrong_name='falsche  mail - Sie muessen Ihren Vornamen einfuellen';
		break;
	case 'sp':
		wrong_mail='Usted tiene que llenar su correo electronico';
		wrong_name='Usted tiene que llenar su  primer nombre';
		break;
	default:
		wrong_mail='You must fill in your Email';
		wrong_name='You must fill in your first name';
		var sorry_the_checkout_special='Sorry the checkout special';
}
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 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');
});

var merchant = "70534";
var cookieVal = 365;

addLoadEvent(function() {
		addScript("https://impression.clickinc.com/impressions/servlet/CookeExpire?merchant=" + merchant);
});

addLoadEvent(function() {
		addScript('/scripts/clickscript.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;
}

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();
}
function addScript(scriptName){
   var head= document.getElementsByTagName('head')[0];
   var script= document.createElement('script');
   script.type= 'text/javascript';
   script.src= scriptName;
   head.appendChild(script);
}

