Global = {
	mouseY: null,
	mouseY: null,
	initialize : function()
    {
        var ua = navigator.userAgent.toLowerCase();

        this.isOpera = (ua.indexOf('opera') > -1);
        this.isSafari = (ua.indexOf('safari') > -1);
        this.isGecko = (!this.isOpera && !this.isSafari && ua.indexOf('gecko') > -1);
        this.isIE = (!this.isOpera && ua.indexOf('msie') > -1);
        this.isMac = (ua.indexOf('macintosh') > -1);

        if(this.isIE)
        {
            var msieIndex = ua.indexOf('msie');
            this.IEVersion = parseFloat(ua.substring(msieIndex + 5, ua.indexOf(';', msieIndex)));
        }
        else
        {
            this.IEVersion = -1;
        }

        if(this.isGecko) {
            var index = ua.indexOf('firefox');
            this.FFVersion = parseFloat(ua.substring(index + 8 ));
        }

        this.setMoveListener();
    },

    setMoveListener: function(){
    	if(Global.isIE){
            document.attachEvent("onmousemove", Global.mouseMove);
        }else{
            document.addEventListener('mousemove',Global.mouseMove,true);
        }
    },

    mouseMove: function (e){
    	try{
            Global.mouseX = (!Global.isIE) ? e.pageX : event.x+document.body.scrollLeft;
            Global.mouseY = (!Global.isIE) ? e.pageY : event.y+document.body.scrollTop;
        }catch(e){}
    }
}

Global.initialize();

Array.prototype.in_array = function(value){
    for(var k=0;k<this.length;k++){
        if(value == this[k]){
            return true;
        }
    }
    return false;
}

Array.prototype.array_unique = function(){
    var newArray = new Array();

    for (var i=0; i<this.length; i++) {
        if(newArray.in_array(this[i])){
            continue;
        }
        newArray.push(this[i]);
    }

    return newArray;
}
function MobileAddProductToCart(form_id,tab_id,id,type){
    var aData = $j('#'+form_id).serialize();
    if(type == 'quickorder'){
        $j("#loader_"+id).css("visibility","visible");
        $j.post("?action=quickorder_ajax&mode=addToCart",  aData ,
            function(data){
                $j('#header_total').html(data.total);
                $j('.products-list [type=text]').val(0);
                $j("#tr_qo_product_"+id).removeClass("product-bottom");
                $j("#append").appendTo("#td_qo_product_"+id);
                $j("#tr2_qo_product_"+id).addClass("product-bottom");
                $j("#append").css("display","block");
                $j("#loader_"+id).css("visibility","hidden");
            },"json");
    }
    if(type == 'product'){
        $j("#loader_").css("visibility","visible");
        $j.post("?action=quickorder_ajax&mode=addToCart",  aData ,
            function(data){
                $j('#header_total').html(data.total);
                $j('.quantity [type=text]').val(0);
                $j("#append").appendTo("#toappend");
                $j("#append").css("display","block");
                $j("#append").css("padding-bottom","10px");
                $j("#loader_").css("visibility","hidden");
            },"json");
    }
}
function addProductToCart(form_id,tab_id, pm_office){
    if(pm_office == 1){
       addToBin(form_id);
    }else{
	   openBinPopup(tab_id,pm_office);
       addToBin(form_id);
    }
}

/* functions which are necessary for product ordering */
function openBinPopup(tab_id,pm_office){
    if (pm_office == 1) {
        str = '&pm_office='+pm_office;
    }else{
        str='';
    }
    
	w=window.open("?action=check_continue&tab="+tab_id+str+"", "BinInfo", "toolbar=no,width=250,height=200,directories=no,status=no,scrollbars=no, resizable=yes, menubar=no, location=no");
}
function addToBin(form_id) {
    document.forms[form_id].submit();
}

function pageStatus() {
    if( document.getElementById('is_loaded') ){
    	document.getElementById('is_loaded').value=1;
    }
}

function ShowGalleryImage($image)
{
	var win=window.open( $image, "aaa", "width=480,height=480,resizable=yes,scrolling=yes");
	win.focus();
}

