var sDir = 5;
var sDir = 5;
var tId;
var runDelay = 20;
var scrollVar;
var stillScroll;

function showMe(text, ev) {
	var theDiv = document.getElementById('showMeDiv');
	theDiv.scrollTop = 0;
	theDiv.style.left = (ev.clientX + 15 + document.documentElement.scrollLeft)+ "px";
	theDiv.style.top = (ev.clientY + document.documentElement.scrollTop)+ "px";
	theDiv.innerHTML = text;
	theDiv.style.visibility = 'visible';
	theDiv.style.width = "250px";
	var wid, hei, dWid, dHei;
	if (window.innerWidth) {
		wid = window.innerWidth;
		hei = window.innerHeight;
	}
	else {
		wid = document.body.clientWidth;
		hei = document.body.clientHeight;
	}
	wid -= 15;
	dWid = theDiv.clientWidth;
	dHei = theDiv.clientHeight;
	if (ev.clientX + dWid > wid)
		theDiv.style.left = (parseInt(theDiv.style.left+document.documentElement.scrollTop) - dWid - 30) + "px";
	if (ev.clientY + dHei > hei)
		theDiv.style.top = (parseInt(theDiv.style.top+document.documentElement.scrollTop) - dHei) + "px";
}

function hideMe() {
	var theDiv = document.getElementById('showMeDiv');
	theDiv.style.visibility = 'hidden';
	stillScroll = false;
	if (tId)
		clearTimeout(tId);
}

function moveMe(ev) {
	var theDiv = document.getElementById('showMeDiv');
	theDiv.style.left = (ev.clientX + 15 + document.documentElement.scrollLeft)+ "px";
	theDiv.style.top = (ev.clientY + document.documentElement.scrollTop)+ "px";
	var wid, hei, dWid, dHei;
	if (window.innerWidth) {
		wid = window.innerWidth;
		hei = window.innerHeight;
	}
	else {
		wid = document.body.clientWidth;
		hei = document.body.clientHeight;
	}
	wid -= 15;
	dWid = theDiv.clientWidth;
	dHei = theDiv.clientHeight;
	if (ev.clientX + dWid > wid)
		theDiv.style.left = (parseInt(theDiv.style.left) - dWid - 30) + "px";
	if (ev.clientY + dHei > hei)
		theDiv.style.top = (parseInt(theDiv.style.top) - dHei) + "px";
}

function sizeMe(x) {
	var theDiv = document.getElementById('showMeDiv');
	if (x != '')
		theDiv.style.width = x + 'px';
	else
		theDiv.style.width = '';
	theDiv.style.height = '';
}

function scrollMe() {
	scrollVar = 0;
	stillScroll = true;
	sDir = 5;
	nextScrollStep();
	var theDiv = document.getElementById('showMeDiv');
}

function nextScrollStep() {
	var theDiv = document.getElementById('showMeDiv');
	runDelay = 20;
	theDiv.scrollTop = scrollVar;
	scrollVar += sDir;
	if (scrollVar <= 0) {
		scrollVar = 0;
		sDir = -sDir;
		runDelay = 1500;
	}
	if (scrollVar >= theDiv.scrollHeight - parseInt(theDiv.style.height) +25 ) {
		scrollVar = theDiv.scrollHeight - parseInt(theDiv.style.height) + 25;
		sDir = -sDir;
		runDelay = 1500;
	}
	if (stillScroll)
		tId = setTimeout('nextScrollStep()', runDelay);
}

function getInfo(text_value){
	new Ajax.Updater('showMeDiv','jax/return_img_text.php',{method:'post',postBody:'text_value='+text_value});
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function make_focus(obj){
		obj.focus();	
	}

function verifyPassPresse(doc_id,code,file,zip){
	new Ajax.Updater('presse_detail_div','jax/load_presse_pass.jax.php',{evalScripts:true,method:'post',postBody:'doc_id='+doc_id+'&file='+file+'&code='+code+'&zip='+zip});
}

function png_changes()
{	
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	if ((version >= 5.5) && (document.body.filters)) 
	{
	   for(var i=0; i<document.images.length; i++)
	   {
		  var img = document.images[i]
		  var imgName = img.src.toUpperCase()
		  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		  {
			 var imgID = (img.id) ? "id='" + img.id + "' " : ""
			 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			 var imgStyle = "display:inline-block;" + img.style.cssText 
			 if (img.align == "left") imgStyle = "float:left;" + imgStyle
			 if (img.align == "right") imgStyle = "float:right;" + imgStyle
			 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			 var strNewHTML = "<span " + imgID + imgClass + imgTitle
			 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			 img.outerHTML = strNewHTML
			 i = i-1
		  }
	   }
	   //change the default buttons
	   var divs = document.getElementsByTagName("div");
		for (i = 0; i!=divs.length; i++)
		{
			if (divs[i].className == "default_button_FF") divs[i].className="default_button_IE";
		}
	}
}

/*--------------------------------------------------------------------------*/
				/* overlay div */
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll(){
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}
// -----------------------------------------------------------------------------------
//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
	pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
function showSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}
// ---------------------------------------------------

function hideSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}
// ---------------------------------------------------
function showFlash(){
/*
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "visible";
	}
	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "visible";
	}
*/
if ($('logo_anim')) $('logo_anim').show();
if ($('flash_carousel')) $('flash_carousel').show();
if ($('shop_cart_right_corner')) $('shop_cart_right_corner').show();
}
// ---------------------------------------------------

function hideFlash(){
/*
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "hidden";
	}
	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "hidden";
	}
*/
if ($('logo_anim')) $('logo_anim').hide();
if ($('flash_carousel')) $('flash_carousel').hide();
if ($('shop_cart_right_corner')) $('shop_cart_right_corner').hide();
}

function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
       return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".")+1 == email.length) {  // . must not be the last character
	return false;
    }
    return true;
	}

function allValidChars(email) {
	  var parsed = true;
	  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
	  for (var i=0; i < email.length; i++) {
		var letter = email.charAt(i).toLowerCase();
		if (validchars.indexOf(letter) != -1)
		  continue;
		parsed = false;
		break;
	  }
	  return parsed;
	}

function allValidUsernameChars(username){
		var parsed = true;
	  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789_";
	  for (var i=0; i < username.length; i++) {
		var letter = username.charAt(i).toLowerCase();
		if (validchars.indexOf(letter) != -1)
		  continue;
		parsed = false;
		break;
	  }
	  return parsed;
	}

function login_info(){
	$('login_status').innerHTML='';
	$('loading_gif').style.top=240+"px";	
	jQuery("#loading_gif").fadeIn(500);	
	new Ajax.Updater('login_status','jax/login_do.jax.php',{onComplete: function () {jQuery("#loading_gif").fadeOut(500)}, evalScripts:true,method:'post',postBody:'u_name='+$('login_username').value+'&pass='+$('login_password').value+'&remember='+$('remember_checkbox').checked});		
}

function login_after_signup(username,password){	
	$('loading_gif').style.top=240+"px";	
	jQuery("#loading_gif").fadeIn(500);		
	new Ajax.Updater('login_div','jax/login_do.jax.php',{onComplete: function () {jQuery("#loading_gif").fadeOut(500); location.reload(true);}, evalScripts:true,method:'post',postBody:'u_name='+username+'&pass='+password+'&remember=false&no_inactive_message=1'});			
}

function login_do_order(){			
	$('login_status').innerHTML='';
	$('loading_gif').style.top=240+"px";	
	jQuery("#loading_gif").fadeIn(500);	
	new Ajax.Updater('login_status','jax/login_do.jax.php',{onComplete: function () {jQuery("#loading_gif").fadeOut(500)}, evalScripts:true,method:'post',postBody:'u_name='+$('login_username').value+'&pass='+$('login_password').value+'&remember='+$('remember_checkbox').checked+'&order=1'});
}

function login_submit()
{	
	login_info();
}

function logout(){	
	//new Ajax.Updater('debug','jax/logout.jax.php',{evalScripts:true,method:'post'});	
}
var open_cart=0;

function login()
{	
	if ($('is_logged_user').value==0) 
	{
		jQuery('html, body').animate({scrollTop:0});
		var arrayPageSize = getPageSize();
		$('overlay_div').style.width = arrayPageSize[0]+'px';
		$('overlay_div').style.height = arrayPageSize[1]+'px';
		$('overlay_div').style.top = '0px';
		$('overlay_div').style.left= '0px';
		hideSelectBoxes();
		hideFlash();
		jQuery('#overlay_div').fadeIn(200);
		jQuery('#overlay_div').fadeTo(200,0.88, function(){jQuery('#login_div').show()});
		//Element.show('login_div');
		$('loading_gif').style.top=240+"px";	
		jQuery("#loading_gif").fadeIn(500);			
		new Ajax.Updater('login_div', 'jax/login_signup.jax.php', {onComplete: function () {jQuery("#loading_gif").fadeOut(500)}, evalScripts:true, method:'post', postBody:'sid='});				
	}
	else {new Ajax.Updater('login_logout','jax/logout_do.jax.php',{evalScripts:true, method:'post', postBody:'sid='});}
}


function login_order()
{	
		var arrayPageSize = getPageSize();
		$('overlay_div').style.width = arrayPageSize[0]+'px';
		$('overlay_div').style.height = arrayPageSize[1]+'px';
		$('overlay_div').style.top = '0px';
		$('overlay_div').style.left= '0px';
		hideSelectBoxes();
		hideFlash();
		jQuery('#overlay_div').fadeIn(200);
		jQuery('#overlay_div').fadeTo(200,0.88, function(){jQuery('#login_div').show()});
		//Element.show('login_div');	
		new Ajax.Updater('login_div', 'jax/login_order.jax.php', {evalScripts:true, method:'post', postBody:'sid='});
}

function refresh_page(){document.location.href=document.location.href;}

function close_login()
{	
	/*Element.hide('overlay_div');*/
	Element.hide('login_div');
	jQuery('#overlay_div').fadeOut();
	$('login_div').innerHTML='';
	showSelectBoxes();
	showFlash();
	
}

