function HelpOpenClose(pId, pMax, pMin) 
{
    document.getElementById(pMax).style.display = 'none';
    document.getElementById(pMin).style.display = 'none';

    if (document.getElementById(pId).style.display == 'none') 
    {
        document.getElementById(pId).style.display = '';
        document.getElementById(pMin).style.display = '';
    }
    else 
    {
        document.getElementById(pId).style.display = 'none';
        document.getElementById(pMax).style.display = '';
    }
}


function ClickButton(pE, pId)
{
    var myEvent = pE ? pE : window.event;
    var myButton = document.getElementById(pId);

    if (myButton) 
    {
        if (myEvent.keyCode == 13) 
        {
            myButton.click();
            return false;
        }
    }
}  

function JumpTab(pTab,pHost) 
{
    document.getElementById("imgDetailDesc").src = "http://" + pHost + "/Img/A038_1000_1000_1/Detay-Aciklama.jpg";
    document.getElementById("imgDetailPict").src = "http://" + pHost + "/Img/A044_1000_1000_1/Detay-Resim.jpg";

    if (pTab == '0')
	{
		document.getElementById('divDetail').style.display = '';
		document.getElementById('divPicture').style.display = 'none';
		document.getElementById("imgDetailDesc").src = "http://" + pHost + "/Img/A037_1000_1000_1/Detay-Aciklama.jpg";
	}

	if (pTab == '1')
	{
		document.getElementById('divDetail').style.display = 'none';
		document.getElementById('divPicture').style.display = '';
		document.getElementById("imgDetailPict").src = "http://" + pHost + "/Img/A043_1000_1000_1/Detay-Resim.jpg";
	}
}

function onMouse(pThis,pColor)
{
	pThis.style.color = pColor;
}

function addCommas(pArea, nStr, nDecFormat) 
{
    e = window.event;

    if (e.keyCode == 9 || e.keyCode == 16) 
    {
        return false;
    }
    else 
    {
        if (nDecFormat.indexOf('.') != "-1") 
        {
            nDecSpl = nDecFormat.split('.')
            nDecFormat = nDecSpl[1].length - 1

            nStrLen = nStr.length;
            nStrLastChar = nStr.substring(nStrLen - 1, nStrLen);

            if (nStrLastChar == '0' || nStrLastChar == '1' || nStrLastChar == '2' || nStrLastChar == '3' || nStrLastChar == '4' || nStrLastChar == '5' || nStrLastChar == '6' || nStrLastChar == '7' || nStrLastChar == '8' || nStrLastChar == '9' || nStrLastChar == '-' || nStrLastChar == ',') 
            {
                if (nStrLastChar == '-' & nStrLen > 1) 
                {
                    nStr = nStr.substring(0, nStrLen - 1);
                }

                if (nStrLastChar == ',') 
                {
                    if (nStr.indexOf(',') < nStr.lastIndexOf(',')) 
                    {
                        nStr = nStr.substring(0, nStrLen - 1);
                    }
                }

                if (nStr.indexOf(',') == -1) 
                {
                    nNum = 1;
                    if (nStr.substring(0, 1) == '-') 
                    {
                        nNum = 2;
                    }

                    if (nStr.length > nNum & (nStr.substring(0, 1) == '0' || nStr.substring(0, 2) == '-0')) 
                    {
                        nStr = nStr.substring(0, nStrLen - 1);
                    }
                }
            }
            else 
            {
                nStr = nStr.substring(0, nStrLen - 1);
            }
            nStrLen = nStr.length;
            nNewStr = "";

            for (i = 0; i <= nStrLen - 1; i++) 
            {
                nStrChar = nStr.substring(i, i + 1);
                if (nStrChar == '0' || nStrChar == '1' || nStrChar == '2' || nStrChar == '3' || nStrChar == '4' || nStrChar == '5' || nStrChar == '6' || nStrChar == '7' || nStrChar == '8' || nStrChar == '9' || nStrChar == '-' || nStrChar == ',') 
                {
                    nNewStr += nStrChar;
                }
            }
            nStr = nNewStr;

            nSing = '';
            if (nStr.substring(0, 1) == '-') 
            {
                nSing = '-';
                nStr = nStr.substring(1, nStr.length);
            }

            x = nStr.split(',');
            x1 = x[0];
            x2 = x[1];
            if (x1 == null || x1 == '') 
            {
                if (nStr.indexOf(',') != -1) 
                {
                    x1 = 0;
                }
            }

            if (x2 == null) 
            {
                nStr = addMyComma(x1);
            }
            else 
            {
                nX2Len = x2.length;
                if (nX2Len > nDecFormat) 
                {
                    nStr = addMyComma(x1) + "," + x2.substring(0, nDecFormat);
                }
                else 
                {
                    nStr = addMyComma(x1) + "," + x2;
                }
            }
            document.getElementById(pArea).value = nSing + nStr;
        }
        else 
        {
            //no decimal
            nStrLen = nStr.length;
            nStrLastChar = nStr.substring(nStrLen - 1, nStrLen);

            if (nStrLastChar == '0' || nStrLastChar == '1' || nStrLastChar == '2' || nStrLastChar == '3' || nStrLastChar == '4' || nStrLastChar == '5' || nStrLastChar == '6' || nStrLastChar == '7' || nStrLastChar == '8' || nStrLastChar == '9' || nStrLastChar == '-') 
            {
                if (nStrLastChar == '-' & nStrLen > 1) 
                {
                    nStr = nStr.substring(0, nStrLen - 1);
                }

                nNum = 1;
                if (nStr.substring(0, 1) == '-') 
                {
                    nNum = 2;
                }

                if (nStr.length > nNum & (nStr.substring(0, 1) == '0' || nStr.substring(0, 2) == '-0')) 
                {
                    nStr = nStr.substring(0, nStrLen - 1);
                }
            }
            else 
            {
                nStr = nStr.substring(0, nStrLen - 1);
            }
            document.getElementById(pArea).value = nStr;
        }
    }
}