function flashPopup(id,type){
    $j('#new_style_popup_video .content').css('min-height','390px');
    $j('#new_style_popup_video .content').css('height','auto');
    $j('#pmi_video').css('display','none'); 

    w = '770px';
    l = '250px';
    t = '200px';
    h = 'auto';
    if(type == 'intro'){
        w = '440px';
        l = '350px';
    }

    uipopup('new_style_popup_video',w,h,l,t,true,'0px',true);  
    $j('.blockOverlay').css('cursor','default'); 
     
    getPopupVideo(id,type);
    /*
    
	if( typeof _flashPopup == "function"){
		_flashPopup(id);
	} else {
		window.open("?action=video&id="+id, "", "toolbar=no,width=825,height=510,directories=no,status=no,scrollbars=no, resizable=yes, menubar=no, location=no");
    }
    */
}


function getSportPopup(id,cid,isnewsession, type_video, overlayCSS, callbackFuncName,siteType){
    $j('#new_style_popup_video .content').css('min-height','390px');
    $j('#new_style_popup_video .content').css('height','auto');
    $j('#pmi_video').css('display','none'); 

    w = '440px';
    l = '350px';
    t = '200px';
    h = 'auto';

    uipopup('new_style_popup_video',w,h,l,t,true,'0px',true, overlayCSS, callbackFuncName);  
    $j('.blockOverlay').css('cursor','default'); 
     
    getSportPopupVideo(id,cid,isnewsession,type_video,siteType, callbackFuncName);

}


function getSportPopupVideo(id,cid,isnewsession, type_video, siteType,showpage){
//alert(cid);
    $j('.colorLoader').css('margin','0 auto');
    $j('.colorLoader').css('margin-top','160px'); 
    $j('.colorLoader').css('display','block');
    param = '';
    
    if(typeof(cid) != 'undefined'){
        param  = '&cid='+cid;
    }
    if(typeof(isnewsession) != 'undefined'){
        param  = param + '&isnewsession=1';
    }

    if(typeof(siteType) == 'undefined'){
        var siteType = 2;
    }    
        
    param  = param + '&siteType='+siteType;
    
    if(typeof(type_video) != 'undefined'){
        param  = param+ '&type_video='+type_video;
    }
        
    if(typeof(showpage) != 'undefined'){
        param  = param+ '&showpage=1';
    }    
    
    //alert('?action=video'+param);
    
    $j.getJSON('?action=video'+param,
               {id: id},
               function (data){
               $j('.colorLoader').css('display','none');
               $j('#pmi_video').html(data.html);
               $j(".but").corner("5px");
               $j('#pmi_video').css('display','block');
               setzero();
               }
    );
}

function showPage(){
    //alert('show page called');
    $j('#container').css('display','');    
}


function aboSelectMonthPopup(){
    if(!$j("table").is(".product_list")){
        $j('#update_data').val('1');
        $j('#abo_order_form').submit();   
        return;
    }
    w = '550px';
    l = '350px';
    t = '300px';
    h = 'auto';
    uipopup('abo_popup',w,h,l,t,true,'0px',true);  
    $j('.blockOverlay').css('cursor','default');
    return false; 
     
}
function resultAboMonthPopup(result){
    
    if(result == 1){
        UIPopupClose();
        $j('#update_data').val('1');
        $j('#abo_order_form').submit();   
    }else{
        v = $j("#delivery_count_month option:selected").val();
        if(v == 1){
           $j("#delivery_count_month [value='3']").attr("selected", "selected"); 
        }else if(v == 3){
            $j("#delivery_count_month [value='1']").attr("selected", "selected"); 
        }
        UIPopupClose();
        return false;
    }
    
}


function introClose(){
    if(typeof(is_five_seconds) == 'number'){
        setTimeout('goFollowTo()',5000);//redirect for LC
    }
}


function getPopupVideo(id,type, isnewsession, cid, TP){
    $j('.colorLoader').css('margin','0 auto');
    $j('.colorLoader').css('margin-top','160px'); 
    $j('.colorLoader').css('display','block');
    param = '';
    
    if(type == 'intro'){
        param  = '&type_video=intro&sport=0';
    }

        //param  = '&type_video=intro';
    
  /*  
    if(typeof(isnewsession) != 'undefined'){
        param  = param + '&isnewsession=1&siteType=2';
    }        
    
    if(typeof(cid) != 'undefined'){
        param  = param + '&cid='+cid;
    }
    
    if(typeof(TP) != 'undefined'){
        param  = param + '&TP='+TP;
    }        
*/
    $j.getJSON('?action=video'+param,
               {id: id},
               function (data){
               $j('.colorLoader').css('display','none');
               $j('#pmi_video').html(data.html);
               $j(".but").corner("5px");
               $j('#pmi_video').css('display','block');
               setzero();
               }
    );
}

