﻿//////////////////////////////////////////////////////////////////
var detect = 
    navigator.userAgent.toLowerCase();
var isIe = (detect.indexOf('msie')>-1);
//////////////////////////////////////////////////////////////////

function fnover()
{
    event.srcElement.style.color="#be0030"
}

function fnout()
{
    event.srcElement.style.color="#3f3f3f"
    
}


function fnoverbg(obj)
{
	obj.style.background="url('/Supersol/Images/he/Big/left_menu_bg_over.gif')"
	obj.style.backgroundRepeat="repeat"
}

function fnoutbg(obj)
{
	obj.style.background="url('/Supersol/Images/he/Big/left_menu_bg.gif')"
	obj.style.backgroundRepeat="repeat"
}

function customWindowOpen(strUrl, strWindow, strParams, iWidth, iHeight)
{
	try
	{
		var iLeft, iTop;
		iLeft = (window.screen.width - iWidth) / 2;
		iTop = (window.screen.height - iHeight) / 2;
		if (strParams == '')
		{
		    strParams = "width=" + iWidth.toString() + ",height=" + iHeight.toString() + ",left=" + iLeft.toString() + ",top=" + iTop.toString();
		}
		else
		{
		    strParams = strParams + ",width=" + iWidth.toString() + ",height=" + iHeight.toString() + ",left=" + iLeft.toString() + ",top=" + iTop.toString();
		}
		    
		//alert(strUrl);
		window.open(strUrl, strWindow, strParams);
	}
	catch (e) 
	{ 	
	} 
}
function SChildPgVal(objLink)
{
    try
    {             
        obj = 
            GetParentTbl(objLink).firstChild.lastChild.firstChild.firstChild;       
        obj.value = objLink.name;                              
    }
    catch (e) { }
}

function SPgVal(objLink)
{
    try
    {             
        obj = 
            GetParentTbl(objLink)
        obj = 
            GetParentTbl(obj.parentElement).firstChild.lastChild.firstChild.firstChild;       
        obj.value = objLink.name;                              
    }
    catch (e) { }
}
function GetParentTbl(obj)
{
    if(obj.tagName == 'TABLE')
        return obj;
    else
        if(isIe)    
            return GetParentTbl(obj.parentElement);
        else
            return GetParentTbl(obj.parentNode);
}

function PrintVersion(id)
{
	var HTML = "<HTML>";
	obj = 
		document.getElementsByTagName('HEAD')[0];			
	HTML += obj.outerHTML;
	obj = 
		document.getElementsByTagName('BODY')[0];				
	HTML += "<BODY onload='window.print()' dir='" +obj.dir+"' >";		
	obj = document.getElementById(id);
	HTML += obj.outerHTML;
	HTML += "</BODY></HTML>";	
	OpenPrintVersion(HTML,'Supersol');
}

function OpenPrintVersion(HTML,WindowName)
{		
	myWindow = window.open("", "WindowName", 'scrollbars=1,width=900,height=600');
	myWindow.document.write(HTML);	
	myWindow.document.close(); 	
}

function SetHeightDIV()
{
    objDiv = document.getElementById('HeightDIV');
    objDivPos = document.getElementById('HeightDIVPos');    
    var Height = 555;
    if(objDiv.offsetTop < Height)
    {       
        objDivPos.style.height += Height - objDiv.offsetTop;      
    }    
}

function OnlyNum()
{
    if(!((event.keyCode >=96 && event.keyCode <= 105) ||
       (event.keyCode >=48 && event.keyCode <= 57) ||
        event.keyCode == 46 || event.keyCode == 8 ||
        event.keyCode == 9))
        {
            event.returnValue = false
        }
}
function SubmitLogin(obj,idToClick)
{
      try
    {
        if(event.keyCode == 13)
        {             
            var btnLogin =  document.getElementById(idToClick);
            btnLogin.click();      
        }
    }
    catch(e){}
}
function SubmitSearch(obj)
{
    try
    {
        if(event.keyCode == 13)
        {             
            if(obj.value == '' || obj.value == "" || obj.value.length < 2)
            {
                return false;
            }
            objTdTxt = obj.parentElement;
            objTdLink = objTdTxt.nextSibling.nextSibling;                        
            objTdLink.firstChild.click();        
        }
    }
    catch(e){}
}


