﻿function jsfPIWC(path, wndWidth, wndHeight) // Popup Image Window Centered
{
    var wndLeft = ( screen.width - wndWidth ) / 2;
    var wndTop = ( screen.height - wndHeight ) / 2;
    win = window.open("PopupImage.aspx?path="+path, "", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no," +
	    "resizable=no,copyhistory=no,width=" + wndWidth +",height=" + wndHeight + ",top=" + wndTop + ",left=" + wndLeft, true);
    win.focus();
}
//-----------------------------------------------------------------------------------------------------------------------------------
function jsfPWC(url, width, height) // Popup Window Centered
{
    var left = ( screen.width - width ) / 2;
    var top = ( screen.height - height ) / 2;
    win = window.open(url, "", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=" + width +",height=" + height + ",top=" + top + ",left=" + left, true);
    win.focus();
}

function jsfOWC( wndUrl, wndWidth, wndHeight, wndScrollbar, wndMenubar ) // Open Window Centered
{
	var wndLeft = ( screen.width - wndWidth ) / 2;
	var wndTop = ( screen.height - wndHeight ) / 2;
	win = window.open( wndUrl,"","toolbar=no,location=no,directories=no,status=no,menubar=" + wndMenubar + ",scrollbars=" + wndScrollbar +
		",resizable=no,copyhistory=no,width=" + wndWidth +",height=" + wndHeight + ",top=" + wndTop + ",left=" + wndLeft  );

	win.focus();
}            
//-----------------------------------------------------------------------------------------------------------------------------------
function jsfH(id) // Hide
{
	if(null != ( e = document.getElementById(id)))
		e.style.display = 'none' ;
}
function jsfS(id) // Show
{
	if(null != ( e = document.getElementById(id)))
		e.style.display = 'block' ;
}
function jsfB(id) // Hide
{
	if( null != ( o = document.getElementById(id)))
		o.style.display = ( o.style.display == 'none' ) ? '':'none' ;
}

function jsfSHM(id) // Show Hide Menu
{
	if( null != ( o = document.getElementById(id)))
		o.style.display = ( o.style.display == 'none' ) ? '':'none' ;
}
//-----------------------------------------------------------------------------------------------------------------------------------

function jsfSH(id)
{
	if( null != ( o = document.getElementById(id)))
		o.style.display = ( o.style.display == 'none' ) ? '':'none' ;
}
function jsfTrim(s)
{
  s = this != window ? this : s;

  return s.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
function jsfEnter(e)
{
    e = e || window.event;
   
    var code = e.keyCode || e.which;
    
    return code == 13 ? true : false;
}
function jsfNum(e)
{
    if(!e) {
        //if the browser did not pass the event 
        //information to the function, 
        //we will have to obtain it from the 
        //event register
        if (window.event) { //Internet Explorer
            e = window.event;
        }
        else { //total failure, we have no way of referencing the event
            return false;
        }
    }
    
    if(e.shiftKey) { //for digits
        return false;
    }
    if (typeof(e.keyCode) == 'number') { //DOM
      e = e.keyCode;
    } else if (typeof(e.which) == 'number') { //NS 4 compatible
      e = e.which;
    } else if (typeof(e.charCode) == 'number') { //also NS 6+, Mozilla 0.9+
      e = e.charCode;
    } else { //total failure, we have no way of obtaining the key code
      return false;
    }    

    if (e != 0) {
        return (
            (e <= 105 && e >= 96) ||
            (e <= 57 && e >= 48) ||
            (e == 109) ||
            (e == 8) ||
            (e == 9) ||
            (e == 27) ||
            (e == 46)) ? true : false;
    }
    
    return false;
}
function jsfPassportError(idNum)
{
	while ( idNum.length < 9 )
		idNum = "0" + idNum ;

	idNum1 = idNum.substr(0,1) * 1;
	idNum2 = idNum.substr(1,1) * 2;
	idNum3 = idNum.substr(2,1) * 1;
	idNum4 = idNum.substr(3,1) * 2;
	idNum5 = idNum.substr(4,1) * 1;
	idNum6 = idNum.substr(5,1) * 2;
	idNum7 = idNum.substr(6,1) * 1;
	idNum8 = idNum.substr(7,1) * 2;
	idNum9 = idNum.substr(8,1) * 1;

	if( idNum1 > 9 ) idNum1 = (idNum1%10) + 1;
	if( idNum2 > 9 ) idNum2 = (idNum2%10) + 1;
	if( idNum3 > 9 ) idNum3 = (idNum3%10) + 1;
	if( idNum4 > 9 ) idNum4 = (idNum4%10) + 1;
	if( idNum5 > 9 ) idNum5 = (idNum5%10) + 1;
	if( idNum6 > 9 ) idNum6 = (idNum6%10) + 1;
	if( idNum7 > 9 ) idNum7 = (idNum7%10) + 1;
	if( idNum8 > 9 ) idNum8 = (idNum8%10) + 1;
	if( idNum9 > 9 ) idNum9 = (idNum9%10) + 1;

	var sumVal = idNum1 + idNum2 + idNum3 + idNum4 + idNum5 + idNum6 + idNum7 + idNum8 + idNum9;
	sumVal = sumVal % 10;

	return ( sumVal > 0 ) ? true:false ;
}
function jsfCreditCardError(cardNumber)
{
    var cardTotal = 0;
    var dnum = 0;
    var test = 0;

    if (cardNumber.length >= 13 )
    {
        for (i = cardNumber.length; i >= 1 ;  i--)
        {
            test = test + 1;
            
            num = cardNumber.charAt(i - 1);
            
            if ((test % 2) != 0)
            {
                cardTotal = cardTotal + parseInt(num);
            }
            else
            {
                dnum = parseInt(num) * 2;
                
                if (dnum >= 10)
                {
                    cardTotal = cardTotal + 1 + dnum - 10;
                }
                else
                {
                    cardTotal = cardTotal + dnum;
                }
            }
        }
        
        return ((cardTotal % 10) != 0) ? true : false;
    }

    return true;
}
function jsfBgE(e)
{
    e.style.backgroundColor = '#faa';
}
function jsfBgC(a)
{
    for(i=0; i < a.length; i++)
        if(null != (e = $get(a[i])))
            e.style.backgroundColor = '#fff';
}

function jsfCalcQuickBuyOffset()
{
    if(null!=(eQuickBuy = $get('divQuickBuy')))
    {
//        alert(
//            'getScrollHeight:'+getScrollHeight()+'\n'+
//            'jsfGetClientHeight:'+jsfGetClientHeight()+'\n'+
//            'eQuickBuy.clientHeight:'+eQuickBuy.clientHeight);

        eQuickBuy.style.top = 
            (getScrollHeight() + jsfGetClientHeight()/2 - eQuickBuy.clientHeight/2) +
            'px';
            
//        alert(
//            'getScrollWidth:'+getScrollWidth()+'\n'+
//            'jsfGetClientWidth:'+jsfGetClientWidth()+'\n'+
//            'eQuickBuy.clientWidth:'+eQuickBuy.clientWidth);
            
        eQuickBuy.style.left = 
            (getScrollWidth() + jsfGetClientWidth()/2 - eQuickBuy.clientWidth/2) +
            'px';
    }
}
function jsfCalcQuickProductPictureOffset()
{
    if(null!=(e = $get('divQuickProductPicture')))
    {
//        alert(
//            'getScrollHeight:'+getScrollHeight()+'\n'+
//            'jsfGetClientHeight:'+jsfGetClientHeight()+'\n'+
//            'eQuickBuy.clientHeight:'+eQuickBuy.clientHeight);

        e.style.top = 
            (getScrollHeight() + jsfGetClientHeight()/2 - e.clientHeight/2) +
            'px';
            
//        alert(
//            'getScrollWidth:'+getScrollWidth()+'\n'+
//            'jsfGetClientWidth:'+jsfGetClientWidth()+'\n'+
//            'eQuickBuy.clientWidth:'+eQuickBuy.clientWidth);
            
        e.style.left = 
            (getScrollWidth() + jsfGetClientWidth()/2 - e.clientWidth/2) +
            'px';
    }
}
function getScrollWidth()
{
   var w = window.pageXOffset ||
           document.body.scrollLeft ||
           document.documentElement.scrollLeft;
           
   return w ? w : 0;
} 
function getScrollHeight()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
           
   return h ? h : 0;
}
function jsfGetClientWidth()
{
    return document.compatMode == 'CSS1Compat' && !window.opera ?
        document.documentElement.clientWidth :
        document.body.clientWidth;
}
function jsfGetClientHeight()
{
    return document.compatMode == 'CSS1Compat' && !window.opera ?
        document.documentElement.clientHeight :
        document.body.clientHeight;
} 
function jsfQuickBuyErrors(idColor, idSize)
{
    var msg = '';
    
    if(msg == '') {
        if((null != (e = $get(idColor))) && (e.selectedIndex == 0)) {
            msg = '.בחר צבע'; }}

    if(msg == '') {
        if((null != (e = $get(idSize))) && (e.selectedIndex == 0)) {
            msg = '.בחר מידה'; }}
    
    if(msg == '')
    {
        jsfH('divQuickBuy');
        
        return true; 
    }

    alert(msg);
    
    return false;
}

function jsfSIM( array, o, i ) // Set Image Source
{
	o.src = array[i].src ;
}

function jslfShipmentErrors()
{
	var sMsg = '' ;

    if(sMsg == '')
    {
        bShipmentChecked = false;
        
        if(null != ( a = document.getElementsByName('rbgShipment')))
        {
            for(i = 0 ; i < a.length; i++)
            {
                if(a[i].checked == true)
                {
                    bShipmentChecked = true;
                    break;
                }
            }
        }
        
        if(bShipmentChecked == false)
        {
            sMsg = '.לא נבחר סוג משלוח' ;
        }
    }
    
    return sMsg;
}

function jslfShipment()
{
	var sMsg = jslfShipmentErrors() ;

    if( sMsg.length > 0 )
    {
        alert( sMsg + "\n" + ".לא ניתן לעבור לקנייה" );
        
        return false;
    }

    return true;
}


