﻿
var bgColor1 = "#c2e8ff";
var bgColor2 = "#fffff0";
var bgColor3 = "#C2E8FF";
var bgColor4 = "#FFFFF0";

var bgC1 = "rgb(194, 232, 255)";
var bgC2 = "rgb(255, 255, 240)";

/*修改  border1 颜色小写  and  修改以下事件中的判断 */
var border1 = "#7dbef9 2px solid";

function selectBgColor()
{
    var _Br = GetBrowserVersion();    
    if(_Br == 'msie')
    {
        bgColor1 = bgColor1;
        bgColor2 = bgColor2;
        bgColor3 = bgColor3;
        bgColor4 = bgColor4;
    }
    else if(_Br == 'firefox')
    {
        bgColor1 = bgC1;
        bgColor2 = bgC2;
        bgColor3 = bgC1;
        bgColor4 = bgC2;
    }
}


function changeClass(obj,group,index)
{
    selectBgColor();

    document.getElementById("divL").style.display="none";
    document.getElementById("divW").style.display="none";
    document.getElementById("divBuy").style.display="none";

    var myForm;
    var hidPType = document.getElementById("hidProducType").value;
    myForm = document.forms[0];
    for(var i=0;i<myForm.length;i++)
    {
        if(myForm.elements[i].type=="button")
        {  
            if(myForm.elements[i].alt==group)
            {
                if(group=="W")
                {
                    //var bgColor1 = "#cccccc";
                    if(myForm.elements[i].style.backgroundColor==bgColor1)
                    {
                        setButtonStyle(myForm.elements[i]);
                    }
                    //var bgColor2 = "#ffffff";
                    if(obj.style.backgroundColor!=bgColor2)
                    {
                        if(hidPType==1)
                        {
                            setSelectedStyle(obj);

                            document.getElementById("txt_product_size1").value = obj.value;
                            document.getElementById("hid_measure_fid_1").value = obj.id;

                            MoveOnbutton(obj,index);

                            selectSizeW = new Array(obj)
                            selectSizeWindex = new Array(index + "");
                        }
                        else
                        {
                            setSelectedStyle(obj);

                            document.getElementById("txthid_product_size").value="";
                            document.getElementById("txt_product_size1").value="";
                            document.getElementById("hid_measure_fid_1").value="";
                            document.getElementById("txt_product_size2").value="";
                            document.getElementById("hid_measure_fid_2").value="";

                            document.getElementById("txthid_product_size").value=obj.value;
                            document.getElementById("txt_product_size1").value=obj.value;
                            document.getElementById("hid_measure_fid_1").value=obj.id;
                            document.getElementById("txt_product_size2").value=obj.value;
                            document.getElementById("hid_measure_fid_2").value=obj.id;

                            MoveOnbutton(obj,index);

                            selectSizeW = new Array(obj)
                            selectSizeWindex = new Array(index + "");
                        }
                    }
                    else
                    {
                        document.getElementById("txt_product_size1").value="";
                        document.getElementById("txt_product_size3").value="";
                        document.getElementById("hid_measure_fid_1").value="";
                        selectSizeW = new Array();
                    }
                }
                if(group=="L")
                {
                    //var bgColor1 = "#cccccc";
                    if(myForm.elements[i].style.backgroundColor==bgColor1)
                    {
                        setButtonStyle(myForm.elements[i]);
                    }
                    //var bgColor2 = "#ffffff";
                    if(obj.style.backgroundColor!=bgColor2)
                    {
                        setSelectedStyle(obj);

                        document.getElementById("txt_product_size2").value=obj.value;
                        document.getElementById("hid_measure_fid_2").value=obj.id;

                        MoveOnbutton_L(obj,index);

                        selectSizel = new Array(obj);
                        selectSizelindex = new Array(index+"");
                    }
                    else
                    {                            
                        document.getElementById("txt_product_size2").value="";
                        document.getElementById("txt_product_size3").value="";
                        document.getElementById("hid_measure_fid_2").value="";
                        selectSizel = new Array();
                    }
                }
            } 
        }
    }
    var product_size1 = document.getElementById("hid_measure_fid_1").value;        	      
    var product_size2 = document.getElementById("hid_measure_fid_2").value;        	      
    if(product_size1!="")
    {
        if(product_size2!="")
            GetOneToOneSize(product_size1,product_size2);
    }
    GetPriceAfterSelect();
}



