//Newsletter Signup
var newsletterModal;
function newsletterSignup(anchor) {

	var boxname = "Newsletter"||anchor.title;
	var page = "/newsletter/index.jsp"||anchor.href;
	var width = 460;
	var height = 481;
	var isReady = (typeof dhtmlwindow=="undefined")?false:true;

	newsletterModal=dhtmlmodal.open(boxname, 'iframe', page, 'Signup', 'width='+width+'px,height='+height+'px,center=1,resize=0,scrolling=1,frameBorder=0');
	newsletterModal.onclose=function(){ //Define custom code to run when window is closed
			return true //allow closing of window
	}
	pageTracker._trackPageview('/devine/newsletter/index.jsp');
	return;
}
// Button Rollover Code
function rollOverNew(imgID, imgName) {
	document.getElementById(imgID).setAttribute('src', imgName);
}
function randomBanner(prefix) {
	if (prefix == 'Testimonials'){
		var imgName = "/devine/images/banners/hdr_03.jpg";
		document.write('<img src="' + imgName + '" alt="" />');
	}
	else {
		var imgNames = new Array(2);
		imgNames[0] = "/devine/images/banners/" + prefix + "hdr_01.jpg";
		imgNames[1] = "/devine/images/banners/" + prefix + "hdr_02.jpg";
		var al = imgNames.length;
		var randNum = Math.floor(al * Math.random());
		document.write('<img src="' + imgNames[randNum] + '" alt="" />');
	}
}
function randomHomeBanner(prefix,index) {
	var imgNames = [];
	imgNames.push(prefix + "/res/home.swf");
	//imgNames.push(prefix + "/res/home1.swf");
	imgNames.push(prefix + "/res/home2.swf");
	//imgNames.push(prefix + "/res/home3.swf");
	imgNames.push(prefix + "/res/home4.swf");
	//imgNames[1] = "/devine/images/banners/" + prefix + "home2.swf";
	var al = imgNames.length;
	var randNum = (index==undefined)?Math.floor(al * Math.random()):index;
	return imgNames[randNum];
	//document.write('<img src="' + imgNames[randNum] + '" alt="" />');
}
function getParam(name) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
		return "";
	else
		return results[1];
}
// Toggle Collections calculator on/off
function toggleCalculator(wheel) {
	var getCalcBtnOff = document.getElementById(wheel + '_calcbtnoff');
	var getCalcBtnOn = document.getElementById(wheel + '_calcbtnon');
	var getCalc = document.getElementById(wheel + '_calc');
	if( getCalcBtnOn.style.display.indexOf('none')>=0 ) {
		getCalcBtnOff.style.display = 'none';
		getCalcBtnOn.style.display = 'block';
		getCalc.style.display = 'block';
	}
	else {
		getCalcBtnOff.style.display = 'block';
		getCalcBtnOn.style.display = 'none';
		getCalc.style.display = 'none';
	}
}
// Toggle Collections calculator on/off
function togglePainInfoFootnotes() {
	var getFootnoteDiv = document.getElementById('piLearnMoreFootnotes');
	var getBottomOff = document.getElementById('piBottomOff');
	var getBottomOn = document.getElementById('piBottomOn');
	try {
		var str = getFootnoteDiv.getAttribute('style').toLowerCase();
		if ((str).toLowerCase().indexOf('display: none') != -1) {
			getBottomOff.setAttribute('style', 'display: none;');
			getFootnoteDiv.setAttribute('style', 'display: block;');
			getBottomOn.setAttribute('style', 'display: block;');
		}
		else {
			getBottomOff.setAttribute('style', 'display: block;');
			getFootnoteDiv.setAttribute('style', 'display: none;');
			getBottomOn.setAttribute('style', 'display: none;');
		}
	}
	catch(e) {
		// JT: IE has problems getting attribute method sees as obj in ie7
		if (getFootnoteDiv.style.display.indexOf("none") != -1) {
			getBottomOff.style.display = "none";
			getFootnoteDiv.style.display = "block";
			getBottomOn.style.display = "block";
		}
		else {
			getBottomOff.style.display = "block";
			getFootnoteDiv.style.display = "none";
			getBottomOn.style.display = "none";
		}
	}
}
// Toggle photos for gallery
function togglePhoto(newClassName) {
	document.getElementById('galleryToggle').className = 'gio_' + newClassName;
}
// Functions for the Collections pages/tabs
var tcwc_default;
function chgLgWheelColor(wheel, colorName) {
	tcwc_default = document.getElementById('tcwc_' + wheel).innerHTML;
	document.getElementById('tcwc_' + wheel).innerHTML = colorName;
}
function setDefaultLgWheelColor(wheel) {
	document.getElementById('tcwc_' + wheel).innerHTML = tcwc_default;
}
function chgSwatchColor(wheel, swatch, colorName) {
	tcwc_default = colorName;
	document.getElementById('tcwc_' + wheel).innerHTML = colorName;
	document.getElementById('tcsc_' + wheel).innerHTML = colorName;
	document.getElementById('tcimg_' + wheel).setAttribute('src', '/devine/images/collections/swatch/' + wheel + '_' + swatch + '.jpg');
	var objLgWheel = document.getElementById('tcw_' + wheel);
	var getCurrentBg = null;
	try {
		getCurrentBg = objLgWheel.getAttribute('style'); //Moz
		objLgWheel.setAttribute('style', getCurrentBg.replace(/on_[0-9]+_of_/i, 'on_' + swatch + '_of_'));
	}
	catch(e) {
		// JT: IE has problems getting/setting attribute method
		getCurrentBg = document.getElementById('tcw_' + wheel).style.backgroundImage; //IE
		objLgWheel.style.backgroundImage = getCurrentBg.replace(/on_[0-9]+_of_/i, 'on_' + swatch + '_of_');
	}
	document.getElementById('buythis').elements['devineColor'].value = colorName;

}
function setColorName(colorName) {
	document.getElementById('buythis').elements['devineColor'].value = colorName;
}
var wl_default;
function chgWheelLabel(tab, header, description) {
	wl_default = document.getElementById(tab + '_wheel').innerHTML;
	var htmlHeader = '<h2>' + header + '</h2>';
	var htmlDescription = '<p class="wheelDescription">' + description + '</p>';
	document.getElementById(tab + '_wheel').innerHTML = htmlHeader + htmlDescription;
}
function setDefaultWheelLabel(tab) {
	document.getElementById(tab + '_wheel').innerHTML = wl_default;
}
function chgWheel(tab, header, description, color) {
	//alert('Color='+color);
	var htmlHeader = '<h2>' + header + '</h2>';
	var htmlDescription = '<p class="wheelDescription">' + description + '</p>';
	wl_default = htmlHeader + htmlDescription;
	document.getElementById(tab + '_wheel').innerHTML = htmlHeader + htmlDescription;
	document.getElementById('buythis').elements['devineColor'].value = color;
	resetBuyThis();
}
//form validation for exterior calculator form
function calcResults() {
	var PaintFactor = "400";
	var SurfaceArea;
	var GallonsReq;
	var Perimeter;
	var Height;
	var  f = document.calc;
	var errs = 0;
	var errMsg = ""
	var expr1;
	var Doors;
	var Windows;
	expr1 = /\D/g;
	if(f.Perimeter.value=="" | expr1.test(f.Perimeter.value)){
		errs += 1;
		errMsg += "Please enter a number for the room base " + "\n";
	}
	if(f.Height.value=="" | expr1.test(f.Height.value)){
		errs += 1;
		errMsg += "Please enter a number for the room height " + "\n";
	}
	if(!(f.Windows.value=="")){
		if(expr1.test(f.Windows.value)){
			errs += 1;
			errMsg += "Please enter a number for the number of average windows " + "\n";
		}
	}
	else {
		//default the field to 0
		f.Windows.value = 0;
	}
	if(!(f.Doors.value=="")){
		if(expr1.test(f.Doors.value)){
			errs += 1;
			errMsg += "Please enter a number for the number of average doors " + "\n";
		}
	}
	else {
		//default the field to 0
		f.Doors.value = 0;
	}
	if(!(f.Deduct.value=="")) {
		if(expr1.test(f.Deduct.value)){
			errs += 1;
			errMsg += "Please enter a number for the other deductions " + "\n";
		}
	}
	else {
		//default the field to 0
		f.Deduct.value = 0;
	}
	if(errs > 0){
		alert(errMsg);
		return false;
	}
	else {
		Windows = f.Windows.value * 15;
		Doors = f.Doors.value * 21;
		Height = f.Height.value;
		Perimeter = f.Perimeter.value;
		Deduct = (f.Deduct.value * 1) + Windows + Doors;
		SurfaceArea = (Perimeter * Height) - Deduct;
		GallonsReq = Math.ceil(SurfaceArea/PaintFactor);
		f.tsa.value=SurfaceArea;
		f.ngn.value=GallonsReq;

	}
	try { pageTracker._setVar('Paint Calculator'); } catch(e) {} //Google Analytics
	trackCalculator();  //Omniture
	return false;
}
var comboCurDivId = 1;
var comboCnt = 11;
function toggleCombo(label, inc) {
	var newDivId = eval(label + 'CurDivId') + inc;
	if (newDivId > eval(label + 'Cnt')) {
		newDivId = 1;
	}
	else if (newDivId < 1) {
		newDivId = eval(label + 'Cnt');
	}
	document.getElementById(label + '_' + eval(label + 'CurDivId')).style.display = 'none';
	document.getElementById(label + '_' + newDivId).style.display = 'block';
	document.getElementById(label + 'Cnt' + '_' + eval(label + 'CurDivId')).style.display = 'none';
	document.getElementById(label + 'Cnt' + '_' + newDivId).style.display = 'block';
	if (label == 'combo') {
		comboCurDivId = newDivId;
	}
//  label + 'CurDivId' = newDivId;
}
function resetBuyThis() {
	if(document.getElementById('devineProducts')) {
		document.getElementById('devineProducts').selectedIndex = 0;
	}
	if(document.getElementById('devineSize')) {
		var e = document.getElementById('devineSize');
		while(e.length > 0) {
			e.remove(0);
		}
	}
	showDiv(document.getElementById('purchaseStart'));
	dontShowDiv(document.getElementById('devineProducts'));
	dontShowDiv(document.getElementById('submitButton'));
	dontShowDiv(document.getElementById('devineSize'));
	dontShowDiv(document.getElementById('productQuantity'));
	if(document.getElementById('pebblescream_calcbtnoff')) {
		var el = document.getElementById('pebblescream_calcbtnoff');
		if(el.style.display === 'none') toggleCalculator('pebblescream');  //hide paint calculator
	}
	startCartFlow();
}
function showDiv(div) {
	if(div) div.style.display = "block";
}
function dontShowDiv(div) {
	if(div) div.style.display = "none";
}