function savepopupcookie(video_id){
   
    $j.getJSON('?action=ajax.savecookievideo', {video_id: video_id},
               function (data){
                    //alert('asdasdasd');
               }
    );
}

function setzero(){
    $j(".flash_product_block input[type=text]").bind("click", function(data){               
        value = $j(this).attr('value');
        if (value == 0) {
            $j(this).attr('value','');
        }
    });
    $j(".flash_product_block input[type=text]").bind("blur", function(data){
        value = $j(this).attr('value');
        if (value == ''){
            $j(this).attr('value',0);
        }
    });
}

function flashPopupNew(id, cid){
	window.open("?action=video&cid="+cid+"&id="+id, "", "toolbar=no,width=825,height=510,directories=no,status=no,scrollbars=no, resizable=yes, menubar=no, location=no");
}

function orderSubmode(submode, mode, cid){
//	alert(cid);

	document.getElementById('new_country_id').value=cid;
	//alert(document.getElementById('new_country_id'));
	//alert(cid);
	document.getElementById('order_step').value=mode;
	document.getElementById('submode').value=submode;
	document.forms['bin'].submit();
}

/**
 * used in audio_popup page only
 */
function newWin(url, width, height) {
	var winNew = window.open( url, "winFullScreen", "width="+ width +",height="+ height +",resizable,scrolling,scrollbars" );
 	winNew.focus();
}

function openIngredients(p_id, cid)
{
	// wnd = window.open("?action=product&subact=ingredient&p_id="+p_id+"&cid="+cid, "Ingredients", "toolbar=no,width=300,height=250,directories=no,status=no,scrollbars=yes,resizable=no,menubar=no");
    
    $j('#ingredients').dialog({ resizable: false,position: [100,50]});
    $j("#ingredients").dialog('option', 'title', '');
    $j("#ingredients").dialog('option', 'width', 300);
    $j("#ingredients").dialog('option', 'height', 'auto');
    $j('#ingredients').bind('dialogclose', function(event, ui) {
        $j(this).dialog("destroy");
    });
    $j("#ingredients").dialog();

}

function openVersandkosten(type){
    if(type == 0){
        var id ="Versandkosten";
    }else{
        var id ="Versandkosten_closed";
    }
        $j('#'+id).dialog({ resizable: false,position: [100,50]});
        $j('#'+id).dialog('option', 'title', '');
        $j('#'+id).dialog('option', 'width', 300);
        $j('#'+id).dialog('option', 'height', 'auto');
        $j('#'+id).bind('dialogclose', function(event, ui) {
            $j(this).dialog("destroy");
        });
        $j('#'+id).dialog();

    
}


function openIngredientsYouniverse(p_name,title)
{
    
    $j('#ingredients').dialog({ resizable: false,position: [100,50]});
    $j("#ingredients").dialog('option', 'title', '');
    $j("#ingredients").dialog('option', 'width', 500);
    $j("#ingredients").dialog('option', 'height', 'auto');
    $j('#ingredients').bind('dialogclose', function(event, ui) {
        $j(this).dialog("destroy");
    });
    $j("#ingredients").dialog();
}


function getElementPosition(elemId)
{
	var elem = document.getElementById(elemId);

	var w = elem.offsetWidth;
	var h = elem.offsetHeight;

	var l = 0;
	var t = 0;

	while (elem)
	{
		l += elem.offsetLeft;
		t += elem.offsetTop;
		elem = elem.offsetParent;
	}

	return {"left":l, "top":t, "width": w, "height":h};
}


function getCookie(c_name){
	if(document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
	    {
	    c_start=c_start + c_name.length+1;
	    c_end=document.cookie.indexOf(";",c_start);
	    if (c_end==-1) c_end=document.cookie.length;
	    return unescape(document.cookie.substring(c_start,c_end));
	    }
	  }
	return "";
}

