function updateMan(elem)
{
	r = document.getElementById("update_cat");
	v = document.catForm.material.options[document.catForm.material.options.selectedIndex].value;
	y = document.catForm.cat_id.value;
	z = document.catForm.manufacturer.options[document.catForm.manufacturer.options.selectedIndex].value;

	r.src = "update_cat.php?material=" + v + "&cat_id=" + y + "&manufacturer=" + z;
}

function resetTheForm()
{
	var myForm = document.price;
	myForm.filter_text.value = "";
	myForm.filter_condition.selectedIndex = 0;
	myForm.filter_type.selectedIndex = 0;
	myForm.filter_price.selectedIndex = 0;
	myForm.filter_dimensions_width.selectedIndex = 0;
	myForm.filter_dimensions_height.selectedIndex = 0;
	myForm.filter_manufacturer.selectedIndex = 0;
	myForm.filter_colour.selectedIndex = 0;
	myForm.filter_geartype.selectedIndex = 0;
}

/*
function showPopup(url,wid,hei)
{
    new_url = new String(url);
    ext = url.substr(url.lastIndexOf('.'), 5);
    new_url = new_url.substring(0, new_url.lastIndexOf('.'))+'_l'+ext;
    newwindow = window.open(new_url,'name','height='+hei+',width='+hei);
}
*/

/*
    Product Details Scripts
    showPopup() - self explanitory with the addition of the renaming of the image.
    changeImage() - replaces the large imahge with the thumbnail clicked.
    popGearType() - popup windows for the "what's this" link
*/

function showPopup(url, wid, hei)
{
    var new_url, ext, newext, the_length;

    new_url = new String(url);
    ext = url.substr(url.lastIndexOf('.'), 5);
    new_url = new_url.substring(0, new_url.lastIndexOf('.'))+'_l'+ext;
    newext = new_url.split('/');
    the_length = (newext.length)-1;
    new_url = newext[the_length];
    newwindow = window.open('product_images.php?imgId=' + new_url, 'name', 'height=' + hei + ',width=' + hei + ',resizable=1');
}
function showPopup1(url, wid, hei)
{
    var new_url, ext, newext, the_length;

    new_url = new String(url);
    ext = url.substr(url.lastIndexOf('.'), 5);
    new_url = new_url.substring(0, new_url.lastIndexOf('.'))+'_l'+ext;
    newext = new_url.split('/');
    the_length = (newext.length)-1;
    new_url = newext[the_length];
    newwindow = window.open('product_images.php?imgId=' + new_url, 'name', 'height=' + hei + ',width=' + hei + ',resizable=1');
}
function changeImage(thesrc)
{
    document.getElementById('main').src = 'images/products/'+thesrc;
}

function popGearType(id, wid, hei)
{
    try {
        newwindow = window.open('product_geartype.php?id='+id,'name','resizable=1,scrollbars=yes,height='+hei+',width='+hei);
    }
    catch(e)
    {
        alert('Can not load popup');
    }
}

/*
  @carteckForm
    -> Used for clearing fields
    -> Checks for the
*/

var askQuestion;

var carteckForm =
{

    debugInfo: '',

    clear: function(whatFields)
    {
        switch (whatFields)
        {
            case 'standard':
              document.myform.height_standard.selectedIndex = '';
              document.myform.width_standard.selectedIndex = '';
              document.myform.height_imperial.selectedIndex = '';
              document.myform.width_imperial.selectedIndex = '';
            break;

            case 'bespoke':
              document.myform.height_bespoke.value = '';
              document.myform.width_bespoke.value = '';
            break;

            default:
              // This should never happen
              alert("You have selected an invalid field");
            break;
        }
    },

    question: function (firstWord)
    {
        //return "Click OK if you would like to remove the information stored for the " + firstWord + " or click CANCEL if you wuold like to maintain that information";
    },

    checkFields: function(currentType)
    {
        switch (currentType)
        {
            case 'bespoke':

              var heightIndex = document.myform.height_standard.options[document.myform.height_standard.selectedIndex].value;
              var widthIndex  = document.myform.width_standard.options[document.myform.width_standard.selectedIndex].value;

              // this.debugInfo += "Height S: " + heightIndex;
              // this.debugInfo += "Width S: " + widthIndex;

              if (heightIndex != '' || widthIndex != '')
              {
                  // askQuestion = confirm(this.question('Standard', 'Purpose made'));

                  this.clear('standard');

                  /*
                    if (askQuestion == true)
                    {
                        this.clear('standard');
                    }
                    else
                    {
                        this.clear('bespoke');
                    }
                  */
              }

            break;

            case 'standard':

              heightBespoke = document.myform.height_bespoke.value;
              widthBespoke  = document.myform.width_bespoke.value;

              // this.debugInfo += "Height B: " + heightBespoke;
              // this.debugInfo += "Width B: "  + widthBespoke;

              if (heightBespoke != '' || widthBespoke != '')
              {
                  this.clear('bespoke');

                  /*
                    askQuestion = confirm(this.question('Purpose made', 'Standard'));

                    if (askQuestion)
                    {
                        this.clear('bespoke');
                    }
                    else
                    {
                        this.clear('standard');
                    }
                  */
              }

            break;

            default:
              // This should never happen
              alert("You have selected an invalid field");
            break;

        }

        if (this.debugInfo.length > 0)
        {
            alert("Debug: " + this.debugInfo);
        }

        this.debugInfo = '';
    }
}

/* Clear Field Value On Click `*/
function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}

/* Submit Login Form */
function do_login(){
document.login.submit();
}