/*************************************************** */
/*** color deep linking color-combinations ****/
/****************************************************/
function setColorDisplay(id,color,arr){

var rt = document.getElementById(id);
//alert(rt.name);
if(rt){
	var elements = rt.getElementsByTagName("area");
	var isMatch = false;
	for(var x=0;x<elements.length;x++){
		if(elements[x].alt === color){
			//alert('match chgLgWheelColor(' +  rt.id +',' + elements[x].alt +')');
			chgWheelLabel(arr.tab, arr.h2, arr.p);
			chgWheel(arr.tab, arr.h2, arr.p, elements[x].alt);

			chgLgWheelColor(rt.id, elements[x].alt);
			chgSwatchColor(rt.id, x+1, elements[x].alt);
			isMatch = true;
		}

	}
	if(isMatch == false) {
		chgWheelLabel(arr.tab, arr.h2, arr.p);
		chgWheel(arr.tab, arr.h2, arr.p, elements[0].alt);
		chgLgWheelColor(rt.id, elements[0].alt);
		chgSwatchColor(rt.id, 1, elements[0].alt);

	}
}

}

function setMSDS(obj,upc) {
	location.href = (obj.href).replace('home/msds.jsp','getMsds.do') + "?upc="+upc;
	return false;
}

function getURI() {
	var reExStr = new RegExp("^https?://((.*):[0-9]{2,4}|(.*)com)(/devine)?/");
	if(reExStr.test(window.location)) {
			var str = new String(window.location);
			return str.replace(reExStr,"/") ;
	} else return window.location;
}