function checkCookie(name, callback, isSelf , cid){
	if(typeof(name) == 'undefuned' || name == '' ){
		return false;
	}

	if(typeof(isSelf) != 'undefined'){
		$j.getJSON('?tmcookies=1&tmcookiesname=' + name + '&cid=' + cid, {}, function(json){ if(json == 'ok'){
			if(typeof(callback != 'undefined')){
				try{
					cook=getCookie(name);
					if (cook!=null && cook!=""){
						eval(callback);
					}else{
					  //alert('Enable the support cookies please! It is necessary for further work!');
						showCookiePopup();
					}
				}catch(e){}
			}

		}});
	}else{
		cook=getCookie(name);
		if (cook!=null && cook!=""){
		  return true;
		}else{
		  //alert('Enable the support cookies please! It is necessary for further work!');
			showCookiePopup();
		  return false;
		}
	}
}

function displayMode(id){
	vs = $j('#'+ id).css('display');
	if( typeof(vs) == null || vs == 'none'){
	    $j('#' + id).show();
	}else{
	    $j('#' + id).hide();
	}
}

function showBlock(id){
	$j('#' + id).show();
}

function hideBlock(id){
	$j('#' + id).css('display','none');
}

var interested = {
	cultivate: function(data){
		$j.each(data, function (key, value){
			switch(key){
				case 'alert':
						alert(value);
					break;
				case 'update':
						$j.each(value, function(id, data){
							switch(data.action){
								case 'html':
										$j('#' + data.id).html(data.val);
									break;
								case 'val':
									$j('#' + data.id).val(data.val);
									break;
							}
						});
					break;
				case 'eval':
						eval(value);
					break;

			}
		});

	},
	personSave: function(id){
		data = $j('#' + id).serialize();
		this.doAjax('person_save', data, 'person_data_section_info', 'html', id);
	},

	onlineSave: function(id){
		data = $j('#' + id).serialize();
        this.doAjax('online_save', data, 'person_online_info', 'html', id);
	},

	conferenceSave: function(id){
		data = $j('#' + id).serialize();
		this.doAjax('conference_save', data, 'person_conference_info', 'html', id);
	},

	partnerSave: function(id){
		data = $j('#' + id).serialize();
		this.doAjax('partner_save', data, 'person_teampartner_info', 'html', id);
	},

	partnerInviteReg: function(id){
		data = $j('#' + id).serialize();
		this.doAjax('partnerInviteReg', data, 'person_teampartner_info', 'html', id);
	},
        
   	academySave: function(id){
		data = $j('#' + id).serialize();
		this.doAjax('academy_save', data, 'person_academy_info', 'html', id);
	},


	doAjax:function(action, data, key, dataType, id){
		$j("#loader_"+id).css('visibility', 'visible');
		switch(dataType){
			case 'html':
					$j.getJSON(window.location.href + '&saction=check_state', {}, function(json){
						if(json.state=='ok'){
							$j.get(window.location.href + '&saction='+ action + '&data=' + data, function(data){$j('#' + key).html(data);});
						}
						$j("#loader_"+id).css('visibility', 'hidden')
					});

				break;
			default:
					$j.getJSON(window.location.href + '&saction='+ action + '&data=' + data, {}, function(json){interested.cultivate(json);});
				break;
		}

	}
}

function getContent(id){
	if(id != ''){
		$j.get(window.location.href + '&saction=get_seminar_content&id=' + id, function(data){$j('#online_data_address').html(data);});
	} else {
		$j('#online_data_address').html('');
	}
}

function uipopupGeneric(block_id,showOverlay,w,h,l,t,radius,click_unblock ){

    if(typeof(showOverlay) == 'undefined' || showOverlay == null){
        showOverlay = false;
    }
    
    uipopup(block_id,w,h,l,t,showOverlay,radius,click_unblock);    
}

