// Price Quote Scripts

// Validation Function

function validate(quote) 
{
    //
    // Check the First Name field to see if any characters were entered
    //
    if (quote.first.value.length == 0)
    {
        alert("Please enter your first name.");
        quote.first.focus();
        return false;
	}
	//
    // Check the Last Name field to see if any characters were entered
    //
    if (quote.last.value.length == 0)
    {
        alert("Please enter your last name.");
        quote.last.focus();
        return false;
    }
	//
    // Check the City field to see if any characters were entered
    //
    if (quote.city.value.length == 0)
    {
        alert("Please enter your city.");
        quote.city.focus();
        return false;
	}
	//
    // Check the State field to see if characters were entered
    //
    if (quote.state.value.length == 0)
    {
        alert("Please enter your state.");
        quote.state.focus();
        return false;
	}
	//
    // Check the Zip Code field to see if characters were entered
    //
    if (quote.zip.value.length == 0)
    {
        alert("Please enter your zip code.");
        quote.zip.focus();
        return false;
	}
	//
    // Check the Email field to see if any characters were entered
    //
    if (quote.email1.value.length == 0)
    {
        alert("Please enter an e-mail address.");
        quote.email1.focus();
        return false;
    }
    //
    // Now check the Email field for the "@" symbol
    //
    if (quote.email1.value.indexOf("@") == -1)
    {
        alert("Please enter a valid e-mail address.");
        quote.email1.focus();
        return false;
    }
}

// Checks If Fields Match Function

function BothFieldsIdenticalCaseSensitive() {
var one = document.quote.email1.value;
var another = document.quote.email2.value;
if(one == another) { return true; }
alert("Please make sure both E-Mails are identical.");
return false;
}

function BothFieldsIdenticalCaseInsensitive() {
var one = document.quote.email1.value.toLowerCase();
var another = document.quote.email2.value.toLowerCase();
if(one == another) { return true; }
alert("Please make sure both E-Mails are identical.");
return false;
}

// Main Function for getting items from the Address bar and putting them into the fields.
function replace(string,text,by) {
    // Replaces text with by in string
    var i = string.indexOf(text), newstr = '';
    if ((!i) || (i == -1))
        return string;
    newstr += string.substring(0,i) + by;
    if (i+text.length < string.length)
        newstr += replace(string.substring(i+text.length,string.length),text,by);
    return newstr;
}

var passed = replace(replace(location.search.substring(1),"+"," "),"=","&");

function split(string,text) {
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return;
    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return;
    if (i == -1) {
        splitArray[splitIndex++] = string;
        return;
    }
    splitArray[splitIndex++] = string.substring(0,i);
    if (i+txtLength < strLength)
        split(string.substring(i+txtLength,strLength),text);
    return;
}


function split(string,text) {
    splitArray = string.split(text);
    splitIndex = splitArray.length;
}


// Gets Items from Address Bar
var splitIndex = 0, splitArray = new Object();

split(passed,'&');

for (var i=0; i < splitIndex; i=i+2) {
    if (splitArray[i] == 'style')
        document.quote.style.value = unescape(splitArray[i+1]);
    if (splitArray[i] == 'color')
        document.quote.color.value = unescape(splitArray[i+1]);
    if (splitArray[i] == 'manufacturer')
        document.quote.manufacturer.value = unescape(splitArray[i+1]);
    if (splitArray[i] == 'product')
        document.quote.product[splitArray[i+1]].checked = true;
	if (splitArray[i] == 'selectname')
        document.quote.selectname.selectedIndex = splitArray[i+1];
    if (splitArray[i] == 'multipleselectname')
        document.quote.multipleselectname.options[splitArray[i+1]-0].selected = true;
    if (splitArray[i] == 'checkboxname')
        document.quote.checkboxname.checked = true;
    if (splitArray[i] == 'radioname')
        document.quote.radioname[splitArray[i+1]].checked = true;
}