﻿/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Timestamp 5/20/2009 10:40 PM

/********************************************************************************
PURPOSE: JavaScript does not contain a String.trim() function that I know of.
This adds my own String.trim() to the String object.
Note: This must be physically located in the page above where it is first used.
*********************************************************************************/
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }


//Campaign Tracking Code, switches out the content based on the campaign variable
//IS CASE SENSITIVE
function campaignPhone(pTerr){
	var src = readCookie('Closet Tailors');
	
	//Default Variables
	pnUS = '(800) 750-2567';
	pnCAN = '(888) 472-5673';
	
	var sFinancingHeadline = "12 Months Zero Interest Financing Available";
	var sFinancingLegal = "*At participating franchises only. No monthly payments and no interest if paid within promotional period. On promo purchase, no monthly payments required, and no finance charges assessed if (1) promo purchase is paid in full within promotional period, (2) any minimum monthly payments on account paid when due, and (3) account balance does not exceed credit limit. Otherwise, promo may be terminated and finance charges assessed from purchase date. Applies to purchases made on your Closet Tailors credit card account. Standard terms apply to non-promo purchases, optional charges, and existing accounts. As of 12/1/08, variable APRs: 21.98% & on all accounts in default, 29.99%. Minimum Finance Charge is $2.00. Subject to approval by GE Money Bank.";

	//Link phone numbers with campaign variables
	switch(src){

	case 'cake':
		pnUS = '(866) 638-CAKE';
		sFinancingHeadline = "No Financing for You";
	break;	
	
	case 'CTDex':
		pnUS = '(866) 638-9215';
	break;	
	
	default:
	
	}
	
	
	//Check which country, write out appropriate phone number
	switch(pTerr){
		
	case 'US':
		return(pnUS);
	break;
		
	case 'CAN':
		return(pnCAN);
	break;

	case 'sFinancingHeadline':
		return(sFinancingHeadline);
	break;

	case 'sFinancingLegal':
		return(sFinancingLegal);
	break;

	default:
	}
}

//Campaign WEB Tracking Code

//Check for a query string
if (document.URL.indexOf("?") != -1){
	//Check for and store query string variable "src"
	var source = getQueryVariable("src");
	createCookie('Closet Tailors',source,30);
}

//Write out campaign variable as a hidden form field
function returnSource(){
	var src = readCookie('Closet Tailors');
	document.write('<input name="src" type="hidden" value="'+src+'" />')
}

