
function fnCheckForm(form) 
{
	var alertmsg = ""

    First_Name = form.First_Name.value;
    Last_Name = form.Last_Name.value;
    Address_Line1 = form.Address_Line1.value;
    Address_Line2 = form.Address_Line2.value;
    City = form.City.value;
    State = form.State.value;
    Zip_Code = form.Zip_Code.value;
    Country = form.Country.value;
    Email = form.Email.value;
    Phone_Area_Code = form.Phone_Area_Code.value;
    Phone_Exchange = form.Phone_Exchange.value;
    Phone_Number = form.Phone_Number.value;
    Where_Purchased = form.Where_Purchased.value;
    Model_Purchased = form.Model_Purchased.value;
    When_Purchased_Month = form.When_Purchased_Month.value;
    When_Purchased_Year = form.When_Purchased_Year.value;
    Installation_Type = form.Installation_Type.value;
    Installation_Company_Name = form.Installation_Company_Name.value;
    
	if (First_Name == "") 
	{
		alertmsg = alertmsg + ("- your FIRST NAME is required\n")
	}
	if (First_Name.indexOf('"') >= 0)
	{
		alert ("Double Quotes are not allowed.\nPlease adjust this First Name value.")	
		form.First_Name.focus()
		return false;
	}	
	
	if (Last_Name == "") 
	{
		alertmsg = alertmsg + ("- your LAST NAME is required\n")
	}
	if (Last_Name.indexOf('"') >= 0)
	{
		alert ("Double Quotes are not allowed.\nPlease adjust this Last Name value.")	
		form.Last_Name.focus()
		return false;
	}	

	if (Address_Line1 == "") 
	{
		alertmsg = alertmsg + ("- your ADDRESS is required\n")
	}
	if (Address_Line1.indexOf('"') >= 0)
	{
		alert ("Double Quotes are not allowed.\nPlease adjust this Address value.")	
		form.Address_Line1.focus()
		return false;
	}	

	if (Address_Line2.indexOf('"') >= 0)
	{
		alert ("Double Quotes are not allowed.\nPlease adjust this Address value.")	
		form.Address_Line2.focus()
		return false;
	}	
		
	if (City == "") 
	{
		alertmsg = alertmsg + ("- your CITY is required\n")
	}

	if (City.indexOf('"') >= 0)
	{
		alert ("Double Quotes are not allowed.\nPlease adjust this City value.")	
		form.City.focus()
		return false;
	}	

	if (State == "") 
	{
		alertmsg = alertmsg + ("- your STATE is required\n")
	}
	if (Zip_Code == "") 
	{
		alertmsg = alertmsg + ("- your ZIP is required\n")
	}
	
	if (Zip_Code.indexOf('"') >= 0)
	{
		alert ("Double Quotes are not allowed.\nPlease adjust this Zip Code value.")	
		form.Zip_Code.focus()
		return false;
	}
	
	if (Country == "") 
	{
		alertmsg = alertmsg + ("- your COUNTRY is required\n")
	}
	if (Email == "") 
	{
		alertmsg = alertmsg + ("- your EMAIL ADDRESS is required\n")
	}
	if (Email.indexOf('"') >= 0)
	{
		alert ("Double Quotes are not allowed.\nPlease adjust this Email value.")	
		form.Email.focus()
		return false;
	}

	if ((Phone_Area_Code.indexOf('"') >= 0)||(Phone_Exchange.indexOf('"') >= 0)||(Phone_Number.indexOf('"') >= 0))
	{
		alert ("Double Quotes are not allowed.\nPlease adjust this Phone value.")	
		form.Phone_Area_Code.focus()
		return false;
	}

	if (Installation_Company_Name.indexOf('"') >= 0)
	{
		alert ("Double Quotes are not allowed.\nPlease adjust this Installation Company Name value.")	
		form.Installation_Company_Name.focus()
		return false;
	}
	
	if (alertmsg!="") 
	{
		alert("Incorrect Information: \n\n" + alertmsg + "\nPlease return to the form and correct your information.\n\nThank You.\n")
		alertmsg = ""
		return false
	}
	return true;
	//return false;

}

