function getQueryString(variable) {	var query = window.location.search.substring(1);	var vars = query.split("&");	for (var i=0; i<vars.length; i++) {		var pair = vars[i].split("=");		if (pair[0] == variable) {			return pair[1];		}	}}function initWarrantyForm () {	var form = $('WarrantyForm');	$extend (form, new WarrantyController ());	form.initialize ();}// Use an instance of this object to extend the warranty form in the domready event : $extend ($('WarrantyForm'), new WarrantyController ())var WarrantyController = new Class({  	//implements  	Implements: [Options],  	//options  	options: {		// Language selector: EN for English, ES for Spanish		language: 'EN',		// Dummy element to prevent comma errors		terminator: null	},		// Reference to the form tag set in intialize	form: null,	// Reference to the category selector	inputCategory: null,	// Reference to the category description	inputDescription: null,	// Reference to the div that will contain the request items	issuesContainer: null,	// Reference to the default div that appears when there are no other issues	defaultIssue: null,	//initialization  	initialize: function(options) {  		//set options  		this.setOptions(options);		this.form = $('WarrantyForm');		this.inputCategory = $('inputRequestCategory');		this.inputDescription = $('inputRequestDescription');		this.issuesContainer = $('WarrantyIssuesContainer');		this.issuesTemplate = '<div id="{id}"><div class="Controls"></div><div class="Category">{category}</div><div class="Description">{description}</div></div>';		this.defaultIssue = $('WarrantyIssuesDefault');	},  		// Confirmation message to display on submit	getConfirmationText: function () {		if (this.options.language == 'ES') 	return 'Nosotros apreciamos la oportunidad de proveerle con el mejor nivel de servicio al cliente posible, y estamos muy orgullosos de poder hacerlo en un tiempo aceptable. Para asegurar una respuesta r\u00E1pida, por favor verifique su horario antes de enviar su solicitud para que asi podamos concertar una cita en su casa y dedicarnos a sus asuntos.';		else return 'We appreciate the opportunity to provide you with the highest level of customer service possible, and take great pride in doing so in a timely manner. To ensure a prompt response to your request, please check your schedule prior to submitting your service request so that we may conveniently meet with you at your home to address all issues. ';	},	onsubmit: function () {		if (this.inputDescription.value != '')			if (!this.addIssue ()) return false; 		if (!this.validate()) return false;		if (!this.writeBackendValues()) return false;		if (!confirm (this.getConfirmationText())) return false; 		return true;	},		// These are used to hold the back-end values that will be sent upon submission	requestListValues: [],	codeInfoValues: [],	writeBackendValues: function () {		this.form.oRequestList.value = this.requestListValues.join('>><<');		this.form.codeinfo.value = this.codeInfoValues.join(';');			if (this.form.oRequestList.value == '') {			 alert ('You have not yet entered any warranty items.  (Even a brief description will help.)');			 return false;		}		return true;	},		// Validate the currently entered warranty issue, and if valid, add it to the list.  	addIssue: function() {		// Make sure that values have been entered in the appropriate fields		if (this.inputCategory.selectedIndex == 0) {			alert("Please select a category for this warranty issue.");			this.inputCategory.focus();			return false;		}		if (this.inputDescription.value == '') {			alert("Please describe the warranty issue.");			this.inputDescription.focus();			return false;		}		// Push the field values onto the appropriate arrays		var categorySelected = this.inputCategory.options[this.inputCategory.selectedIndex];		this.requestListValues.push (categorySelected.text + '^' + this.inputDescription.value);		this.codeInfoValues.push (categorySelected.value);		this.update ();		// Clear the fields		this.inputDescription.value ='';		this.inputCategory.selectedIndex =0;		return true;	},	// Template string of a request item's HTML as it should appear in the request container	// use {Category} and {Description} for the keywords to be replaced by user-specified values.	// Set during initialization	issuesTemplate: null,	// Update the display of the warranty issues list	update: function () {		if (this.requestListValues.length >0) this.defaultIssue.dispose();		this.requestListValues.each (function(issue, index) {			// Try to get the current warranty issue			var item = $('WarrantyIssue'+index);			if (item == null) {				var enteredValues = issue.split ('^');				var newValues = {id:'WarrantyIssue'+index, category:enteredValues[0], description: enteredValues[1]};				var newElement = new Element('div', {html: this.issuesTemplate.substitute(newValues)});				newElement.inject (this.issuesContainer, 'bottom');			} else {			}		}, this);	},		clear: function () {		this.form.oFirstName.value='';		this.form.oLastName.value='';		this.form.oAddress.value='';		this.form.oCity.value='';		this.form.oState.value='';		this.form.oZip.value='';		this.form.oEmail.value='';		this.form.oHomePhone.value='';		this.form.oWorkPhone.value='';		this.form.oWhoseWorkPhone.value='';		this.form.oOtherPhone.value='';		this.form.oWhoseOtherPhone.value='';		this.form.oRequestList.value='';	},	validate: function () {		if (this.form.Market && this.form.Market.options) {			if (this.form.Market.selectedIndex == 0) {				alert("Please choose a metropolitan area.");				this.form.Market.focus();				return false;			}		}		return (			checkString(this.form.oFirstName,sUSFirstName) &&			checkString(this.form.oLastName,sUSLastName) &&			checkString(this.form.oAddress,sUSAddress) &&			checkString(this.form.oCity,sCity) &&			checkString(this.form.oState, sStateCode) &&			checkZIPCode(this.form.oZip) &&			checkEmail(this.form.oEmail) &&			checkUSPhone(this.form.oHomePhone) /*&&			checkUSPhone(this.form.oWorkPhone) &&			checkString(this.form.oWhoseWorkPhone, sWhoseWork)*/		);	},		// Dummy element to prevent comma errors	terminator: null});  var digits = "0123456789";var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz";var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";var whitespace = " \t\n\r";var decimalPointDelimiter = ".";var phoneNumberDelimiters = "()- ";var validUSPhoneChars = digits + phoneNumberDelimiters;var validWorldPhoneChars = digits + phoneNumberDelimiters + "+";var SSNDelimiters = "- ";var validSSNChars = digits + SSNDelimiters;var digitsInSocialSecurityNumber = 9;var digitsInUSPhoneNumber = 10;var ZIPCodeDelimiters = "-";var ZIPCodeDelimeter = "-";var validZIPCodeChars = digits + ZIPCodeDelimiters;var digitsInZIPCode1 = 5;var digitsInZIPCode2 = 9;var creditCardDelimiters = " ";var mPrefix = "Please enter a ";var mSuffix = ". (This is a required field.)";var sUSLastName = "Last Name";var sUSFirstName = "First Name";var sUSAddress = "Street Address";var sWorldAddress = "Address";var sCity = "City";var sStateCode = "State Code";var sZIPCode = "ZIP Code";var sPhone = "Phone Number";var sEmail = "Email";var sWhoseWork = "Whose Work Phone";var iZIPCode = "Please enter a 5 or 9 digit U.S. ZIP Code (e.g. 94043).";var iUSPhone = "Please enter a 10 digit U.S. phone number (e.g. 415 555 1212).";var iEmail = "Please enter a valid email address (e.g. username@something.com).";var iSelection = "Please select one of the options listed.";var pEntryPrompt = "Please enter a ";var pStateCode = "2 character code (like CA).";var pZIPCode = "5 or 9 digit U.S. ZIP Code (e.g. 94043).";var pUSPhone = "10 digit U.S. phone number (e.g. 415 555 1212).";var pWorldPhone = "international phone number.";var pEmail = "valid email address (like foo@bar.com).";var defaultEmptyOK = falsefunction makeArray(n) {	for (var i = 1; i <= n; i++) {		this[i] = 0	}	return this}function isEmpty(s) {	return ((s == null) || (s.length == 0))}function isWhitespace (s) {	var i;	if (isEmpty(s)) return true;	for (i = 0; i < s.length; i++) {   		var c = s.charAt(i);		if (whitespace.indexOf(c) == -1) return false;	}	return true;}function stripCharsInBag (s, bag){   var i;    var returnString = "";    for (i = 0; i < s.length; i++)    {           var c = s.charAt(i);        if (bag.indexOf(c) == -1) returnString += c;    }    return returnString;}function stripCharsNotInBag (s, bag){   var i;    var returnString = "";    for (i = 0; i < s.length; i++)    {           var c = s.charAt(i);        if (bag.indexOf(c) != -1) returnString += c;    }    return returnString;}function stripWhitespace (s){   return stripCharsInBag (s, whitespace)}function charInString (c, s){   for (i = 0; i < s.length; i++)    {   if (s.charAt(i) == c) return true;    }    return false}function stripInitialWhitespace (s){   var i = 0;    while ((i < s.length) && charInString (s.charAt(i), whitespace))       i++;        return s.substring (i, s.length);}function isLetter (c){   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )}function isDigit (c){   return ((c >= "0") && (c <= "9"))}function isLetterOrDigit (c){   return (isLetter(c) || isDigit(c))}function isInteger (s){   var i;    if (isEmpty(s))        if (isInteger.arguments.length == 1) return defaultEmptyOK;       else return (isInteger.arguments[1] == true);    for (i = 0; i < s.length; i++)    {           var c = s.charAt(i);        if (!isDigit(c)) return false;    }    return true;}function isSignedInteger (s){   if (isEmpty(s))        if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;       else return (isSignedInteger.arguments[1] == true);    else {        var startPos = 0;        var secondArg = defaultEmptyOK;        if (isSignedInteger.arguments.length > 1)            secondArg = isSignedInteger.arguments[1];        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )           startPos = 1;            return (isInteger(s.substring(startPos, s.length), secondArg))    }}function isPositiveInteger (s){   var secondArg = defaultEmptyOK;    if (isPositiveInteger.arguments.length > 1)        secondArg = isPositiveInteger.arguments[1];    return (isSignedInteger(s, secondArg)         && ( (isEmpty(s) && secondArg)  || (parseInt (s) > 0) ) );}function isNonnegativeInteger (s){   var secondArg = defaultEmptyOK;    if (isNonnegativeInteger.arguments.length > 1)        secondArg = isNonnegativeInteger.arguments[1];    return (isSignedInteger(s, secondArg)         && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );}function isNegativeInteger (s){   var secondArg = defaultEmptyOK;    if (isNegativeInteger.arguments.length > 1)        secondArg = isNegativeInteger.arguments[1];    return (isSignedInteger(s, secondArg)         && ( (isEmpty(s) && secondArg)  || (parseInt (s) < 0) ) );}function isNonpositiveInteger (s){   var secondArg = defaultEmptyOK;    if (isNonpositiveInteger.arguments.length > 1)        secondArg = isNonpositiveInteger.arguments[1];    return (isSignedInteger(s, secondArg)         && ( (isEmpty(s) && secondArg)  || (parseInt (s) <= 0) ) );}function isFloat (s){   var i;    var seenDecimalPoint = false;    if (isEmpty(s))        if (isFloat.arguments.length == 1) return defaultEmptyOK;       else return (isFloat.arguments[1] == true);    if (s == decimalPointDelimiter) return false;    for (i = 0; i < s.length; i++)    {           var c = s.charAt(i);        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;        else if (!isDigit(c)) return false;    }    return true;}function isSignedFloat (s){   if (isEmpty(s))        if (isSignedFloat.arguments.length == 1) return defaultEmptyOK;       else return (isSignedFloat.arguments[1] == true);    else {        var startPos = 0;        var secondArg = defaultEmptyOK;        if (isSignedFloat.arguments.length > 1)            secondArg = isSignedFloat.arguments[1];        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )           startPos = 1;            return (isFloat(s.substring(startPos, s.length), secondArg))    }}function isAlphabetic (s){   var i;    if (isEmpty(s))        if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;       else return (isAlphabetic.arguments[1] == true);    for (i = 0; i < s.length; i++)    {           var c = s.charAt(i);        if (!isLetter(c))        return false;    }    return true;}function isAlphanumeric (s){   var i;    if (isEmpty(s))        if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;       else return (isAlphanumeric.arguments[1] == true);    for (i = 0; i < s.length; i++)    {           var c = s.charAt(i);        if (! (isLetter(c) || isDigit(c) ) )        return false;    }    return true;}function reformat (s){   var arg;    var sPos = 0;    var resultString = "";    for (var i = 1; i < reformat.arguments.length; i++) {       arg = reformat.arguments[i];       if (i % 2 == 1) resultString += arg;       else {           resultString += s.substring(sPos, sPos + arg);           sPos += arg;       }    }    return resultString;}function isUSPhoneNumber (s){   if (isEmpty(s))        if (isUSPhoneNumber.arguments.length == 1) return defaultEmptyOK;       else return (isUSPhoneNumber.arguments[1] == true);    return (isInteger(s) && s.length == digitsInUSPhoneNumber)}function isZIPCode (s){  if (isEmpty(s))        if (isZIPCode.arguments.length == 1) return defaultEmptyOK;       else return (isZIPCode.arguments[1] == true);   return (isInteger(s) &&             ((s.length == digitsInZIPCode1) ||             (s.length == digitsInZIPCode2)))}function isEmail (s){   if (isEmpty(s))        if (isEmail.arguments.length == 1) return defaultEmptyOK;       else return (isEmail.arguments[1] == true);       if (isWhitespace(s)) return false;        var i = 1;    var sLength = s.length;    while ((i < sLength) && (s.charAt(i) != "@"))    { i++    }    if ((i >= sLength) || (s.charAt(i) != "@")) return false;    else i += 2;    while ((i < sLength) && (s.charAt(i) != "."))    { i++    }    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;    else return true;}function isIntegerInRange (s, a, b){   if (isEmpty(s))        if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;       else return (isIntegerInRange.arguments[1] == true);    if (!isInteger(s, false)) return false;    var num = parseInt (s);    return ((num >= a) && (num <= b));}function prompt (s){   window.status = s}function promptEntry (s){   window.status = pEntryPrompt + s}function warnEmpty (theField, s){   theField.focus()    alert(mPrefix + s + mSuffix)    return false}function warnInvalid (theField, s){   theField.focus()    theField.select()    alert(s)    return false}function checkString (theField, s, emptyOK){    if (checkString.arguments.length == 2) emptyOK = defaultEmptyOK;    if ((emptyOK == true) && (isEmpty(theField.value))) return true;    if (isWhitespace(theField.value))        return warnEmpty (theField, s);    else return true;}function reformatZIPCode (ZIPString){   if (ZIPString.length == 5) return ZIPString;    else return (reformat (ZIPString, "", 5, "-", 4));}function checkZIPCode (theField, emptyOK){   if (checkZIPCode.arguments.length == 1) emptyOK = defaultEmptyOK;    if ((emptyOK == true) && (isEmpty(theField.value))) return true;    else    { var normalizedZIP = stripCharsInBag(theField.value, ZIPCodeDelimiters)      if (!isZIPCode(normalizedZIP, false))          return warnInvalid (theField, iZIPCode);      else       {          theField.value = reformatZIPCode(normalizedZIP)         return true;      }    }}function reformatUSPhone (USPhone){   return (reformat (USPhone, "", 3, "-", 3, "-", 4))}function checkUSPhone (theField, emptyOK){   if (checkUSPhone.arguments.length == 1) emptyOK = defaultEmptyOK;    if ((emptyOK == true) && (isEmpty(theField.value))) return true;    else    {  var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters)       if (!isUSPhoneNumber(normalizedPhone, false))           return warnInvalid (theField, iUSPhone);       else        {          theField.value = reformatUSPhone(normalizedPhone)          return true;       }    }}function checkSelectField (theField, nullElement) {	if ((theField.selectedIndex == null) || (theField.selectedIndex == nullElement)) {		return warnInvalid (theField, iSelection);	}}function checkEmail (theField, emptyOK){   if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK;    if ((emptyOK == true) && (isEmpty(theField.value))) return true;    else if (!isEmail(theField.value, false))        return warnInvalid (theField, iEmail);    else return true;}