function uipopup(block_id,w,h,l,t,showOverlay,radius,click_unblock, overlayCSS, callbackFuncName){
    //w - width
    //h - height
    //l - position left
    //t - position top
    //alert(overlayCSS);
    if(typeof(overlayCSS) == 'undefined' ){
        overlayCSS = { 
            backgroundColor: '#000', 
            opacity:         0.6 
        }
    }
    //alert(overlayCSS);
    //return;
     
    if(typeof(w) == 'undefined' || w == null){
        w = '450px';
    }
    if(typeof(h) == 'undefined' || h == null){
        h = 'auto';
    }
    if(typeof(l) == 'undefined' || l == null){
        l = '350px';
    }
    if(typeof(t) == 'undefined' || t == null){
        t = '150px';
    }
    if(typeof(showOverlay) == 'undefined' || showOverlay == null){
        showOverlay = true;
    }
    if(typeof(radius) == 'undefined' || radius == null){
        radius = "0px";
    }
    if(typeof(click_unblock) == 'undefined' || click_unblock == null){
        click_unblock = false;
    }
        $j.blockUI({
                message: $j('#'+block_id),
                showOverlay: showOverlay,
                overlayCSS: overlayCSS,                 
                css: { width: w,
                       height: h,
                     //  '-webkit-border-radius': radius, 
                     //  '-moz-border-radius': radius, 
                       left: l,
                       top:t,
                       cursor: 'default' 
                       }  
        });
        //$j.unblockUI({ fadeOut: 20000 }); 
        if(click_unblock == true){
            //$j('.blockOverlay').attr('title','Click to unblock').click($j.unblockUI);
              $j('.blockOverlay').attr('title','Click to unblock').click(function() {              
              $j.unblockUI();
              if(typeof(callbackFuncName) != 'undefined' ){
                  return callbackFuncName();      
        }
        
            });            
                         
        }
        
        
        /*ua = navigator.userAgent.toLowerCase();
        if(ua.indexOf("msie") == -1){
            $j(".but").corner("5px"); //padaet tyt esli debugger stoit
        }*/
   	    $j(".but").corner("5px");
        //$j("#"+block_id).corner(radius);
        
}

function UIPopupClose(){
    $j.unblockUI();
}


function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

// displays a floating message bar at top of page 
function showTopMessage(){
    $j('#UItextMessage').dialog({ resizable: false,position: [350,150],zIndex : 2000});
    $j('#UItextMessage').bind('dialogclose', function(event, ui) {
        $j(this).dialog("destroy");
    });
    $j("#UItextMessage").dialog('option', 'title', '');
    $j("#UItextMessage").dialog('option', 'width', 400);


}

function setCameraImage(){
            //var url =  '{/literal}{$cameraImageUrl}{literal}?'+Math.random();
            var url =  'https://www.pm-international.com/camera.php?'+Math.random();
            //alert(url);
            //var image1 = $j('<img />').attr('src', url);
            //image1.attr('id','camera1');
            // Insert preloaded image into the DOM tree
            //$j('#camera_image').html(image1);
            var src = url;
            $j('#camera1').fadeOut('fast',function(){
                    $j('#camera1').attr('src',src);
                    $j('#camera1').fadeIn('fast');
                    });                                                
            setTimeout("setCameraImage()", 6700);

}

function addQuickorderProductAjax(){
    //autoship case
    
    
    data = $j("#abo_order_form").serialize();
    
	url = '?action=ajax.quickorder.inc';

	$j.post(url, data, function(response){
		// todo  
        var autoship_product = $j('input:radio[name=data[abo_product_id]]:checked').val();
        $j('#sub_order_'+autoship_product).html(response);
	}, "html" );    
}



var autoship = {
    
    url : '?action=ajax.autoship',
   	

   	delProd: function(product_owner_id,article_number){
    
        //url = '?action=ajax.autoship';
        autoship.showLoader();
    	$j.post(this.url, {'remove_article_owner_id' : product_owner_id, 'remove_article_number' : article_number}, function(response){    		
            $j('#sub_order_'+product_owner_id).html(response);
            autoship.hideLoader();
    	}, "html" );               
	},
    
    addProd: function(){    
        data = $j("#abo_order_form").serialize();
        autoship.showLoader();        
    	//url = '?action=ajax.autoship';
    
    	$j.post(this.url, data, function(response){
    		// todo  
            var autoship_product = $j('input:radio[name=data[abo_product_id]]:checked').val();
            $j('#sub_order_'+autoship_product).html(response);
            autoship.setZeroes();
            autoship.hideLoader();
            
    	}, "html" );       
    },
    
    setZeroes: function(){
        $j("#page_content input:text").attr('value', 0);
    },
    
    hideLoader: function(){
        $j("#loader_order").css('visibility', 'hidden');
    },
        
    showLoader: function(){
        $j("#loader_order").css('visibility', 'visible');
    },
    
    setAutoZero: function(){
        
        $j(".shop_content [type=text]").bind("click", function(data){               
                    value = $j(this).attr('value');
                    if (value == 0) {
                        $j(this).attr('value','');
                    }
        });
            

        $j(".shop_content [type=text]").bind("blur", function(data){
                    value = $j(this).attr('value');
                    if (value == ''){
                        $j(this).attr('value',0);
                    }
        });  
    },
    
    gotab: function(tab_num,cid,cat_id){
        
        autoship.showLoader();   
        if(typeof(cat_id) != 'undefined'){
            
            url = '?action=quickorder.inc&atsh=1&cat_id='+cat_id;
            
        }else{
            
            url = '?action=quickorder.inc&atsh=1';
            
        }
        
         
        $j.getJSON(url,{qo_tab : tab_num , cid : cid},
            function(response){
                
                $j("#content_abo").html(response);
                autoship.hideLoader();
                autoship.setAutoZero();
            });
    }    
    

        
}