function close_login2(name, rank)
{		
	pos=findPos($('over_my_profile_button'));
	//pos[1]=pos[1]+64;
	jQuery('#overlay_div').hide();
	
	if (rank=="Bronze")$('editare_profil_button').className="my_profile_but_bronze";
	else if (rank=="Silver") $('editare_profil_button').className="my_profile_but_silver";
	else if (rank=="Gold") $('editare_profil_button').className="my_profile_but_gold";
	$('editare_profil_button').style.display='block';
	$('editare_profil_button_name').innerHTML=name;
	jQuery("#login_div").animate({opacity: "0.9",left:pos[0]+"px",top:pos[1]+"px", height: "20", width:"20"}, 'normal', '', function () {$('login_div').innerHTML='';jQuery('#login_div').css({ position:"absolute", top:"55px", left:"0px", zIndex:"999999", display:"none", width:"100%"}); document.location.href=(document.location.href).replace('#',''); });	
	showSelectBoxes();
	showFlash();
	
}

function signup()
{
	$('loading_gif').style.top=240+"px";
	jQuery("#loading_gif").fadeIn(500);
	var arrayPageSize = getPageSize();
	$('overlay_div').style.width = arrayPageSize[0]+'px';
	$('overlay_div').style.height = arrayPageSize[1]+'px';
	$('overlay_div').style.top = '0px';
	$('overlay_div').style.left= '0px';
	hideSelectBoxes();
	hideFlash();
	jQuery('#overlay_div').fadeIn(200);
	jQuery('#overlay_div').fadeTo(200,0.88, function(){jQuery('#login_div').show()});
	/*Element.show('overlay_div');
	Element.show('login_div');*/
	
	new Ajax.Updater('login_div', 'jax/signup.jax.php', {onComplete: function () {jQuery("#loading_gif").fadeOut(500)},evalScripts:true, method:'post', postBody:'sid='});	
}

function signup_order()
{
	var arrayPageSize = getPageSize();
	$('overlay_div').style.width = arrayPageSize[0]+'px';
	$('overlay_div').style.height = arrayPageSize[1]+'px';
	$('overlay_div').style.top = '0px';
	$('overlay_div').style.left= '0px';
	hideSelectBoxes();
	hideFlash();
	jQuery('#overlay_div').fadeIn(200);
	jQuery('#overlay_div').fadeTo(200,0.88, function(){jQuery('#login_div').show()});
	/*Element.show('overlay_div');
	Element.show('login_div');*/	
	new Ajax.Updater('login_div', 'jax/signup.jax.php', {evalScripts:true, method:'post', postBody:'sid=&order=1'});
}

var exist_email; 

function signup_do(frm)
{	
	$('status_signup_checkbox').innerHTML='&nbsp;';
	if (!$('signup_termenisiconditii_chekbox').checked)
	{
		$('signup_termenisiconditii_chekbox').focus();
		$('status_signup_checkbox').innerHTML='<span class="status_span">Daca nu sunteti de acord cu termeni si conditii nu puteti creea contul!</span>';
	}
	else
	{		
		if (!$('deliver_chekbox').checked && !validPostalCode($('signup_deliv_postal_code').value))
		{
			$('signup_deliv_postal_code').focus();
			$('status_deliv_signup_postal_code').innerHTML='<span class="status_span">Introduceti un cod postal corect!</span>';
		}
		else
		{
			$('loading_gif').style.top=250+"px";	
			jQuery("#loading_gif").fadeIn(500);		
			new Ajax.Updater('login_div', 'jax/signup_do.jax.php', {onComplete: function () {jQuery("#loading_gif").fadeOut(500)}, evalScripts:true, method:'post', postBody:'sid=&'+Form.serialize(frm)});
		}
	}
}

function signup_do_order(frm)
{
	new Ajax.Updater('login_div', 'jax/signup_do.jax.php', {evalScripts:true, method:'post', postBody:'sid=&order=1&'+Form.serialize(frm)});
}

function signup_change_user_type(type, frm)
{	
	//Effect.Fade('user_personal_datas', {afterFinish:function () {new Ajax.Updater('user_personal_datas', 'jax/signup_change_user_type.jax.php', {evalScripts:true, method:'post', postBody:'sid=&type='+type+'&name='+frm.signup_name.value+'&cnp_cif='+frm.signup_cnp.value+'&bi_reg_com='+frm.signup_bi.value})}});
	jQuery('#user_personal_datas').fadeOut('slow', function () {new Ajax.Updater('user_personal_datas', 'jax/signup_change_user_type.jax.php', {evalScripts:true, method:'post', postBody:'sid=&type='+type+'&name='+frm.signup_name.value+'&cnp_cif='+frm.signup_cnp.value+'&bi_reg_com='+frm.signup_bi.value})});
}

function check_loginform(password_empty, email_empty, not_valid_email)
{			
		$e=1;
		$('login_password_status').innerHTML='&nbsp;';
		$('login_username_status').innerHTML='&nbsp;';	
		if ($('login_password').value=='')
		{
			$('login_password').focus();
			$('login_password_status').innerHTML='<span class="status_span">'+password_empty+'</span>';
			$e=0;
		}
		if ($('login_username').value=='')
		{
			$('login_username').focus();
			$('login_username_status').innerHTML='<span class="status_span">'+email_empty+'</span>';
			$e=0;
		}else{
			if (!isValidEmail($('login_username').value)) {  // check to make sure all characters are valid				
				$('login_username').focus();				
				$('login_username_status').innerHTML='<span class="status_span">'+not_valid_email+'</span>';
				$e=0;
			}
		}	
		if ($e==0) return false;
		else return true;
}