function  MoveOnbutton(obj,index)
{
    selectBgColor();
    var _Br = GetBrowserVersion();
    
    if(obj.style.backgroundColor!=bgColor2)
    {
        //var bgColor1 = "#cccccc";
        if(obj.style.backgroundColor==bgColor1)
            setSelectedStyle(obj);
        else
            setMouseoverStyle(obj);
    }
    else
    {
        setSoldOutStyle(obj);
    }    
    
    var	arrayList;
    var colorid;
    
    if(_Br == 'msie')
    {
        arrayList = document.images.namedItem("ColorImage");
        
        var cl = document.getElementById(document.images.namedItem("ColorImage").id);   
        if(arrayList.length == undefined)
        {
            if((arrText[index][0]+"").indexOf(cl.id.replace("color_",""))!=-1)
            {
                if(cl.style.border=="#7dbef9 2px solid")
                    colorid = cl.id.replace("color_","");
            }
        }
        else
        {
            for(var i=0;i<arrayList.length;i++)
            {   
                if(arrText.length>0)
                {     
                    if(index<arrText.length)
                    {
                        if(arrText[index].length!=null)
                        {
                            if((arrText[index][0]+"").indexOf(arrayList[i].id.replace("color_",""))!=-1)
                            {
                                if(arrayList[i].style.border=="#7dbef9 2px solid")
                                    colorid = arrayList[i].id.replace("color_","");
                            }
                        }
                    }
                }
            }
        }
    }
    else if(_Br == 'firefox')
    {
        arrayList = window.document.getElementsByName('ColorImage');
        
        var cl = document.getElementById(document.images.namedItem("ColorImage").id);   
        if(arrayList.length == undefined)
        {
            if((arrText[index][0]+"").indexOf(cl.id.replace("color_",""))!=-1)
            {
                if(cl.style.border=="2px solid rgb(10, 0, 61)")
                    colorid = cl.id.replace("color_","");
            }
        }
        else
        {
            for(var i=0;i<arrayList.length;i++)
            {   
                if(arrText.length>0)
                {     
                    if(index<arrText.length)
                    {
                        if(arrText[index].length!=null)
                        {
                            var c_id = window.document.getElementById(arrayList[i].id);
                            if((arrText[index][0]+"").indexOf(c_id.id.replace("color_",""))!=-1)
                            {
                                if(c_id.style.border=="2px solid rgb(10, 0, 61)")
                                    colorid = c_id.id.replace("color_","");
                            }
                        }
                    }
                }
            }
        }
    }
    
    var mForm = document.forms[0];
	
    //内裆的循环判更改样式
    //=================================================
    for(var i=0;i<mForm.length;i++)
    {
        if(mForm.elements[i].type=="button")
        {
            if(mForm.elements[i].alt=="L")
            {
                if( mForm.elements[i].style.backgroundColor==bgColor3)
                    setSelectedStyle(mForm.elements[i]);
                else
                    setSoldOutStyle(mForm.elements[i]);
                
                if(arrText.length>0)
                {     
                    if(index<arrText.length)
                    { 
                        if(arrText[index].length!=null)
                        {
                            if(arrText[index].length>0)
                            {
                                var num = 0;
                                var indexL=0;
                                var a = (arrText[index][0]+"").split(",");                             
                                for(var k = 0;k<a.length-1;k++)
                                {
                                    var id = a[k];
                                    var color_id = colorid;
                                    if(id == color_id)
                                    {
                                        if(indexL==0)
                                        {
                                            indexL=k
                                        }                                       
                                        num = num + 1;    
                                    }
                                }
                                var btnlistL=(arrText[index][1]+"").split(",");
                                for(var j=indexL;j<indexL+num;j++)
                                {
                                    if(mForm.elements[i].style.backgroundColor==bgColor3)
                                        setSelectedStyle(mForm.elements[i]);
                                    else
                                        setButtonStyle(document.getElementById(btnlistL[j]));
                                }
                            }  
                        }
                    }
                }
                if(selectSizel.length>0)
                {
                    setSelectedStyle(document.getElementById(selectSizel[0].id));
                }
            } 
        }
    }
    
    //判断当前尺寸的颜色是否有库存
    isSelectStock(index);
}