function mandatoryabocheckbox(id){
     
     first =  $j('#select_autoship input:checkbox:firts').attr('checked');
     last =  $j('#select_autoship input:checkbox:last').attr('checked');
     
     if(id == 1){
         if(first){
            $j('#select_autoship input:checkbox:last').attr('checked',false);
         }else{
            $j('#select_autoship input:checkbox:first').attr('checked',true);
         }
     }
     if(id == 2){
         if(last){
            $j('#select_autoship input:checkbox:first').attr('checked',false);
         }else{
             $j('#select_autoship input:checkbox:last').attr('checked',true);
         }
     }

}
/*
function setproducttocart(siteType){
    //send cart only prods witn  quantity more that 0 
    $j('#tmp').html('');
    $j('input:text[name^="products"]').each(function () {
        var quantity = $j(this).val();
        if (quantity>0){
            $j("#tmp").append('<input type="hidden" value="'+quantity+'"  name="'+$j(this).attr('name')+'" >');
            var hidden_id = $j(this).attr('id') + '_article_number';
            var hidden_article_number = $j('#'+hidden_id).val();
            var hidden_name = $j('#'+hidden_id).attr('name');
            $j("#tmp").append('<input type="hidden" value="'+hidden_article_number+'"  name="'+hidden_name+'" >');
            
            
            
        }        
    });
    popupFlashAddToCart(siteType, 'tmp');
    
    
    //$j('#tmp').submit();


}
*/


function setproducttocart(siteType,gotoorder){
/* send cart only prods witn  quantity more that 0 */
    if(typeof(gotoorder) == 'undefined'){
        gotoorder = 0;
    }
    $j('#tmp').html('');
    $j('#tmp').css('display','none');
    $j('input:text[name^="products"]').each(function () {
        var quantity = $j(this).val();
        
        var inputname = $j(this).attr('name');
        if (quantity > 0 && ! /set/.test(inputname)){
                          

            $j(this).clone().val(quantity).appendTo("#tmp");//copy input with quantity
            var product_id = $j(this).attr('id').replace("_quantity","").replace("product_","");//get product_id from input with type text
            
            var val_select = -1;
            if( $j("input:hidden").is("#products_"+product_id+"_article_number") ){//quickoreder page. 
            
                var hidden_id = $j("#products_"+product_id+"_article_number").attr('id');
                
            }else if( $j("input:hidden").is("#product_"+product_id+"_article_number") ){//other page
                
                var hidden_id = $j("#product_"+product_id+"_article_number").attr('id');
                
            }else if( $j("select").is("#products_"+product_id+"_article_number") ){//other page
                
                var hidden_id = $j("#products_"+product_id+"_article_number").attr('id');
                var val_select = $j("#products_"+product_id+"_article_number :selected").val();               
            }
            
            $j($j('#'+hidden_id)).clone().val($j('#'+hidden_id).val()).appendTo("#tmp");//copy input with article_number
            if(val_select != -1){
                $j('#tmp #'+hidden_id).empty();
                $j('#tmp #'+hidden_id).prepend( $j('<option value="'+val_select+'">val</option>'));
            }
            
            ////////////////FOR XXS PRODUCT, CLONE ALL INPUTS IN XSS BLOCK////////////////
            if( $j("div").is("#products_set_block_"+product_id) ){
                
                $j('#products_set_block_'+product_id +' input').each(function (indx, element) {
                    $j(element).clone().appendTo("#tmp");
                   
                });
            
            }else if( $j("table").is(".product_set") ){
               
                $j('table.product_set input').each(function (indx, element) {
                    $j(element).clone().appendTo("#tmp");
                   
                });
            }
            /////////////////////END XXS PRODUCT BLOCK/////////////////////
            
        }//end if quantity
        
                
    });//ned each
    
    popupFlashAddToCart(siteType, 'tmp',gotoorder);
}