function read_pin_after_login(art_id)
{	
	var arrayPageSize = getPageSize();
	$('overlay_div').style.width = arrayPageSize[0]+'px';
	$('overlay_div').style.height = arrayPageSize[1]+'px';
	$('overlay_div').style.top = '0px';
	$('overlay_div').style.left= '0px';
	/*document.write('<script type="text/javascript" src="js/prototype.js"></script>');*/
	/*$('showMeDiv').innerHTML='<script type="text/javascript" src="js/scripta/effects.js"></script>';*/
	hideSelectBoxes();
	hideFlash();
	jQuery('#overlay_div').fadeIn(200);
	jQuery('#overlay_div').fadeTo(200,0.88, function(){jQuery('#login_div').show()});
	/*Element.show('overlay_div');
	Element.show('login_div');*/
	new Ajax.Updater('login_div', 'jax/read_pin.jax.php', {evalScripts:true, method:'post', postBody:'sid=&art_id='+art_id});	
}

function birthday(name)
{
	var arrayPageSize = getPageSize();
	$('overlay_div').style.width = arrayPageSize[0]+'px';
	$('overlay_div').style.height = arrayPageSize[1]+'px';
	$('overlay_div').style.top = '0px';
	$('overlay_div').style.left= '0px';
	hideSelectBoxes();
	hideFlash();
	jQuery('#overlay_div').fadeIn(200);
	jQuery('#overlay_div').fadeTo(200,0.88, function(){jQuery('#login_div').show()});
	/*Element.show('overlay_div');
	Element.show('login_div');*/
	new Ajax.Updater('login_div', 'jax/birthday.jax.php', {evalScripts:true, method:'post', postBody:'sid=&name='+name});	
}

function read_pin_after_login_do(art_id, pin, empty_cnp, error_message)
{
	$('login_cnp_status').innerHTML='&nbsp;';	
	if (pin=='')
	{
		$('login_cnp_status').innerHTML='<span class="status_span">'+empty_cnp+'</span>';
	}
	else
	{
		if (validCNP(pin))
		{
			if (pin.substr(0,1)<3) year="19"+pin.substr(1,2);
			else year="20"+pin.substr(1,2);
			month=pin.substr(3,2);
			day=pin.substr(5,2);						
			new Ajax.Updater('debug', 'jax/read_pin_do.jax.php', {evalScripts:true, method:'post', postBody:'sid=&art_id='+art_id+'&pin='+pin+'&year='+year+'&month='+month+'&day='+day});	
			close_login();
		}
		else $('login_cnp_status').innerHTML='<span class="status_span">'+error_message+'</span>';
	}
}

function validateDate(fld)
{
	/*date format: mm/dd/YYYY */
    var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;    
    if ((fld.search(RegExPattern)==0)) {
        return 1;
    } else {        
        return 0;
    } 
}

function validPhone(phone_nb)
{
	reg_expr=/^\d{10}$/;
	if (phone_nb.search(reg_expr)==0) return 1;
	else return 0;
}

function validPostalCode(nb)
{
	reg_expr=/^\d{2,}$/;
	if (nb.search(reg_expr)==0) return 1;
	else return 0;
}

function reverseString(s)
{
	new_s="";
    for (i=s.length; i > 0 ; i -- )     
         new_s += s.substring(i-1, i);
    return new_s;
}

function validCNP(cnp)
{
	re13digit=/^\d{13}$/;
	if (cnp.search(re13digit)==0)
	{		
		if (cnp.substr(0,1)<3) year="19"+cnp.substr(1,2);
		else year="20"+cnp.substr(1,2);
		month=cnp.substr(3,2);
		day=cnp.substr(5,2);
		date=month+"/"+day+"/"+year;
		if(validateDate(date)) 
		{
			test_key="279146358279";
			sum=0;
			for(i=0; i<12;i++)
			{
				sum=sum+test_key.substr(i,1)*cnp.substr(i,1);
			}
			if (sum%11 <10) control_key=sum%11;
			else control_key=1;
			if (control_key==cnp.substr(12,1)) return 1;
			else return 0;
		}
		else return 0;
	}
	else return 0;
}

function validCIF(cif)
{
	reg_expr=/^\d{0,10}$/;
	if (cif.search(reg_expr)==0)
	{
		test_key="753217532";
		reverse_cif=reverseString(cif);		
		reverse_test_key=reverseString(test_key);		
		sum=0;
		for(i=1; i<reverse_cif.length; i++)
		{			
			sum=sum+reverse_test_key.substr(i-1,1)*reverse_cif.substr(i,1);
		}
		verification_nb=(sum*10)%11;
		if (verification_nb==10) verification_nb=0;			
		if (verification_nb==reverse_cif.substr(0,1)) return 1;
		else return 0;		
	}
	else return 0;
}