function fnCheckProductSupportForm(form)
{
    str_Where_Purchased = (form.Where_Purchased.options[form.Where_Purchased.selectedIndex].value)
    //alert ("str_Where_Purchased=" + str_Where_Purchased)
	if (str_Where_Purchased == '')
	{
        alert ("Please select where you have purchased your garage door before continuing.") 
    	form.Where_Purchased.focus()
    	return false
	
	}
	return true;
}

function confirm_Reg_Back(form) 
{
    //alert ("action=" + form.action)
    // form.action = "/warranty_registration.html"
    //alert ("action2=" + form.action)
    form.submit()
    //return false;
    return true;

}

function confirm_Claim_Back(form) 
{

    //alert ("action=" + form.action)
    Registration_ID = form.Registration_ID.value
    form.action = "/submit_a_claim.html?Registration_ID=" + Registration_ID
    //alert ("action2=" + form.action)
    form.submit()
    //return false;
    return true;

}

function parseValues(form)
{
    First_Name = form.First_Name.value;
    Last_Name = form.Last_Name.value;
    Address_Line1 = form.Address_Line1.value;
    Address_Line2 = form.Address_Line2.value;
    City = form.City.value;
    State = form.State.value;
    Zip_Code = form.Zip_Code.value;
    Country = form.Country.value;
    Email = form.Email.value;
    Phone_Area_Code = form.Phone_Area_Code.value;
    Phone_Exchange = form.Phone_Exchange.value;
    Phone_Number = form.Phone_Number.value;
    Where_Purchased = form.Where_Purchased.value;
    Model_Purchased = form.Model_Purchased.value;
    When_Purchased_Month = form.When_Purchased_Month.value;
    When_Purchased_Year = form.When_Purchased_Year.value;
    Installation_Type = form.Installation_Type.value;
    Installation_Company_Name = form.Installation_Company_Name.value;

    First_Name = First_Name.replace(/'/g,"''");
	form.First_Name_Parsed.value = First_Name;
	//alert ("form.First_Name_Parsed.value=" + form.First_Name_Parsed.value) 

    Last_Name = Last_Name.replace(/'/g,"''");
	form.Last_Name_Parsed.value = Last_Name;
	//alert ("form.Last_Name_Parsed.value=" + form.Last_Name_Parsed.value) 

    Address_Line1 = Address_Line1.replace(/'/g,"''");
	form.Address_Line1_Parsed.value = Address_Line1;
	//alert ("form.Address_Line1_Parsed.value=" + form.Address_Line1_Parsed.value) 

    Address_Line2 = Address_Line2.replace(/'/g,"''");
	form.Address_Line2_Parsed.value = Address_Line2;
	//alert ("form.Address_Line2_Parsed.value=" + form.Address_Line2_Parsed.value) 

    City = City.replace(/'/g,"''");
	form.City_Parsed.value = City;
	//alert ("form.City_Parsed.value=" + form.City_Parsed.value) 

    State = State.replace(/'/g,"''");
	form.State_Parsed.value = State;
	//alert ("form.State_Parsed.value=" + form.State_Parsed.value) 

    Zip_Code = Zip_Code.replace(/'/g,"''");
	form.Zip_Code_Parsed.value = Zip_Code;
	//alert ("form.Zip_Code_Parsed.value=" + form.Zip_Code_Parsed.value) 

    Country = Country.replace(/'/g,"''");
	form.Country_Parsed.value = Country;
	//alert ("form.Country_Parsed.value=" + form.Country_Parsed.value) 

    Email = Email.replace(/'/g,"''");
	form.Email_Parsed.value = Email;
	//alert ("form.Email_Parsed.value=" + form.Email_Parsed.value) 

    Phone_Area_Code = Phone_Area_Code.replace(/'/g,"''");
	form.Phone_Area_Code_Parsed.value = Phone_Area_Code;
	//alert ("form.Phone_Area_Code_Parsed.value=" + form.Phone_Area_Code_Parsed.value) 

    Phone_Exchange = Phone_Exchange.replace(/'/g,"''");
	form.Phone_Exchange_Parsed.value = Phone_Exchange;
	//alert ("form.Phone_Exchange_Parsed.value=" + form.Phone_Exchange_Parsed.value) 

    Phone_Number = Phone_Number.replace(/'/g,"''");
	form.Phone_Number_Parsed.value = Phone_Number;
	//alert ("form.Phone_Number_Parsed.value=" + form.Phone_Number_Parsed.value) 

    Where_Purchased = Where_Purchased.replace(/'/g,"''");
	form.Where_Purchased_Parsed.value = Where_Purchased;
	//alert ("form.Where_Purchased_Parsed.value=" + form.Where_Purchased_Parsed.value) 

    Model_Purchased = Model_Purchased.replace(/'/g,"''");
	form.Model_Purchased_Parsed.value = Model_Purchased;
	//alert ("form.Model_Purchased_Parsed.value=" + form.Model_Purchased_Parsed.value) 

    When_Purchased_Month = When_Purchased_Month.replace(/'/g,"''");
	form.When_Purchased_Month_Parsed.value = When_Purchased_Month;
	//alert ("form.When_Purchased_Month_Parsed.value=" + form.When_Purchased_Month_Parsed.value) 

    When_Purchased_Year = When_Purchased_Year.replace(/'/g,"''");
	form.When_Purchased_Year_Parsed.value = When_Purchased_Year;
	//alert ("form.When_Purchased_Year_Parsed.value=" + form.When_Purchased_Year_Parsed.value) 

    Installation_Type = Installation_Type.replace(/'/g,"''");
	form.Installation_Type_Parsed.value = Installation_Type;
	//alert ("form.Installation_Type_Parsed.value=" + form.Installation_Type_Parsed.value) 

    Installation_Company_Name = Installation_Company_Name.replace(/'/g,"''");
	form.Installation_Company_Name_Parsed.value = Installation_Company_Name;
	//alert ("form.Installation_Company_Name_Parsed.value=" + form.Installation_Company_Name_Parsed.value) 

    //return false;
    return true;


}

function submitClaimID(form)
{
    
    //here check if ID is numeric

	//alert ("form.Registration_ID.value =" + form.Registration_ID.value)
	//alert ("Is Number? =" + isNaN(form.Registration_ID.value))
    if (isNaN(form.Registration_ID.value))
    {
		alert ("Registration confirmation numbers should be numeric. Please try again.")
	    form.Registration_ID.focus()
	    return false;
    
    }
    
    my_action = form.action + "?Registration_ID=" + form.Registration_ID.value;
    form.action = my_action

    //return false;
    return true;

}

function populateModels(form)
{
    var str_parse_Models = ""
    str_Where_Purchased = (form.Where_Purchased.options[form.Where_Purchased.selectedIndex].value)
    //alert ("str_Where_Purchased=" + str_Where_Purchased)
    
    str_Models_Purchased=form.Model_Purchased_Values.value
    //alert ("str_Models_Purchased=" + str_Models_Purchased)
    
    where_String = "#" + str_Where_Purchased + "#"
    where_Marker = str_Models_Purchased.indexOf(where_String)

    //alert ("where_Marker=" + where_Marker)
    
    if (where_Marker >= 0)
    {
        where_Length = where_String.length

        //alert ("where_Length=" + where_Length)
        
        str_parse_Models = str_Models_Purchased.substr(where_Marker+where_Length)
        //alert ("str_parse_Models=" + str_parse_Models)
        
        if (str_parse_Models.indexOf("#") >=0)
        {
            str_parse_Models = str_parse_Models.substr(0,str_parse_Models.indexOf("#"))    
        }
        
        //alert ("str_parse_Models2=*" + str_parse_Models +"*")
        //str_parse_Models = str_parse_Models.replace(/^(.*)[ ]+$/, '$1') // Trims trailing spaces
        str_parse_Models = str_parse_Models.replace(/\r\n|\r|\n/g,'')
        //alert ("str_parse_Models3=*" + str_parse_Models +"*")

    //    str_parse_Models = str_parse_Models.replace(/\r\n/g,'')
        str_parse_Models = trimString(str_parse_Models)

        //alert ("str_parse_Models4=*" + str_parse_Models +"*")
    
    }
    //alert ("str_parse_Models=*" + str_parse_Models +"*")
    //now split the array
    //clean up options box and populate with new values
    clearOptions(form.Model_Purchased);
    if (str_parse_Models.length > 0)
    {
        //add a value to make the first one blank
        str_parse_Models = "|" + str_parse_Models
    
        //alert ("In IF")
        array_OptionValues = str_parse_Models.split("|")
        for (j=0;j<array_OptionValues.length;j++)
        {
            //alert("Adding Option: " + array_OptionValues[j])
            addOption(form.Model_Purchased, array_OptionValues[j], array_OptionValues[j]) 
        }
        
    }
}

function trimString(str)
{

    while('' + str.charAt(0) == ' ')
    {
        str=str.substring(1,str.length);
    }
    while('' + str.charAt(str.length-1) == ' ')
    {
        str=str.substring(0,str.length-1);
    }
    return str;
}


function clearOptions(OptionList) 
{

   // Always clear an option list from the last entry to the first
   for (x = OptionList.length; x >= 0; x = x - 1) {
      OptionList[x] = null;
   }

}

function addOption(OptionList, OptionValue, OptionText) 
{
   // Add option to the bottom of the list
   OptionList[OptionList.length] = new Option(OptionText, OptionValue);
}

function getDocuments()
{
    //alert ("action 1 =" + document.submit_claim.action)
    my_action = "/warranty_documents.html";
    document.submit_claim.action = my_action
    //alert ("action 2 =" + document.submit_claim.action)
	document.submit_claim.submit()
    return true;
}

//Using this function to clear selected Where Purchased when browser uses back button
function checkModel()
{
    

    form1 = document.forms["product_support_form"]
    if (form1)
    {
        // alert ("product_support_form exists")
        if (form1.Where_Purchased)
        {
            // alert ("Where_Purchased = *" + form1.Where_Purchased.options[form1.Where_Purchased.selectedIndex].value + "*")
            // alert ("Model_Purchased.length = *" + form1.Model_Purchased.length + "*")
            if (form1.Model_Purchased)
            {
                if (form1.Model_Purchased.length == 0)
                {
                    for(intIndex = 0; intIndex < form1.Where_Purchased.length; intIndex++ )
                    {
                        if( form1.Where_Purchased.options[intIndex].value == '') 
                        {
                            form1.Where_Purchased.selectedIndex = intIndex;
                            break;
                        }
                    }
                }        
            }
        }
    }

    form2 = document.forms["warranty_registration_form"]
    if (form2)
    {
        //alert ("warranty_registration_form exists")
        if (form2.Where_Purchased)
 
        {
            //alert ("Where_Purchased = *" + form2.Where_Purchased.options[form2.Where_Purchased.selectedIndex].value + "*")
            //alert ("Model_Purchased.length = *" + form2.Model_Purchased.length + "*")
            if (form2.Model_Purchased.length == 0)
            {
                if (form2.Model_Purchased)
                {
                    for(intIndex = 0; intIndex < form2.Where_Purchased.length; intIndex++ )
                    {
                        if(form2.Where_Purchased.options[intIndex].value == '') 
                        {
                            form2.Where_Purchased.selectedIndex = intIndex;
                            break;
                        }
                    }
                }
            }        
        }
    }

}