function getQueryVariable(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 createCookie(name,value,days) {
		if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie('Closet Tailors',"",-1);
}

function getIB(){
getTestimonials(2);
document.write('<div class="hr2"></div>');
document.write('<div class="sub_box ib2"><div class="inspiration_bin"><h2><a href="/blog/">Inspiration Bin - Home<br />Organization Blog</a></h2><h3 class="txt_white">A blog to organize your <br />home and life</h3><p class="visit"><a href="/blog/">Visit our blog</a></p></div></div><div class="hr2"></div>');	
}

function getFinancing(){
document.write('&nbsp;');	
}
function getRecent(){
document.write('<h2>Recent Articles</h2>');
document.write('<ul class="list_normal">');
document.write('<li>');
document.write('<h3><a href="/inspiration-bin/2008/08/organize-your-kids-playroom/">Organize Your Kids’ Playroom</a></h3>');
document.write('</li>');
document.write('<li>');
document.write('<h3><a href="/inspiration-bin/2008/07/environmentally-friendly-storage-solutions/index.html">Environmentally Friendly Storage Solutions</a></h3>');
document.write('</li>');
document.write('<li>');
document.write('<h3><a href="/inspiration-bin/2007/10/a-wardrobe-lift-brings-items-to-your-level/">A Wardrobe Lift Brings Items To Your Level</a></h3>');
document.write('</li>');
document.write('</ul>');
document.write('<h3><a href="/inspiration-bin/">See More Articles</a></h3>');
}

//This function writes out a list of testimonials on the sidebar page
function getTestimonials(myNum){
	
	var myList = new Array();
	//<p><em>QUOTE</em> <br /><strong>CUSTOMER</strong></p>
	myList[0] = '<p><em>I had a small closet off my laundry room that was in desperate need of organization. I called Closet Tailors and they turned my messy closet into a beautiful streamlined space. They were professional, affordable and had the job done on time.</em> <br /><strong>Lisa (Watkinsville, GA )</strong></p>';
	myList[1] = '<p><em>Our experience with Closet Tailors from start to finish was great. We are so pleased with the finished product - I don\'t see how we functioned before! Now all our clothes and "stuff" has a place - makes our lives so much easier...thanks Scott R.!</em> <br /><strong>Jean (Bogart, GA)</strong></p>';
	myList[2] = '<p><em>It was such a pleasure to work with Closet Tailors.  We were very happy with the options available to us and were amazed that options could be presented at the first visit...no waiting.</em> <br /><strong>Mike & Marquetta (Eagle Point, AL)</strong></p>';
	myList[3] = '<p><em>My thanks to all of you.  From my first phone call to the final installation - everyone was so helpful and so professional.  Closet Tailors did a beautiful job on the master closet and I cannot wait to invite them back for additional closet needs.</em> <br /><strong>Bobbi (Trussville, AL)</strong></p>';
	myList[4] = '<p><em>Thanks so much for the design and installation. It looks fantastic. My wife and I love it. As I show it off, I\'ll be sure to point people your way.</em> <br /><strong>John M. (Nashville, TN)</strong></p>';
	myList[5] = '<p><em>Good ideas. Easy to work with. Customer satisfaction excellent. Our closet has never been so organized. Installation was on time. Craftsmanship excellent.</em> <br /><strong>S.K. (Tampa, Fl)</strong></p>';
	myList[6] = '<p><em>Thank you for our beautiful closets! We wish all of our projects could go as smoothly. You asked great questions and delivered exactly what you said you would.</em> <br /><strong>Shawn S. (Richmond, VA)</strong></p>';
	myList[7] = '<p><em>We recently decided to organize our lives and have professionally constructed closets installed in our home.  We chose Closet Tailors and are so very pleased that we did!</em> <br /><strong>Herb & Betsy H. (Richmond, VA)</strong></p>';
	myList[8] = '<p><em>Closet Tailors was very professional, prompt, and a joy to work with.  We would recommend them to anyone.</em> <br /><strong>D. Wilson (Sherwood, OR)</strong></p>';
	myList[9] = '<p><em>I\'m so pleased with the quality of the materials used in transforming my garage into a suitable storage area.  The attention to detail in doing the work was outstanding. Thank you again for a beautiful job!  I\'d be happy to recommend Closet Tailors to anyone considering organizing thier home. </em> <br /><strong>L. Bradley (Wilsonville, OR)</strong></p>';
	myList[10] = '<p><em>Closet Tailors was a pleasure to work with from design to installation of my walk-in closet.  They created a closet that is both attractive and efficient.  The installation work was unobtrusive and completed in less than a day!  I recommend Closet Tailors to anyone who wants to get more out of their storage space.</em> <br /><strong>Kevin (Norfolk, VA)</strong></p>';
	
	document.write('<h2>Testimonials</h2>');

	//Picks a random quote from the array then deletes that entry. Loops a number of times specified by myVar
	for (i=0;i<myNum;i++)
		{
			myVar = [Math.floor(Math.random()*myList.length)];
			document.write(myList[myVar]);
			myList.splice(myVar,myVar);
			
		}
}


//Zero out postal codes/repop//////////////////////////////
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_setTextOfTextfield(objName,x,newText) { //v3.0
  var obj = MM_findObj(objName);
  if (obj.value == "" || newText == ""){
    if (obj)
         obj.value = newText;
  }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function readout(){
	document.write('Text Size : ');
	document.write('<span><a href="#" onclick="setActiveStyleSheet(\'master\'); return false;">Normal</a></span> ');
	document.write('<span><a href="#" onclick="setActiveStyleSheet(\'alt\'); return false;">Large</a></span>');
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');

  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
/* Commented out 5/29. Form validation handled by vf.js now
function validateForm() {
	var i,p,q,nm,prntNm,test,num,min,max,testr,errors='',args=validateForm.arguments;
	for (i=0; i < (args.length-2); i += 3) {	//	Loop through every third value in the args		:BP
		test = args[i+2];						//	Set a var = the third arg						:BP
		fld = findObj(args[i]);				//	Get the object with the arg name				:BP
		if (fld) {
			nm = fld.name;
			prntNm = args[i+1];					//	Set a var = the second arg name, I added this as the printable Name		:BP
			if (prntNm == "")	prntNm = nm;	//	Set printable name to arg Name if not provided
			if ((val = fld.value) != "") {
				if (test.indexOf('isEmail') != -1) {
					p = val.indexOf('@');
					if (p < 1 || p == (val.length - 1))
						errors += '- ' + prntNm + ' must contain an e-mail address.\n';
				} else if (test.indexOf('cPass') != -1) {
					p = test.indexOf(':');
					testr = test.substring(p+1);
					val2 = findObj(testr);
					if (val != val2.value)
						errors += '- Password fields do not match.\n';
				} else if (test == 'C') {
					if (fld.checked != true) errors += '- ' + prntNm + '\n';
				} else if (test != 'R') {
					num = parseFloat(val);
					if (isNaN(val)) errors += '- ' + prntNm + ' must contain a number.\n';
					if (test.indexOf('inRange') != -1) {
						p = test.indexOf(':');
						min = test.substring(8,p);
						max = test.substring(p+1);
						if (num < min || max < num)
							errors += '- ' + prntNm + ' must contain a number between ' + min + ' and ' + max + '.\n';
					}
				}
			} else if (test.charAt(0) == 'R') errors += '- ' + prntNm + ' is required.\n';
		}
	}
	if (errors)
		alert('The following information is required:\n' + errors);
	document.MM_returnValue = (errors == '');
}
*/
function popAnyHelp(strURL, strWinName, strParams) {
	var winRUHelp = window.open(strURL, strWinName, strParams);
	if(!winRUHelp) {
		alert("This HFC site has detected that you are using a popup blocker.\nPlease add this site to your trusted sites list or disable your popup blocker.\n\nThank you.");
	}
	winRUHelp.focus();
}