 


function isNumber( value )
{
    var fieldValueInt = parseInt (value);
    var fieldValueFloat = parseFloat (value);
    if(value == fieldValueInt || value == fieldValueFloat ){
        return true;
    }else{
        return false;
    }
}


function echeck(str){
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

   if(reg.test(str) == false) {
      return false;
   }
   return true;

}
function echeck2(str) {


		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   
		    return false
		 }

		 if (str.indexOf(" ")!=-1){
		   
		    return false
		 }

 		 return true
	}
    
    function textCounter( field, countfield, maxlimit ) {
      if ( field.value.length > maxlimit )
      {
        field.value = field.value.substring( 0, maxlimit );
        //alert( 'Го поминавте бројот на дозволени карактери.' );
        return false;
      }
      else
      {
        countfield.value = maxlimit - field.value.length;
      }
    }

    function redirect(where)
    {
        window.location = where;
    }

    function getHelpIcon(name)
    {
        var helpIcon = ' <span>';
    helpIcon +="<a name='helper' title='"+name+"' href='#'><img width='16px' height='16px' src='/images/help.png'/></a>";
    helpIcon +='  </span>';
    return helpIcon;
    }

    function replaceall(find,replacechar,originalString){
	for (i=0;i<originalString.length;i++){
		originalString=originalString.replace(find,replacechar);
	}
	return originalString;
}

function initializeCheckBoxFields(opt1, opt2, opt3)
{
   var checkboxOptions = '<select id="checkbox_select">';
   checkboxOptions += '<option value=0>'+opt1+'</option>'
   checkboxOptions += '<option value=1>'+opt2+'</option>'
   checkboxOptions += '<option value=2>'+opt3+'</option>'
   checkboxOptions += '</select>'
   $(".subtitulo:last").append(checkboxOptions);
   $('#checkbox_select').change(function(){
       if($('#checkbox_select').val() == 1){
           $("input[name=number]").attr('checked', true);
       }
       if($('#checkbox_select').val() == 2){
            $("input[name=number]").attr('checked', false);
       }
   });

}

function wordwrap( str, int_width, str_break, cut ) {
   
    var m = ((arguments.length >= 2) ? arguments[1] : 75   );
    var b = ((arguments.length >= 3) ? arguments[2] : "\n" );
    var c = ((arguments.length >= 4) ? arguments[3] : false);

    var i, j, l, s, r;

    str += '';

    if (m < 1) {
        return str;
    }

    for (i = -1, l = (r = str.split(/\r\n|\n|\r/)).length; ++i < l; r[i] += s) {
        for(s = r[i], r[i] = ""; s.length > m; r[i] += s.slice(0, j) + ((s = s.slice(j)).length ? b : "")){
            j = c == 2 || (j = s.slice(0, m + 1).match(/\S*(\s)?$/))[1] ? m : j.input.length - j[0].length || c == 1 && m || j.input.length + (j = s.slice(m).match(/^\S*/)).input.length;
        }
    }

    return r.join("\n");
}

function showLang(lang)
{
    $("#"+lang+"_page").val(1);
    $("div[name=lang]").hide();
    $("#"+lang).show();
}

function popitup(url) {
	newwindow=window.open(url,"name","location=1,status=1,scrollbars=1,width=800,height=600,screenX=400,screenY=400");
	//newwindow.moveTo(0,0);
	if (window.focus) {newwindow.focus()}
	return false;
}

function showMethod(id, storeId)
{
    url = '/shipping_info/index/'+id+'/'+storeId;
    newwindow=window.open(url,"name","location=1,status=1,scrollbars=1,width=800,height=600,screenX=400,screenY=400");
    if (window.focus) {newwindow.focus()}
	//return false;
}

function loadProgress() {

         var html = '<div id="fancy_overlay_1" class="progress" style="opacity: 0.3; display: block;">';
         html += '<img id="progress_image"  width="40px" height="40px" style="margin-top:300px;padding-left:5px;padding-top:5px;" src="/images/icon-loading-animated_04.gif" alt="" />';
         html += '</div>';
         $(html).appendTo("body");
    }

function hideProgress()
{
    $("#fancy_overlay_1").remove();
}



function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   }
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function expandCategories(id)
{

    if(id){
        var elid = id;
    }else{
        var elid = 1;
    }
             $("#ygtvc"+elid+" .ygtvlabel").each(function(){
                var id = $(this).attr('id');
                var ids = id.split('ygtvlabelel');
              
                if($("#ygtvc"+ids[1]).css('display') == 'none' ){

                      //YAHOO.widget.TreeView.getNode('taskTreeView' , 2).toggle();
                      YAHOO.widget.TreeView.getNode('taskTreeView' , ids[1]).toggle();

                      var checked = $("#ygtv"+ids[1]+" .ygtvcheck2");
                      
                      if( checked.length == 0 ){
                            YAHOO.widget.TreeView.getNode('taskTreeView' , ids[1]).toggle();
                      }
                }

                if($("#ygtvc"+ids[1]).hasClass('ygtvchildren')){
                    expandCategories(ids[1]);
                }

                


                
             })
}