function CheckValue(objLink)
{
    try
    {
        objTdLink = objLink.parentElement;
        objTdTxt = objTdLink.previousSibling.previousSibling;
        objTxt = objTdTxt.firstChild;
        if(objTxt.value == '' || objTxt.value == "")
            return false;     
        return true;    
    }
     catch(e){}
}

function ReplaceSearchImg()
{    
    try
    {                      
        switch (event.type)
        {            
            case 'mouseover':                           
                event.srcElement.src = IMG_FOLDER + 'Cuts/button_over.gif';
                break;        
            case 'mouseout':
                event.srcElement.src = IMG_FOLDER + 'Cuts/button.gif';
                break;        
        }
    }
    catch(e){}
}

function TransferData(Src,Dst)
{
    try
    {       
        Dst.value = Src.value;
    }
    catch(e){}
}

function ClientIDValidate(idnumber)
{
	var strID     = idnumber.toString();
	var leng      = strID.length;

    if( (leng < 9) && (leng >= 5))  // checking for leading zero 
	{
		var addNull = 9 - leng;
		var addn    = "0";

		for( i = 1; i <= (addNull-1); i++ )
			addn += "0";

		strID = addn + idnumber;
		leng  = 9;
	}
	else if (leng < 5)
	{
	    return false;
	}
	//****** Algorithm CheckID Number *******************************
	var sum       = 0; 
	var mul       = 1;
	var result;
	var sum2;

	for( var i = 0; i <= (leng - 2); i++ )
	{
		sum2 = mul * Number( strID.substr(i,1) );
		if( sum2 > 9 )
			sum2 -= 9;
	
		sum += sum2;
		mul = 3 - mul;
	}

	sum = sum % 10;

	var result = 10 - sum;
	if( result == 10 )
		result = 0;

	if( Number( strID.substr(i,1) ) != result )
	{
		//alert( "Examination ( last ) digit is not compatible to Login Name ( ID )." );
		return false;
	}

	//ID passed successfuly
	return true;
}

function LoadLoader()
{

    var divLoader = document.getElementById('LoaderDiv');
    var Left = document.body.offsetWidth -290;
    var TopP = 200;
    var img = document.getElementById('imgLoader');
    
    if (divLoader.style.MozOpacity!=null) {  		
			divLoader.style.MozOpacity = 0;
		} else if (divLoader.style.opacity!=null) {			
			divLoader.style.opacity = 0;
		} else if (divLoader.style.filter!=null) {			
			divLoader.style.filter = "alpha(opacity=0)";
		}		
		 
    divLoader.style.left = Left/2;        
    TopP = document.body.scrollTop + 216; 
    divLoader.style.top = TopP;
    divLoader.style.display = 'block';
    window.setTimeout("SetOpacity(0)", 250);
}

function SetOpacity(opacity)
{
    var divLoader = document.getElementById('LoaderDiv');
    var img = document.getElementById('imgLoader');
    if (divLoader) 
    {
		if (opacity <= 95) 
		{
			if (divLoader.style.MozOpacity!=null) 
			{				
				divLoader.style.MozOpacity = (opacity/100)-.001;				
			} 
			else if (divLoader.style.opacity!=null) 
			{				
				divLoader.style.opacity = (opacity/100)-.001;
			} 
			else if (divLoader.style.filter!=null) 
			{				
				divLoader.style.filter = "alpha(opacity="+opacity+")";				
			}
			opacity += 10;
			img.src = '/Supersol/Images/Common/loader.gif';
			window.setTimeout("SetOpacity("+opacity+")", 5);
			
		}
	}
}
function PrintPicture(id)
{
    try
    {
        var html = "<html><body>"
        var _tdMainCoupon = document.getElementById(id);
        var htmlString = _tdMainCoupon.outerHTML;                        
        html += htmlString;
        html += "</body></html>"        
        poponload(htmlString);                        
    }
    catch(e)
    {
        var msg = 'הדפסה נכשלה';
        alert(msg);
    }
}

function poponload(html)
{
    picWin = window.open("", "PrintPictureNotVisible", "scrollbars=no,resizable=no,width=0,height=0,top=9999,left=9999"); 
    picWin.document.body.innerHTML = html;
    picWin.document.body.style.direction = 'rtl';
    picWin.print();                                              
    picWin.close();
}