function updateBirthdateField(cnp, birthdate_field)
{		
	re13digit=/^\d{13}$/;	
	if (cnp.search(re13digit)==0)
	{			
		if (cnp.substr(0,1)<3) year="19"+cnp.substr(1,2);
		else year="20"+cnp.substr(1,2);
		month=cnp.substr(3,2);
		day=cnp.substr(5,2);
		date=month+"/"+day+"/"+year;		
		if(validateDate(date)) {document.getElementById(birthdate_field).value=day+"."+month+"."+year; return 1;}
		else return 0;
	}
	return 0;
	
}

/*Levi's function */
var fixable_png_array = new Array();

function add_png_to_fix(div_id,class_nameFF)
{	
	fixable_png_array.push({'div_id':div_id,'class_name':class_nameFF});	
}

function png_fix()
{
	if (!(/MSIE/.test(navigator.userAgent))){ 
		for (i=0;i<fixable_png_array.length;i++) if ($(fixable_png_array[i].div_id)) $(fixable_png_array[i].div_id).className=fixable_png_array[i].class_name;		
	}
}

function top_menu_over(id)
{
	$('top_menu_'+id).style.display='none';
	$('top_menu_over_'+id).style.display='block';
}
function top_menu_out(id)
{	
	$('top_menu_over_'+id).style.display='none';
	$('top_menu_'+id).style.display='block';
}

function view_prod_img(id, has_primary_img, next_id)
{
	var arrayPageSize = getPageSize();
	$('overlay_div').style.width = arrayPageSize[0]+'px';
	$('overlay_div').style.height = arrayPageSize[1]+'px';
	$('overlay_div').style.top = '0px';
	$('overlay_div').style.left= '0px';
	hideSelectBoxes();
	hideFlash();
	//document.location.href="#";	
	jQuery('html, body').animate({scrollTop:0});
	jQuery('#overlay_div').fadeIn(200);
	jQuery('#overlay_div').fadeTo(200,0.88, function(){jQuery('#zoom_images_div').fadeIn(100,function(){new Ajax.Updater('zoom_images_div', 'jax/view_prod_img.jax.php', {evalScripts:true, method:'post', postBody:'id='+id+'&has_primary_img='+has_primary_img+'&next_id='+next_id});})});
	hideFlash();
	/*Element.show('overlay_div');
	Element.show('login_div');*/
}
function view_prod_img_inner(id, has_primary_img, next_id)
{		
	view_prod_img(id, has_primary_img, next_id)	
}

function close_view_prod_img()
{	
	/*Element.hide('overlay_div');*/
	Element.hide('zoom_images_div');
	jQuery('#overlay_div').fadeOut();
	$('zoom_images_div').innerHTML='';
	showSelectBoxes();
	showFlash();
}

function add_to_wishlist(prod_id, user_id, variant)
{	
	if (user_id=='') user_id=-1;
	var arrayPageSize = getPageSize();
	$('overlay_div').style.width = arrayPageSize[0]+'px';
	$('overlay_div').style.height = arrayPageSize[1]+'px';
	$('overlay_div').style.top = '0px';
	$('overlay_div').style.left= '0px';
	hideSelectBoxes();
	hideFlash();
	/*Element.show('overlay_div');
	Element.show('login_div');*/
	jQuery('#overlay_div').fadeIn(200);
	jQuery('#overlay_div').fadeTo(200,0.88, function(){jQuery('#login_div').show()});
	new Ajax.Updater('login_div','jax/wishlist.jax.php',{evalScripts:true,method:'post',postBody:'prod_id='+prod_id+'&user_id='+user_id+'&variant='+variant});	
}

function add_to_wishlist_do(prod_id, user_id, variant)
{		
	$('loading_gif').style.top=240+"px";	
	jQuery("#loading_gif").fadeIn(500);	
	new Ajax.Updater('login_div','jax/wishlist_do.jax.php',{onComplete: function () {jQuery("#loading_gif").fadeOut(500)},evalScripts:true,method:'post',postBody:'prod_id='+prod_id+'&user_id='+user_id+'&variant='+variant});	
}

function close_add_to_whishlist()
{	
	/*Element.hide('overlay_div');*/
	Element.hide('login_div');
	jQuery('#overlay_div').fadeOut();
	$('login_div').innerHTML='';
	showSelectBoxes();
	showFlash();
}

function add_to_cart(id, variant)
{		
	//document.location.href="#";	
	jQuery('html, body').animate({scrollTop:0});
	var arrayPageSize = getPageSize();
	$('overlay_div').style.width = arrayPageSize[0]+'px';
	$('overlay_div').style.height = arrayPageSize[1]+'px';
	$('overlay_div').style.top = '0px';
	$('overlay_div').style.left= '0px';
	hideSelectBoxes();	
	jQuery('#overlay_div').fadeIn(200, function(){jQuery('#overlay_div').fadeTo(200,0.88, function(){jQuery('#login_div').show()});});	
	/*Element.show('overlay_div');
	Element.show('login_div');*/
	/*alert('itt');*/
	new Ajax.Updater('login_div','jax/shopcart.jax.php',{evalScripts:true,method:'post',postBody:'prod_id='+id+'&variant='+variant});	
}

