//
// hem_products.js
// functions in js for hemstitcher.com
//
// by Mark Ward / Oasis Technologies
//
// 20080316
//

function msv(form) {
        var product_id=document.getElementById("material_select").value;
        if (product_id==-1) {
                alert ("Please Select a Material\n before adding the item\n      to your cart.");
                return false;
        }
        else {
                return true;
        }
}

function verify(form) {
        var ed=false;
        var etxt="";
        if (the_node=document.getElementById("material_select_"+form)) {
                if (thv=the_node.getAttribute("value")) {
                        if (thv==-1) {
                                ed=true;
                                etxt="* Material\n";
                       }
                }                
        }
        if (the_node=document.getElementById("mono_color_select_"+form)) {
                if (thv=the_node.getAttribute("value")) {
                        if (thv==-1) {
                                ed=true;
                                etxt+="* Monogram Color\n";
                       }
                }
        }
        if (the_node=document.getElementById("mono_font_select_"+form)) {
                if (thv=the_node.getAttribute("value")) {
                        if (thv==-1) {
                                ed=true;
                                etxt+="* Monogram Type Style\n";
                       }
                }
        }
        if (the_node=document.getElementById("mono_char_select_"+form)) {
                if (thv=the_node.getAttribute("value")) {
                        if (thv==-1) {
                                ed=true;
                                etxt+="* Monogram Character\n";
                       }
                }
        }
        if (the_node=document.getElementById("position_select_"+form)) {
                if (thv=the_node.getAttribute("value")) {
                        if (thv==-1) {
                                ed=true;
                                etxt+="* Monogram Position\n";
                       }
                }
        }
        if (ed) {
                estart="An error occured. Please make sure to select valid choices for the following items:\n\n";
                alert (estart+etxt);
                return false;
        }
        else {
                return true;
        }
}        


function update_image(product_id) {
        var material_id=document.getElementById("material_select_"+product_id).value;
        if (material_id!=-1) {
                var db_image_name=img_array[product_id][material_id];
                if (db_image_name.indexOf(".gif")>0 && db_image_name.indexOf("ttp:")===null) {
                                new_image="http://www.flannelworld.com/Images/product/"+db_image_name;
                }
                else if (db_image_name.indexOf("ttp:")>0) {
                                new_image=db_image_name;
                }
                else {
                        new_image="http://www.flannelworld.com/Images/product/"+db_image_name+".jpg";
                }
         data="<img src=\""+new_image+"\" onclick=\"client_display_full_image(product_id,"+material_id+");\" alt=\"Click on thumbnail to view a larger image\">";
           }
           else {
                           new_image="http://www.flannelworld.com/Images/product/"+db_image_name+".jpg";
                           data="<img src=\""+new_image+"\>";
           }
        document.getElementById("material_preview_"+product_id).innerHTML=data;
        update_price(product_id);
}


function update_thread_image(product_id) {
        var thread_id=document.getElementById("mono_color_select_"+product_id).value;
        if (thread_id!=-1) {
                var db_image_name=mt_img_array[product_id][thread_id];
                
                         data="<img src=\""+db_image_name+"\">";
           }
           else {
                data="<img src=\"http://www.hankyblanks.com/images/blank.gif\">";
           }
        document.getElementById("thread_preview_"+product_id).innerHTML=data;
}



function update_font_image(product_id) {
        var font_id=document.getElementById("mono_font_select_"+product_id).value;
        if (font_id!=-1) {
                var db_image_name=font_img_array[product_id][font_id];
                
                         data="<img src=\""+db_image_name+"\">";
           }
           else {
                data="<img src=\"http://www.hankyblanks.com/images/blank.gif\">";
           }
        document.getElementById("font_preview_"+product_id).innerHTML=data;
}



function update_price(product_id) {
        if (typeof(thv_a[product_id])!="undefined") {
                th=document.getElementById("thickness_"+product_id).value;
                thv=thv_a[product_id][th];
        }
        else {
                thv=0;
        }
        if (typeof(stv_a[product_id])!="undefined") {
                st=document.getElementById("style_"+product_id).value;
                stv=stv_a[product_id][st];
        }
        else {
                stv=0;
        }
        if (typeof(kiv_a[product_id])!="undefined") {
                ki=document.getElementById("kit_"+product_id).value;
                kiv=kiv_a[product_id][ki];
        }
        else {
                kiv=0;
        }
        if (typeof(siv_a[product_id])!="undefined") {
                si=document.getElementById("size_"+product_id).value;
                siv=siv_a[product_id][si];
        }
        else {
                siv=0;
        }
        if ((typeof(fcd_array[product_id])!="undefined")) {
                ms=document.getElementById("material_select_"+product_id).value;
                if (ms!=-1) {
                        mpv=fcd_array[product_id][ms];
                  }
                  else {
                                  mpv=0;
                  }
        }
        else {
                mpv=0;
        }
        if (typeof(delta_array[product_id])!="undefined") {
                        dv=document.getElementById("material_select_"+product_id).value;
                        if (dv==-1) {
                                mdv=0;
                        }
                        else {
                               mdv=delta_array[product_id][dv];
                       }
       }
       else {
                       mdv=0;
       }       
        if (typeof(mpd_array[product_id])!="undefined") {
                        dv=document.getElementById("position_select_"+product_id).value;
                        if (dv==-1) {
                                mpdv=0;
                        }
                        else {
                               mpdv=mpd_array[product_id][dv];
                       }
       }
       else {
                       mpdv=0;
       }
        if (typeof(mts_array[product_id])!="undefined") {
                        dv=document.getElementById("mono_color_select_"+product_id).value;
                        if (dv==-1) {
                                mtsv=0;
                        }
                        else {
                               mtsv=mts_array[product_id][dv];
                       }
       }
       else {
                       mtsv=0;
       }       
              
        
        np=bp[product_id]+thv+stv+kiv+siv+mpv+mdv+mpdv+mtsv;
        np=""+Math.floor(np*100);
        npl=np.length;
        npx=np.substring(0,npl-2)+"."+np.substring(npl-2,npl);
        document.getElementById("computed_price_"+product_id).innerHTML=npx;
}

