// JavaScript Document
function DisplayImage(imgName, imgTarget)
{
    document.getElementById(imgTarget).src = imgName;
}
function SetActiveTab(newTab, listTabs)
{
    if (listTabs)
    {
        for(var i = 0; i < listTabs.length; i++)
            SetInactiveTab(listTabs[i]);
    }    
    document.getElementById(newTab + "Left").className = "bgTabL";
    document.getElementById(newTab + "Center").className = "bgTabB";
    document.getElementById(newTab + "Right").className = "bgTabR";
}

function SetInactiveTab(newTab)
{
    document.getElementById("bgTabLB" + newTab).className = "bgTabL";
    document.getElementById("bgTabCB" + newTab).className = "bgTabC";
    document.getElementById("bgTabRB" + newTab).className = "bgTabR";
}
function ChangeTab(newTab)
{
    for (var i = 0; i < arrCategory.length; i++)
    {
        SetInactiveTab(arrCategory[i]);
    }
    document.getElementById("bgTabLB" + newTab).className = "bgTabLB";
    document.getElementById("bgTabCB" + newTab).className = "bgTabCB";
    document.getElementById("bgTabRB" + newTab).className = "bgTabRB";
}
function A(src)
{
	 var 	image=document.getElementById("image");                                 
			image.src=src;
}

function ChangeImage(id,src)
{
	 var 	image=document.getElementById(id);                                 
			image.src=src;
}
function AddProperty(propertyName1, propertyType, checkBox, CanInput, txtboxName)
    {
        var div = $get("divOrderProperty_" + propertyType);
        var propertyName = propertyName1;
        if (div)
        {
            //If selected, add it
            if (checkBox.checked)
            {
                if(CanInput == "True")
                    propertyName = propertyName1 + "()";
                //Check for first time add, so, it equals "[.?.]"
                if (div.innerHTML.indexOf("[.?.]") >= 0)
                    div.innerHTML = propertyName;
                else //Not first time, add trail
                    div.innerHTML += ", " + propertyName;
            }
            else //Not selected (remove)
            {
                if(CanInput == "True")
                {
                    var txtbox = document.getElementById(txtboxName);
                    if(txtbox)
                        txtbox.value = '';
                    propertyName = div.innerHTML.substring(div.innerHTML.indexOf(propertyName), div.innerHTML.indexOf(')', div.innerHTML.indexOf(propertyName)) + 1);
                }
                //Get position of property to remove
                var index = div.innerHTML.indexOf(propertyName);
                //If this's first property
                if (index == 0)
                {
                    //If the string has only this property, replace it by "[.?.]"
                    if (div.innerHTML.length == propertyName.length)
                        div.innerHTML = "[.?.]";
                    else //Otherwise, remove it from string by get string from it's position include ", " to end of string
                        div.innerHTML = div.innerHTML.substring(propertyName.length + 2, div.innerHTML.length);
                }
                else if (index + propertyName.length == div.innerHTML.length) //If this's the last property
                {
                    //Remove it by get string from 0 to it's position include the previous ", "
                    div.innerHTML = div.innerHTML.substring(0, index - 2);
                }
                else //It's between string
                {
                    //Remove it by get string from 0 to it's position combine string from the end position of current removed property include ", " to end
                    div.innerHTML = div.innerHTML.substring(0, index) + div.innerHTML.substring(index + propertyName.length + 2, div.innerHTML.length);
                }
            }
        }
    }
    function AddProperty1(propertyType, combobox)
    {
        var div = $get("divOrderProperty_" + propertyType);
        if (div)
            div.innerHTML = combobox.options[combobox.selectedIndex].text;
    }
     function AddProperty2(propertyTye, txtbox, propertyName, e, chkboxName)
    {
        if(txtbox)
        {
            var chkbox = document.getElementById(chkboxName);
            if(chkbox)
            {
                if(!chkbox.checked)
                {
                    chkbox.checked = true;
                    AddProperty(propertyName, propertyTye, chkbox, 'True', txtbox);
                }
            }  
            txtbox.value = txtbox.value.replace('(', '').replace(')', '');
            if(e.keyCode == 57 || e.which == 57 || e.keyCode == 48 || e.which == 48)
                txtbox.value = txtbox.value.replace('(', '').replace(')', '');
            else
            {
                var div = $get("divOrderProperty_" + propertyTye);
                var i = -1;
                var y = -1;
                if(div)
                {
                    i = div.innerHTML.indexOf(propertyName + "(");
                    if(i > -1)
                        y = div.innerHTML.indexOf(')', i + (propertyName + "(").length);
                    var str1 = "";
                    var str2 = "";
                    if(i > -1 && y > -1)
                    {
                        str1 = div.innerHTML.substring(0, i + (propertyName + "(").length);
                        str2 = div.innerHTML.substring(y, div.innerHTML.length);
                        div.innerHTML = str1 + txtbox.value + str2;
                    }
                }
            }
        }
    }