function  MoveOnbutton_L(obj,index)
{
    selectBgColor();
    var	arrayList;
    var colorid;
    var _Br = GetBrowserVersion();    
    if(_Br == 'msie')
    {
        arrayList = window.document.images.namedItem("ColorImage");
        
        var cl = document.getElementById(document.images.namedItem("ColorImage").id);   
        if(arrayList.length == undefined)
        {
            if((arrText[index][0]+"").indexOf(cl.id.replace("color_",""))!=-1)
            {
                if(cl.style.border=="#7dbef9 2px solid")
                    colorid = cl.id.replace("color_","");
            }
        }
        else
        {
            for(var i=0;i<arrayList.length;i++)
            {   
                if(arrText.length>0)
                {     
                    if(index<arrText.length)
                    {
                        if(arrText[index].length!=null)
                        {
                            if((arrText[index][0]+"").indexOf(arrayList[i].id.replace("color_",""))!=-1)
                            {
                                if(arrayList[i].style.border=="#7dbef9 2px solid")
                                    colorid = arrayList[i].id.replace("color_","");
                            }
                        }
                    }
                }
            }
        }
    }
    else if(_Br == 'firefox')
    {
        arrayList = window.document.getElementsByName('ColorImage');
        
        var cl = document.getElementById(document.images.namedItem("ColorImage").id);   
        if(arrayList.length == undefined)
        {
            if((arrText[index][0]+"").indexOf(cl.id.replace("color_",""))!=-1)
            {
                if(cl.style.border=="2px solid rgb(10, 0, 61)")
                    colorid = cl.id.replace("color_","");
            }
        }
        else
        {
            for(var i=0;i<arrayList.length;i++)
            {   
                if(arrText.length>0)
                {     
                    if(index<arrText.length)
                    {
                        if(arrText[index].length!=null)
                        {
                            var c_id = window.document.getElementById(arrayList[i].id);
                            if((arrText[index][0]+"").indexOf(c_id.id.replace("color_",""))!=-1)
                            {
                                if(c_id.style.border=="2px solid rgb(10, 0, 61)")
                                    colorid = c_id.id.replace("color_","");
                            }
                        }
                    }
                }
            }
        }
    }


    var mForm = document.forms[0];
    if(obj.style.backgroundColor!=bgColor2)
    {
        //var bgColor1 = "#cccccc";
        if(obj.style.backgroundColor==bgColor1)
            setSelectedStyle(obj);
        else
            setMouseoverStyle(obj);
    }
    else
    {
        setSoldOutStyle(obj);
    }
	//腰围的循环判更改样式
	for(var i=0;i<mForm.length;i++)
	{
        if(mForm.elements[i].type=="button")
        {  
            if(mForm.elements[i].alt=="W")
            {
                if( mForm.elements[i].style.backgroundColor==bgColor3)
                    setSelectedStyle(mForm.elements[i]);
                else
                    setSoldOutStyle(mForm.elements[i]);
                
                if(arrTextl.length>0)
                { 
                    if(index<arrTextl.length)
                    {
                        if(arrTextl[index].length!=null)
                        {
                            if(arrTextl[index].length>0)
                            {
                                var num = 0;
                                var indexW=0;
                                var a = (arrTextl[index][0]+"").split(",");
                                for(var k = 0;k<a.length-1;k++)
                                {
                                    var id = a[k];
                                    var color_id = colorid;
                                    if(id == color_id)
                                    {
                                        if(indexW==0)
                                        {
                                            indexW=k;
                                        }
                                        num = num + 1;    
                                    }
                                }
                                var btnlist=(arrTextl[index][1]+"").split(",");
                                for(var j=indexW;j<indexW+num;j++)
                                {
                                    if(mForm.elements[i].style.backgroundColor==bgColor3)
                                        setSelectedStyle(mForm.elements[i]);
                                    else
                                        setButtonStyle(document.getElementById(btnlist[j]));
                                }
                            }
                        }  
                    }                  
                }
                if(selectSizeW.length>0)
                {
                    setSelectedStyle(document.getElementById(selectSizeW[0].id));
               }
            } 
        }
    }
    //判断当前尺寸的颜色是否有库存
    isSelectStock(index);
}