function clearCart(siteType){
            $j.getJSON('?action=ajax.addToCart',{},
                    function(data,textSatus){
                        if(siteType == 1){
                            $j('#shopping_cart_total').html(data);
                        }else{
                            $j("#cart").html(data);
                        }
                    }
                );
}


 function popupFlashAddToCart(siteType, form_id,gotoorder){
        if(typeof(form_id) == 'undefined'){
            var form_id = 'frm'; 
        }
        
        
        aData = $j('#'+form_id).serialize();
        if(siteType == 16){
            $j('#beautifulloader').beautifulloader({isvisible:1,positionTop:'50%',positionLeft:'430px'});
        }else{
            $j('.progress_16').css('visibility','visible');    
        }
        
        $j.getJSON('?action=ajax.addToCart',aData,
                    function(data,textSatus){
                        if(siteType == 1){
                            $j('#shopping_cart_total').html(data);
                        }else{
                            $j("#cart").html(data);
                        }
                        
                        $j(".flash_product_block input[type=text]").val(0);
                        if (form_id !='frm'){
                            //set 0 as quantity for products on page
                            $j('input:text[name^="products"]').each(function () {                                   
                                    if ($j(this).val()>0){
                                        $j(this).val(0);                    
                                    }        
                                });                        
                        } 
                        
                                if(siteType == 16){
                                    $j('#beautifulloader').beautifulloader({isvisible:0});
                                }else{
                                    $j('.progress_16').css('visibility','hidden');    
                                }
                        if(gotoorder != 0){
                            window.location = gotoorder;
                        }else{
                            
                            visibleControl();    
                        
                        }
                        
                    }
                );
}



function visibleControl(){
   if( $j('#popup_controls').dialog('isOpen') == 1){
        return;
   }
   OpenPopupControls();
}

function hiddenControl(){
    $j('#popup_controls').dialog("destroy");
}




function  OpenPopupControls(){
    $j('#popup_controls').dialog({ resizable: false,position: [5,5],zIndex : 2000});
    $j('#popup_controls').bind('dialogclose', function(event, ui) {
        $j(this).dialog("destroy");
    });
    $j("#popup_controls").dialog('option', 'title', '');
    $j("#popup_controls").dialog('option', 'width', 280);
    $j("#popup_controls").dialog();
}

function  open_recommend(title){
    
        $j('#sport_recommend').dialog({ resizable: false,position: [100,50]});
        $j('#sport_recommend').bind('dialogclose', function(event, ui) {
            $j(this).dialog("destroy");
        });
        $j("#sport_recommend").dialog('option', 'title', title);
        $j("#sport_recommend").dialog('option', 'width', 590);
        $j(".ui-widget-header").css('background',' #C83246');
        $j(".ui-widget-header").css('color','#ffffff');
        //$j(".ui-dialog-titlebar-close span").addClass('sport_recommed_popup_cross');
      
        $j("#sport_recommend").dialog();
}
function send_recommend(){
            $j('#sport_recommend .loader').css('visibility','visible');
            data = $j('#recommend').serialize();
            $j.getJSON('?action=ajax.recommend',data,
                          function (data){
                                if(data.error == 1){
                                    if(typeof(data.empty_fields) != 'undefined'){
                                        $j('#empty_fields').css('display','');
                                    }
                                    if(typeof(data.to_email_not_valid) != 'undefined'){
                                        $j('#to_email_not_valid').css('display','');
                                    }
                                    if(typeof(data.from_email_not_valid) != 'undefined'){
                                        $j('#from_email_not_valid').css('display','');
                                    }
                                }else{
                                    $j('#sport_recommend').dialog("destroy");
                                    open_recommend_send();
                                }
                               $j('#sport_recommend .loader').css('visibility','hidden');
                          }
            );
}

function  open_recommend_send(){
    
        $j('#sport_recommend_send').dialog({ resizable: false,position: [200,150]});
        $j('#sport_recommend_send').bind('dialogclose', function(event, ui) {
            $j(this).dialog("destroy");
        });
        $j("#sport_recommend_send").dialog('option', 'title', '');
        $j("#sport_recommend_send").dialog('option', 'width', 300);
        $j(".ui-widget-header").css('background',' #C83246');
        $j(".ui-widget-header").css('color','#ffffff');
        //$j(".ui-dialog-titlebar-close span").addClass('sport_recommed_popup_cross');
      
        $j("#sport_recommend_send").dialog();
}




