function ChangeImage(pSMA010_Name, pSMA010_Price, pSMA010_Code, pSMA010_Id, pThis) 
{
    for (i = 0; i < document.Form1.length; i++) 
    {
        if (document.Form1.elements[i].type == 'radio') 
        {
            if (document.Form1.elements[i].name.substring(0, 5) == 'myPro') 
            {
                document.Form1.elements[i].checked = false;
            }
        }
    }
    pThis.checked = true;

    document.getElementById(document.getElementById("txtSMA010_Id").value).style.display = "none";
    document.getElementById(pSMA010_Id).style.display = "";
    document.getElementById("txtSMA010_Id").value = pSMA010_Id;
}


function ChangeImage2(pSMA010_Name, pSMA010_Price, pSMA010_Code, pSMA010_Id, pThis) 
{
    myThis = "_" + pThis.id.split('_')[1] + "_";
    
    for (i = 0; i < document.Form1.length; i++) 
    {
        if (document.Form1.elements[i].type == 'radio') 
        {
            if (document.Form1.elements[i].name.indexOf('myProduct') > -1) 
            {
                document.Form1.elements[i].checked = false;
            }
        }
    }
        
    pThis.checked = true;

    document.getElementById(myThis + "txtSMA010_Id").style.display = "none";

    document.getElementById(myThis + "txtSMA010_Id").value = pSMA010_Id;
}


function PaySelect() 
{
    document.getElementById("tabCard").style.display = "none";
    document.getElementById("tabBank").style.display = "none";
    document.getElementById('txtCardName').value = '';
    document.getElementById('txtCardNo').value = '';
    document.getElementById('ddlCardType').options[0].selected = true;
    document.getElementById('ddlCardMonth').options[0].selected = true;
    document.getElementById('ddlCardYear').options[0].selected = true;
    document.getElementById('txtCardCvc').value = '';
    for (i = 0; i < document.Form1.length; i++) 
    {
        if (document.Form1.elements[i].type == 'radio') 
        {
            if (document.Form1.elements[i].name.substring(0, 5) != 'myPro') 
            {
                document.Form1.elements[i].checked = false;
            }    
        }
    }

    document.getElementById('txtPayId').value = '-1';
    document.getElementById('txtPayType').value = '-1';

    switch (document.getElementById("ddlPayType").options[document.getElementById("ddlPayType").selectedIndex].value) 
    {
        case "1":
            document.getElementById("tabCard").style.display = "";
            break;
        case "2":
            document.getElementById("tabBank").style.display = "";
            break;
    }
    document.getElementById('txtPayType').value = document.getElementById("ddlPayType").options[document.getElementById("ddlPayType").selectedIndex].value;
    
}

function CheckSelect(pLocation,pThis,pId)
{
	if(document.all)
	{
		if (pLocation == 'Card')
		{
			for(i=0;i< document.Form1.length;i++)
			{
			    if (document.Form1.elements[i].type == 'radio') 
				{
				    if (document.Form1.elements[i].name.substring(0, 5) != 'myPro') 
				    {
				        document.Form1.elements[i].checked = false;
				    }
				}
			}   
		
			document.getElementById('txtCardName').value = '';
			document.getElementById('txtCardNo').value = '';
			document.getElementById('ddlCardType').options[0].selected = true;
			document.getElementById('ddlCardMonth').options[0].selected = true;
			document.getElementById('ddlCardYear').options[0].selected = true;
			document.getElementById('txtCardCvc').value = '';
		
			pThis.checked = true;          
			document.getElementById('txtPayId').innerText = pId;
		}

		if (pLocation == 'Bank')
		 {
			for(i=0;i< document.Form1.length;i++)
			{
			    if (document.Form1.elements[i].type == 'radio') 
				{
				    if (document.Form1.elements[i].name.substring(0, 5) != 'myPro') 
				    {
				        document.Form1.elements[i].checked = false;
				    }
				}
			}

			pThis.checked = true;
			document.getElementById("txtPayId").innerText = pId;
		}
	}
	else
	{
		//Firefox Block
		if (pLocation == 'Card')
		{
			for(i=0;i< document.Form1.length;i++)
			{
				if (document.Form1.elements[i].type == 'radio')
				{
					document.Form1.elements[i].checked = false;
				}
			}   
		
			document.getElementById('txtCardName').value = '';
			document.getElementById('txtCardNo').value = '';
			document.getElementById('ddlCardType').options[0].selected = true;
			document.getElementById('ddlCardMonth').options[0].selected = true;
			document.getElementById('ddlCardYear').options[0].selected = true;
			document.getElementById('txtCardCvc').value = '';
		
			pThis.checked = true;          
			document.getElementById('txtPayId').value = pId;
		}

		if (pLocation == 'Bank')
		{
			for(i=0;i< document.Form1.length;i++)
			{
				if (document.Form1.elements[i].type == 'radio')
				{
				document.Form1.elements[i].checked = false;
				}
			}   
		
			pThis.checked = true;          
			document.getElementById("txtPayId").value = pId;
		}
	}
}

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 onMouse(pThis, pColor) 
{
    pThis.style.color = pColor;
}