function isSelectStock(index)
{
    var _Br = GetBrowserVersion();    
    
    var arrayList = window.document.images.namedItem("ColorImage");
    var cl = document.getElementById(document.images.namedItem("ColorImage").id);   
    if(arrayList.length == undefined)
    {
        if((arrText[index][0]+"").indexOf(cl.id.replace("color_",""))!=-1)
        {
            if(_Br == 'msie')
            {
                if(cl.style.border=="#7dbef9 2px solid")
                    ImageOnclick(cl);
                else
                    Imagebutton(cl);
            }
            else if(_Br == 'firefox')
            {
                if(cl.style.border== "2px solid rgb(10, 0, 61)")
                    ImageOnclick(cl);
                else
                    Imagebutton(cl);
            }            
        }
        else
        {
            ImagesoldOut(cl);
        }
    }
    else
    {
        for(var i=0;i<arrayList.length;i++)
        {   
            if(arrText.length>0)
            {     
                if(index<arrText.length)
                {
                    if(arrText[index].length!=null)
                    {
                        if((arrText[index][0]+"").indexOf(arrayList[i].id.replace("color_",""))!=-1)
                        {
                            if(_Br == 'msie')
                            {
                                if(arrayList[i].style.border=="#7dbef9 2px solid")
                                    ImageOnclick(arrayList[i]);
                                else
                                    Imagebutton(arrayList[i]);
                            }
                            else if(_Br == 'firefox')
                            {
                                if(arrayList[i].style.border== "2px solid rgb(10, 0, 61)")
                                    ImageOnclick(arrayList[i]);
                                else
                                    Imagebutton(arrayList[i]);
                            }
                        }
                        else
                        {
                            ImagesoldOut(arrayList[i]);
                        }
                    }
                    else
                    {
                        ImagesoldOut(arrayList[i]);
                    }
                }
                else
                {
                    ImagesoldOut(arrayList[i]);
                }
            }
            else
            {
                ImagesoldOut(arrayList[i]);
            }
        }
    }
}




function mouseoutSize(obj)
{
    selectBgColor();
    var myForm;
    myForm=document.forms[0];
    for(var i=0;i<myForm.length;i++)
    {
        if(myForm.elements[i].type=="button")
        {  
            if(obj.alt=="W")
            {     
                if(myForm.elements[i].alt=="W")
                {
                    if(myForm.elements[i].style.backgroundColor!=bgColor2)
                    {
                        //var bgColor1 = "#cccccc";
                        if(myForm.elements[i].style.backgroundColor==bgColor1)
                            setSelectedStyle(myForm.elements[i]);
                        else
                            setButtonStyle(myForm.elements[i]);
                    }
                    else
                    {
                        setSoldOutStyle(myForm.elements[i]);
                    }
                }      
                if(myForm.elements[i].alt=="L")
                {
                    if(selectSizeW.length>0)
                    {
                        if(myForm.elements[i].style.backgroundColor!=bgColor4)
                        {                                
                            //var bgColor3 = "#CCCCCC";
                            if(myForm.elements[i].style.backgroundColor!=bgColor3)
                                setSelectedStyle(myForm.elements[i]);
                            else
                                setButtonStyle(myForm.elements[i]);
                        }
                        else
                        {
                            setSoldOutStyle(myForm.elements[i]);
                        }
                    }
                    else
                    {
                        if(myForm.elements[i].style.backgroundColor==bgColor1)
                            setSelectedStyle(myForm.elements[i]);
                        else
                            setButtonStyle(myForm.elements[i]);
                    }   		    
                } 
		    }   
		    if(obj.alt=="L")
		    {  
		        if(myForm.elements[i].alt=="L")
                {
                    if(myForm.elements[i].style.backgroundColor!=bgColor2)
                    {
                        //var bgColor1 = "#cccccc";
                        if(myForm.elements[i].style.backgroundColor==bgColor1)
                            setSelectedStyle(myForm.elements[i]);
                        else
                            setButtonStyle(myForm.elements[i]);
                    }
                    else
                    {
                        setSoldOutStyle(myForm.elements[i]);
                    }
                }     
                if(myForm.elements[i].alt=="W")
                {  
                    if(selectSizel.length>0)
                    {
                        if(myForm.elements[i].style.backgroundColor!=bgColor4)
                        {
                            //var bgColor3 = "#CCCCCC";
                            if(myForm.elements[i].style.backgroundColor==bgColor3)
                                setSelectedStyle(myForm.elements[i]);
                            else
                                setButtonStyle(myForm.elements[i]);
                        }
                        else
                        {
                            setSoldOutStyle(myForm.elements[i]);
                        }
                    }
                    else
                    {
                        if(myForm.elements[i].style.backgroundColor==bgColor1)
                            setSelectedStyle(myForm.elements[i]);
                        else
                            setButtonStyle(myForm.elements[i]);
                    }
                } 
        	}
        }
    }
    OutbuttonSize();
}

function OutbuttonSize()
{
    var objL = "";
    var objW = "";
    if(selectSizel.length>0)
    {
        objL = selectSizel[0];
        hidlindex = selectSizelindex[0];
        MoveOnbutton_L(objL,hidlindex);
    }
    if(selectSizeW.length>0)
    {
        objW = selectSizeW[0];
        hidwindex=selectSizeWindex[0];
        MoveOnbutton(objW,hidwindex); 
    }
    if(SelectColorObj.length>0)
    {
        ImageOnclick(SelectColorObj[0]);
    }
}
 
