/*
======================================================================
ddcolorposter.js: By Dynamic Drive (http://www.dynamicdrive.com)
Communicates between Yahoo Color Picker and form fields on your page
Created: Feb 20th, 06'
======================================================================
*/

function executeonload(functionref){
	if (window.addEventListener)
		window.addEventListener("load", functionref, false)
	else if (window.attachEvent)
		window.attachEvent("onload", functionref)
	else if (document.getElementById)
		window.onload=functionref
}

var ddcolorposter={
initialize:function(r,g,b, hexvalue){
	this.rvalue=r //store red value
	this.gvalue=g //store green value
	this.bvalue=b //store blue value
	this.hexvalue=hexvalue //store combined hex value
	
	if(document.getElementById('colorfieldDefault').checked) {
		setInitalColours();
	}
	
	// To change background colour
	
	document.WebSiteTemplateForm.ColourChoice.value='';
	document.WebSiteTemplateForm.ColourChoice.value='Template Colour: '+document.getElementById('colorbox1').style.backgroundColor+'\n'+'Menu/Footer Font Colour: '+document.getElementById('colorbox4').style.color+'\n'+'Side Menu Font Colour: '+document.getElementById('colorbox6').style.color;
	
	
	if(document.getElementById('colorfield1').checked) {
		document.getElementById('colorbox1').style.backgroundColor="#"+this.hexvalue;
		document.getElementById('colorbox7').style.backgroundColor="#"+this.hexvalue;
		document.getElementById('colorbox2').style.backgroundColor="#"+this.hexvalue;
	}
	
	// To change text colour + add to below !statement
	
	if(document.getElementById('colorfield4').checked) {
		document.getElementById('colorbox4').style.color="#"+this.hexvalue
		document.getElementById('colorbox8').style.color="#"+this.hexvalue
	}
	if(document.getElementById('colorfield6').checked) {
		document.getElementById('colorbox6').style.color="#"+this.hexvalue
		document.getElementById('colorbox9').style.color="#"+this.hexvalue
		document.getElementById('colorbox10').style.color="#"+this.hexvalue
		document.getElementById('colorbox11').style.color="#"+this.hexvalue
		document.getElementById('colorbox12').style.color="#"+this.hexvalue
	}
	if(!document.getElementById('colorfield4').checked | !document.getElementById('colorfield6').checked) {
	if (typeof this.targetobj!="undefined"){
		this.targetobj.value=this.hexvalue //set field to selected hex color value
		if (typeof this.divobj!="undefined") //set adjacent div to selected hex color value
			this.divobj.style.backgroundColor="#"+this.hexvalue
	}
	}
},
echocolor:function(inputobj, divID){
	this.targetobj=inputobj
	this.divobj=document.getElementById(divID)
	this.targetobj.onblur=function(){
	if (inputobj.value.search(/^[a-zA-Z0-9]{6}$/)!=-1) //if field contains valid hex value
		document.getElementById(divID).style.backgroundColor="#"+inputobj.value
	}
},
fillcolorbox:function(inputID, divID){
	var inputobj=document.getElementById(inputID)
	if (inputobj.value.search(/^[a-zA-Z0-9]{6}$/)!=-1) //if field contains valid hex value
		document.getElementById(divID).style.backgroundColor="#"+inputobj.value
}
}