function add_to_cart_with_preselect_variant(id, variant)
{		
	//document.location.href="#";	
	jQuery('html, body').animate({scrollTop:0});
	var arrayPageSize = getPageSize();
	$('overlay_div').style.width = arrayPageSize[0]+'px';
	$('overlay_div').style.height = arrayPageSize[1]+'px';
	$('overlay_div').style.top = '0px';
	$('overlay_div').style.left= '0px';
	hideSelectBoxes();
	hideFlash();	
	jQuery('#overlay_div').fadeIn(200);
	jQuery('#overlay_div').fadeTo(200,0.88, function(){jQuery('#login_div').show()});
	/*Element.show('overlay_div');
	Element.show('login_div');*/
	/*alert('itt');*/
	new Ajax.Updater('login_div','jax/shopcart.jax.php',{evalScripts:true,method:'post',postBody:'prod_id='+id+'&variant='+variant+'&preselect=1'});	
}

function add_to_cart_do(prod_id, prod_name, price, prod_count, prod_variant, promotion_price, old_price)
{		
	//alert(old_price);
	$('loading_gif').style.top=240+"px";	
	jQuery("#loading_gif").fadeIn(500);	
	new Ajax.Updater('debug','jax/shopcart_do.jax.php',{onComplete: function () {jQuery("#loading_gif").fadeOut(500)},evalScripts:true,method:'post',postBody:'prod_id='+prod_id+'&prod_name='+prod_name+'&price='+price+'&prod_count='+prod_count+'&prod_variant='+prod_variant+'&promotion_price='+promotion_price+'&old_price='+old_price});	
	
}
function close_add_to_cart()
{
	/*Element.hide('overlay_div');*/
	Element.hide('login_div');
	jQuery('#overlay_div').fadeOut();
	$('login_div').innerHTML='';
	showSelectBoxes();
	showFlash();
}

function onchange_prodcount(key, value, changed_input)
{
	pos=findPos(changed_input);	
	$('loading_gif').style.top=(pos[1]+15)+"px";	
	jQuery("#loading_gif").fadeIn(500);
	new Ajax.Updater('shopcart','jax/onchange_values_in_shopcart.jax.php',{onComplete: function () {jQuery("#loading_gif").fadeOut(500)}, evalScripts:true,method:'post',postBody:'shopcart_key='+key+'&new_prod_count='+value});	
}

function load_transport_bar(sum)
{
	new Ajax.Updater('transport_ranking_bar_div','jax/ranking_bar_transport.jax.php',{evalScripts:true,method:'post',postBody:'sum='+sum});	
}
function load_discount_bar(sum)
{
	new Ajax.Updater('discount_ranking_bar_div','jax/ranking_bar_discount.jax.php',{evalScripts:true,method:'post',postBody:'sum='+sum});
}

function slide_pass_reminder()
{
	jQuery("#login_button").toggle();	
	jQuery("#pass_reminder_div").slideToggle("slow");	
}
function send_reminder(email,text)
{
	var my_email=email;
	if (isValidEmail(my_email)) new Ajax.Updater('pass_reminder_div','jax/pass_reminder.jax.php',{evalScripts:true,method:'post',postBody:'email='+my_email});		
	else alert(text);
}

function order()
{	
	new Ajax.Updater('shopcart','jax/check_before_order.jax.php',{evalScripts:true,method:'post',postBody:'id='});		
}


function order_form()
{
	var arrayPageSize = getPageSize();
	$('overlay_div').style.width = arrayPageSize[0]+'px';
	$('overlay_div').style.height = arrayPageSize[1]+'px';
	$('overlay_div').style.top = '0px';
	$('overlay_div').style.left= '0px';
	hideSelectBoxes();
	hideFlash();
	jQuery('#overlay_div').fadeIn(200);
	jQuery('#overlay_div').fadeTo(200,0.88, function(){jQuery('#login_div').show()});
	/*Element.show('overlay_div');
	Element.show('login_div');*/
	//document.location.href="#";	
	jQuery('html, body').animate({scrollTop:0});
	new Ajax.Updater('login_div','jax/order_form.jax.php',{evalScripts:true,method:'post',postBody:'id='});		
}

function close_order_form()
{
	/*Element.hide('overlay_div');*/
	Element.hide('login_div');
	jQuery('#overlay_div').fadeOut();
	$('login_div').innerHTML='';
	showSelectBoxes();
	showFlash();
}

function send_order(frm)
{
	//pos=findPos(changed_input);	
	$('loading_gif').style.top=240+"px";	
	jQuery("#loading_gif").fadeIn(500);		
	new Ajax.Updater('login_div', 'jax/send_order.jax.php', {onComplete: function () {jQuery("#loading_gif").fadeOut(500)}, evalScripts:true, method:'post', postBody:'sid=&'+Form.serialize(frm)});	
	refresh_page();
}

function remove_from_shopcart(key)
{
	new Ajax.Updater('shopcart','jax/shopcart_remove.jax.php',{evalScripts:true,method:'post',postBody:'remove_key='+key});	
}