function getUrlServer() {
	return parent.window.location.host.replace(/www[0-9]*\./, '');
}


/********************* COLOR COMBINATIONS **************/
var tab1Arr = [];  // Trend Proof
		tab1Arr.push({'tab':'tab1', 'h2': 'Pebbles &amp; Creams', 'p':'Peek-a-boo hues reflecting<br/>the sheer side of color.'});
		tab1Arr.push({'tab':'tab1', 'h2': 'Pacific Trail Mix',    'p':'Nutty Characters with subtle personalities<br/>exude depth and warmth.'});
		tab1Arr.push({'tab':'tab1', 'h2': 'Espresso Blends',      'p':'Deep and sultry tones that penetrate walls<br/>captivating the essence or elegance.'});
		tab1Arr.push({'tab':'tab1', 'h2': 'Cool Grasses and Evergreens', 'p':'Our version of green. This palette<br/>makes your room feel au natural.'});
		tab1Arr.push({'tab':'tab1', 'h2': 'Natural Blondes',      'p':'Friendly and cozy exuberance<br/>that vibrates with warmth.'});
		tab1Arr.push({'tab':'tab1', 'h2': 'Valley Vineyard &amp; Spices', 'p':'Exciting and passionate appetites<br/>that represent the fullness of life.'});
		tab1Arr.push({'tab':'tab1', 'h2': 'Desert Lights',         'p':'Worldly and exotic diversities<br/>that impart cultural wisdom.'});
		tab1Arr.push({'tab':'tab1', 'h2': 'Silver Skies',          'p':'Cool richness that translates<br/>into regal memories.'});
		tab1Arr.push({'tab':'tab1', 'h2': 'Ocean Tide Pools',      'p':'Soothing and relaxing clarities<br/>that compose restful thoughts.'});
		tab1Arr.push({'tab':'tab1', 'h2': 'Woven Tattles &amp; Spun Tales', 'p':'Laundered color through<br/>the fabric of life.'});
		tab1Arr.push({'tab':'tab1', 'h2': 'Sweet &amp; Hot Beans', 'p':'Sparkling and whimisical treats<br/>that awaken the inner child.'});
var tab2Arr = []; //Flor Fauna
			tab2Arr.push({ 'h2':'Collection 1', 'p':"Gleefully fresh<br/>and inspiring", 'tab':'tab2' });
			tab2Arr.push({ 'h2':'Collection 2', 'p':"Never shy<br/>or reserved",         'tab':'tab2' });
			tab2Arr.push({ 'h2':'Collection 3', 'p':"Nature\'s<br/>camouflage",          'tab':'tab2' });

var tab3Arr = [   //Well Traveled
   			{ 'h2':'Havana', 'p':'Passionate hues and<br>roaring pursuits.', 'tab':'tab3' },
   			{ 'h2':'French Casino', 'p':'Lively and oh-so<br/>cosmopolitan.', 'tab':'tab3' },
			{ 'h2':'Pieces of Paradise', 'p':'Citrus and spice and<br/>everything nice.','tab':'tab3' }
];