function addMyComma(xStr) 
{
    z1 = xStr;
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(z1)) 
    {
        z1 = z1.replace(rgx, '$1' + '.' + '$2');
    }
    return z1;
}

function addReCommas(pArea, nStr, nDecFormat, nMinVal) 
{
    if (nDecFormat.indexOf('.') != "-1") 
    {
        nDecSpl = nDecFormat.split('.')
        nDecFormat = nDecSpl[1].length - 1

        nSing = '';

        if (nStr.substring(0, 1) == '-') 
        {
            nSing = '-';
            nStr = nStr.substring(1, nStr.length);
        }

        x = nStr.split(',');
        x1 = x[0];
        if (x1 == null || x1 == '') 
        {
            if (nMinVal == null || nMinVal == '') 
            {
                nMinVal = 0;
            }
            x1 = nMinVal;
        }

        x2 = x[1];
        if (x2 == null) 
        {
            nStr = x1 + ",";
            for (i = 0; i <= nDecFormat - 1; i++) 
            {
                nStr += "0";
            }
        }
        else
         {
            nX2Len = x2.length;

            if (nX2Len < nDecFormat) 
            {
                nStr = x1 + "," + x2;

                for (i = 0; i <= nDecFormat - nX2Len - 1; i++) 
                {
                    nStr += "0";
                }
            }
        }
        document.getElementById(pArea).value = nSing + nStr;
    }
    else 
    {
        //no Decimal
        if (nStr == null || nStr == '' || nStr == '-') 
        {
            if (nMinVal == null || nMinVal == '')
            {
                nMinVal = 0;
            }
            nStr = nMinVal;
        }
        else {
            if (parseInt(nStr) < parseInt(nMinVal)) 
            {
                nStr = nMinVal;
            }
        }
        document.getElementById(pArea).value = nStr;
    }
}


function UpDown(pType)
{
    switch(pType)
    {
        case "Up":
            document.getElementById("txtSHP001_Quantity").value = parseInt(document.getElementById("txtSHP001_Quantity").value) + 1;
            break;
        case "Down":
            myQuantity = parseInt(document.getElementById("txtSHP001_Quantity").value) - 1;
            
            if(myQuantity <= 0)
            {
                document.getElementById("txtSHP001_Quantity").value = 1;
            }
            else
            {
                document.getElementById("txtSHP001_Quantity").value = myQuantity;
            }
            break;
    }
}