function change_transport(county, city)
{
	new Ajax.Updater('debug', 'jax/change_transport.jax.php', {evalScripts:true, method:'post', postBody:'sid=&county='+county+'&city='+city});	
}

	
function get_radio_value()
{
	for (i=0; i < document.orderform.product_variant_radio.length; i++)
   	{   		
   		if (document.orderform.product_variant_radio[i].checked)
      	{
     		return document.orderform.product_variant_radio[i].value;
      	}      	
   }
   return '';
}

/*tooltip*/
function tooltip_right(target_items, name, text){
 jQuery(target_items).each(function(i){
		jQuery("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+text+"</p></div>");
		var my_tooltip = jQuery("#"+name+i);

		if(jQuery(this).attr("title") != ""){ // checks if there is a title

		jQuery(this).removeAttr("title").mouseover(function(){
				my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(400);
		}).mousemove(function(kmouse){
				my_tooltip.css({left:kmouse.pageX+15, top:kmouse.pageY+15});
		}).mouseout(function(){
				my_tooltip.fadeOut(400);
		});

		}
	});
}

function tooltip_left(target_items, name, text){	
 jQuery(target_items).each(function(i){ 		
		jQuery("body").append("<div class='"+name+"' id='"+name+i+"'><div>"+text+"</div></div>");
		var my_tooltip = jQuery("#"+name+i);

		if(jQuery(this).attr("title") != ""){ // checks if there is a title

		jQuery(this).removeAttr("title").mouseover(function(){
				my_tooltip.css({display:"none"}).fadeIn(400);
		}).mousemove(function(kmouse){
				my_tooltip.css({left:kmouse.pageX-145, top:kmouse.pageY+15});
		}).mouseout(function(){
				my_tooltip.fadeOut(100);
		});

		}
	});
}

function tooltip_left2(target_items, name, text){	
 jQuery(target_items).each(function(i){	 		
 		pos=findPos($('order_comments')); 		
		jQuery("body").append("<div class='"+name+"' id='"+name+i+"' style='z-index:99999999'><div>"+text+"</div></div>");
		var my_tooltip = jQuery("#"+name+i);

		if(jQuery(this).attr("title") != ""){ // checks if there is a title		
		jQuery(this).removeAttr("title").click(function(){
				my_tooltip.css({display:"none"}).fadeIn(400);
		}).click(function(kmouse){
				my_tooltip.css({left:pos[0]+152, top:pos[1]-70});
		}).blur(function(){
				my_tooltip.fadeOut(100);
		});

		}		
	});
}


function tooltip_left_signup_form(target_items, name, text){
 jQuery(target_items).each(function(i){ 		
 		pos=findPos($('signup_email')); 		
		jQuery("body").append("<div class='"+name+"' id='"+name+i+"' style='z-index:99999999'><div>"+text+"</div></div>");
		var my_tooltip = jQuery("#"+name+i);
		my_tooltip.css({display:"none"}).fadeIn(400);
		my_tooltip.css({left:pos[0]+180, top:pos[1]});
		jQuery(this).blur(function(){my_tooltip.fadeOut(100);});		
	});
}
/*tooltip end*/

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function select_next_step(list_count)
{		
	var arrayPageSize = getPageSize();
	$('overlay_div').style.width = arrayPageSize[0]+'px';
	$('overlay_div').style.height = arrayPageSize[1]+'px';
	$('overlay_div').style.top = '0px';
	$('overlay_div').style.left= '0px';
	hideSelectBoxes();	
	jQuery('#overlay_div').fadeIn(200, function(){jQuery('#overlay_div').fadeTo(200,0.88, function(){jQuery('#login_div').show()});});	
	/*Element.show('overlay_div');
	Element.show('login_div');*/
	/*alert('itt');*/
	new Ajax.Updater('login_div','jax/select_next_step.jax.php',{evalScripts:true,method:'post',postBody:'list_count='+list_count});	
}

function continue_shopping(list_count)
	{
		close_login();
		jaaspeel.putObjects('shop_cart_right_corner');
		close_add_to_cart()
		$('shop_cart_count').innerHTML=list_count;
		//window.location.reload(true);
	}
	
function updateCities(county){	
	new Ajax.Updater('signup_city_div','jax/update_cities.jax.php',{evalScripts:true,method:'post',postBody:'county='+county+'&select_name=signup_city'});	
}

function updateOrderFormCities(county){	
	new Ajax.Updater('deliver_city_div','jax/update_order_form_cities.jax.php',{evalScripts:true,method:'post',postBody:'county='+county});	
}

function updatePostalCode(county, city, street, sector)
{
	new Ajax.Updater('debug','jax/update_postal_code.jax.php',{evalScripts:true,method:'post',postBody:'county='+county+'&city='+city+'&street='+street+'&sector='+sector+'&input_name=signup_postal_code'});
}

function updateCities2(county){
	new Ajax.Updater('signup_deliv_city_div','jax/update_cities.jax.php',{evalScripts:true,method:'post',postBody:'county='+county+'&select_name=signup_deliv_city'});
}

function updatePostalCode2(county, city, street, sector)
{
	new Ajax.Updater('debug','jax/update_postal_code.jax.php',{evalScripts:true,method:'post',postBody:'county='+county+'&city='+city+'&street='+street+'&sector='+sector+'&input_name=signup_deliv_postal_code'});
}

function remove_avatar(user_id)
{
	new Ajax.Updater('avatar_div','jax/avatar_remove.jax.php',{evalScripts:true,method:'post',postBody:'user_id='+user_id});	
}

var nb_of_delivery_address=0;
var delivery_address_index=0;

function add_delivery_address(style_mode)
{	
	/*jQuery('#delivery_address_tr_'+nb_of_delivery_address).show(); 
	jQuery('#delivery_address_white_line_'+nb_of_delivery_address).show(); 
	jQuery('#edit_deliv_address_visible_'+nb_of_delivery_address).val('1'); 
	jQuery('#delivery_address_div_'+nb_of_delivery_address).show();*/
	jQuery.ajax({
		type: "POST",
		url: "jax/add_delivery_address.jax.php",
		data: "delivery_address_index="+delivery_address_index+"&nb_of_delivery_address="+nb_of_delivery_address+"&style_mode="+style_mode,
		success: function(html){			
			jQuery("#new_delivery_addresses_div").html(jQuery("#new_delivery_addresses_div").html()+html);
		}

	})	
	nb_of_delivery_address++;	
	delivery_address_index++;
}

function save_delivery_address(id, name, address, city, county, postal_code, phone, message_container, index)
{		
	jQuery.ajax({
		type: "POST",
		url: "jax/save_delivery_addresses.jax.php",
		data: "id="+id+"&name="+name+"&address="+address+"&city="+city+"&county="+county+"&postal_code="+postal_code+"&phone="+phone,
		success: function(msg){
			jQuery('#'+message_container).fadeIn();
			setTimeout("jQuery('#"+message_container+"').fadeOut();",1000)
			jQuery('#edit_deliv_address_id_'+index).val(msg);			
			jQuery('#delete_a_'+index).attr( "onclick","" )
			jQuery('#delete_a_'+index).click(function(){
				delete_delivery_address(jQuery('#edit_deliv_address_id_'+index).val(), index); 
				nb_of_delivery_address--; 
				jQuery('#delivery_address_tr_'+index).hide();					
			})		
			
			jQuery('#cancel_a_'+index).attr( "onclick","" )
			jQuery('#cancel_a_'+index).click(function(){				
				jQuery('#delivery_address_div_'+index).slideUp('normal', function(){jQuery('#delivery_address_short_'+index).slideToggle()});				
			})	
			jQuery('#delivery_address_short_content_'+index).html('<b>'+name+'</b><br />'+address+', '+city+', '+postal_code+', '+county);
			jQuery('#delivery_address_div_'+index).slideUp('normal', function(){jQuery('#delivery_address_short_'+index).slideToggle()});
		}

	})
}

function delete_delivery_address(id,index)
{		
	jQuery.ajax({
		type: "POST",
		url: "jax/delete_delivery_addresses.jax.php",
		data: "id="+id,
		success: function(msg){			
			jQuery('#edit_deliv_name_'+index).val('');
			jQuery('#edit_deliv_address_phone_'+index).val('');
			jQuery('#edit_deliv_address_'+index).val('');
			jQuery('#edit_deliv_city_'+index).val('');
			jQuery('#edit_deliv_postal_code_'+index).val('');
			jQuery('#delivery_adresses_status').html('');
			$('edit_deliv_name_status_'+index).innerHTML='';
			$('edit_deliv_address_phone_status_'+index).innerHTML='';
			$('edit_deliv_address_status_'+index).innerHTML='';
			$('edit_deliv_city_status_'+index).innerHTML='';
			$('edit_deliv_postal_code_status_'+index).innerHTML='';
		}
	})
}

function delete_old_delivery_address(id)
{		
	jQuery.ajax({
		type: "POST",
		url: "jax/delete_delivery_addresses.jax.php",
		data: "id="+id,
		success: function(msg){			
			jQuery('#new_delivery_address_status').hide();			
		}
	})
}

function cancel_delivery_address(index)
{		
	jQuery('#delivery_address_tr_'+index).hide(); 
	jQuery('#delivery_adresses_status').html('');
	$('edit_deliv_name_status_'+index).innerHTML='';
	$('edit_deliv_address_phone_status_'+index).innerHTML='';
	$('edit_deliv_address_status_'+index).innerHTML='';
	$('edit_deliv_city_status_'+index).innerHTML='';
	$('edit_deliv_postal_code_status_'+index).innerHTML='';
	jQuery('#delivery_address_white_line_'+index).hide();
}

var nb_of_remained_place_for_delivery_adresses;

function onchange_product_count_input_field(prod_id)
{
	if (jQuery('#prod_count').val()<0 || jQuery('#prod_count').val()=='') jQuery('#prod_count').val('0');
	else
	{
		prod_variant=jQuery("input[name='product_variant_radio']:checked").val()		
		jQuery("#prod_count_input_container").load("jax/verify_real_stock.jax.php",{'prod_id':prod_id, 'prod_variant':prod_variant, 'new_prod_count':jQuery('#prod_count').val()})
	}
}