function printSelection(node,notincludeCss){

  var content=node.innerHTML
  var pwin=window.open('','print_content','width=100,height=100');

  pwin.document.open();

  var html = '';
  if(!notincludeCss)
  {    html += '<link rel="stylesheet" href="/css/blueprint/screen.css" type="text/css" media="screen, projection"/>';
      html += '<link rel="stylesheet" href="/css/blueprint/print.css" type="text/css" media="print"/>';
      html += '<link rel="stylesheet" href="/css/mycustom.css" type="text/css" media="print" />';

      html +='<style type="text/css" media="print">';


    //  html +='#'+node+'{';
    //  html +='size: landscape;';
    //  html +='margin: 2cm;}';



      html += '@page port {size: portrait;}';
      html += '@page land {size: landscape;}';

      html += '.portrait {page: port;}';

      html += '.landscape {page: land;}';

      html += '</style>';
   }
  pwin.document.write('<html><head>'+html+'</head><body onload="window.print()">'+content+'</body></html>');

  
  //pwin.document.write('<html><body onload="window.print()">'+content+'</body></html>');
  pwin.document.close();

  setTimeout(function(){pwin.close();},1000);

}


function printPublicSelection(node,notincludeCss){

  var content=node.innerHTML
  var pwin=window.open('','print_content','width=100,height=100');

  pwin.document.open();

  var html = '';
  if(!notincludeCss)
  {    html += '<link rel="stylesheet" href="/css/public/tabs.css" type="text/css" />';
       html +='  <link rel="stylesheet" href="/css/jquery.tooltip.css" type="text/css"/>';

       html +='  <link rel="stylesheet" href="/css/yui-grids/reset-fonts-grids.css" type="text/css" media="screen, projection"/>';
       html +='  <link rel="stylesheet" href="/css/yui-grids/grids-min.css" type="text/css" media="screen, projection"/>';
       html +='  <link rel="stylesheet" href="/css/public/main.css" type="text/css" media="screen, projection"/>';
       html +='  <link rel="stylesheet" href="/css/public/main_menu.css" type="text/css" media="screen, projection"/>';

      html +='<style type="text/css" media="print">';


    //  html +='#'+node+'{';
    //  html +='size: landscape;';
    //  html +='margin: 2cm;}';



      html += '@page port {size: portrait;}';
      html += '@page land {size: landscape;}';

      html += '.portrait {page: port;}';

      html += '.landscape {page: land;}';

      html += '</style>';
   }
  pwin.document.write('<html><head>'+html+'</head><body onload="window.print()">'+content+'</body></html>');


  //pwin.document.write('<html><body onload="window.print()">'+content+'</body></html>');
  pwin.document.close();

  setTimeout(function(){pwin.close();},1000);

}

 function mathCapchaFristNum()
 {

       return    Math.floor(Math.random()*11);
  }

 function mathCapchaSecountNum()
  {

        return     Math.floor(Math.random()*11);
  }

 function mathCapchaOperator()
  {
      var operators = new Array("+","-","x");
      var index = Math.floor(Math.random()*3);
      return   operators[index];
  }

   function mathCapchaOperation(operationString)
    {
           var operators = operationString.split(" ");
           var num1 = Number(operators[0]);
           var num2 = Number(operators[2]);

          switch(operators[1])
          {
              case '+':
                  return num1+num2
                  break;
              case '-':
                  return num1-num2
                  break;

              case 'x':
                  return num1*num2
                  break;

              default: return 0;

          }
   }

   function createCaptcha(captchaContainer, result){

       $(captchaContainer).text(mathCapchaFristNum()+' '+mathCapchaOperator()+' '+mathCapchaSecountNum());
       $(result).val(mathCapchaOperation($(captchaContainer).text()));
   }




 
/*
 * js/hoverintent.js
 **/

(function($){
	/* hoverIntent by Brian Cherne */
	$.fn.hoverIntent = function(f,g) {
		// default configuration options
		var cfg = {
			sensitivity: 7,
			interval: 100,
			timeout: 0
		};
		// override configuration options with user supplied object
		cfg = $.extend(cfg, g ? { over: f, out: g } : f );

		// instantiate variables
		// cX, cY = current X and Y position of mouse, updated by mousemove event
		// pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
		var cX, cY, pX, pY;

		// A private function for getting mouse position
		var track = function(ev) {
			cX = ev.pageX;
			cY = ev.pageY;
		};

		// A private function for comparing current and previous mouse position
		var compare = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			// compare mouse positions to see if they've crossed the threshold
			if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
				$(ob).unbind("mousemove",track);
				// set hoverIntent state to true (so mouseOut can be called)
				ob.hoverIntent_s = 1;
				return cfg.over.apply(ob,[ev]);
			} else {
				// set previous coordinates for next time
				pX = cX; pY = cY;
				// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
				ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
			}
		};

		// A private function for delaying the mouseOut function
		var delay = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			ob.hoverIntent_s = 0;
			return cfg.out.apply(ob,[ev]);
		};

		// A private function for handling mouse 'hovering'
		var handleHover = function(e) {
			// next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
			var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
			while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
			if ( p == this ) { return false; }

			// copy objects to be passed into t (required for event object to be passed in IE)
			var ev = jQuery.extend({},e);
			var ob = this;

			// cancel hoverIntent timer if it exists
			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }

			// else e.type == "onmouseover"
			if (e.type == "mouseover") {
				// set "previous" X and Y position based on initial entry point
				pX = ev.pageX; pY = ev.pageY;
				// update "current" X and Y position based on mousemove
				$(ob).bind("mousemove",track);
				// start polling interval (self-calling timeout) to compare mouse coordinates over time
				if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}

			// else e.type == "onmouseout"
			} else {
				// unbind expensive mousemove event
				$(ob).unbind("mousemove",track);
				// if hoverIntent state is true, then call the mouseOut function after the specified delay
				if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
			}
		};

		// bind the function to the two event listeners
		return this.mouseover(handleHover).mouseout(handleHover);
	};

})(jQuery);



/**
 * /js/superfish.js
 */


/*
 * Superfish v1.4.8 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */

;(function($){
	$.fn.superfish = function(op){

		var sf = $.fn.superfish,
			c = sf.c,
			//$arrow = $(['<span class="',c.arrowClass,'"> </span>'].join('')),
			over = function(){
				var $$ = $(this), menu = getMenu($$);
				clearTimeout(menu.sfTimer);
				$$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var $$ = $(this), menu = getMenu($$), o = sf.op;
				clearTimeout(menu.sfTimer);
				menu.sfTimer=setTimeout(function(){
					o.retainPath=($.inArray($$[0],o.$path)>-1);
					$$.hideSuperfishUl();
					if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
				},o.delay);
			},
			getMenu = function($menu){
				var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
				sf.op = sf.o[menu.serial];
				return menu;
			};
			//addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };

		return this.each(function() {
			var s = this.serial = sf.o.length;
			var o = $.extend({},sf.defaults,op);
			o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
				$(this).addClass([o.hoverClass,c.bcClass].join(' '))
					.filter('li:has(ul)').removeClass(o.pathClass);
			});
			sf.o[s] = sf.op = o;

			$('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {

			})
			.not('.'+c.bcClass)
				.hideSuperfishUl();

			var $a = $('a',this);
			$a.each(function(i){
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
			});
			o.onInit.call(this);

		}).each(function() {
			var menuClasses = [c.menuClass];
			if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
			$(this).addClass(menuClasses.join(' '));
		});
	};

	var sf = $.fn.superfish;
	sf.o = [];
	sf.op = {};
	sf.IE7fix = function(){
		var o = sf.op;
		if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
			this.toggleClass(sf.c.shadowClass+'-off');
		};
	sf.c = {
		bcClass     : 'sf-breadcrumb',
		menuClass   : 'sf-js-enabled',
		anchorClass : 'sf-with-ul',
		arrowClass  : 'sf-sub-indicator',
		shadowClass : 'sf-shadow'
	};
	sf.defaults = {
		hoverClass	: 'sfHover',
		pathClass	: 'overideThisToUse',
		pathLevels	: 1,
		delay		: 800,
		animation	: {opacity:'show'},
		speed		: 'normal',
		autoArrows	: true,
		dropShadows : true,
		disableHI	: false,		// true disables hoverIntent detection
		onInit		: function(){}, // callback functions
		onBeforeShow: function(){},
		onShow		: function(){},
		onHide		: function(){}
	};
	$.fn.extend({
		hideSuperfishUl : function(){
			var o = sf.op,
				not = (o.retainPath===true) ? o.$path : '';
			o.retainPath = false;
			var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility','hidden');
			o.onHide.call($ul);
			return this;
		},
		showSuperfishUl : function(){
			var o = sf.op,
				sh = sf.c.shadowClass+'-off',
				$ul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility','visible');
			sf.IE7fix.call($ul);
			o.onBeforeShow.call($ul);
			$ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
			return this;
		}
	});

})(jQuery);

//======================================
