

a=0;
setup = new Array("00","33","66","99","cc","ff");
colors = new Array();
for(x=0; x< setup.length; x++){
	for(y=0; y< setup.length; y++){
		for(z=0; z< setup.length; z++){
			colors[colors.length] = "#"+setup[x]+setup[y]+setup[z];
			a++
		}
	}
}
//alert(a);

function previewColor(foo,theColor){
	document.getElementById(foo).style.backgroundColor = theColor;
}
function setColor(foo,theColor){
	document.getElementById(foo).value = theColor;
	document.getElementById(foo+"Display").style.backgroundColor = theColor;
	if(document.getElementById("colorPicker"))document.body.removeChild(document.getElementById("colorPicker"));
	document.getElementById('dropdowns').style.visibility = "visible";
	ds_updateCard();
}

function createPicker(foo,colorFor,e){
	document.getElementById('dropdowns').style.visibility = "hidden";
	picker = document.getElementById("colorPicker");
	if(!picker){
		t = 1;
		// create picker
		picker = d.body.appendChild(d.createElement("div"));
		picker.id = "colorPicker";
		// set position of picker
		picker.style.position = "absolute";
		fromTop = findPosY(foo)+20;
		picker.style.top = fromTop+"px"
		picker.style.left = findPosX(foo)+"px"
		window.status = findPosX(foo)+","+findPosY(foo);
		
		pickerContent ="<p class=\"left\">Choose a color below:</p><p class=\"right fakeLink\" onclick=\"document.getElementById('dropdowns').style.visibility = 'visible';document.body.removeChild(document.getElementById('colorPicker'));\">Close</p><div style=\"clear:both\"></div>";
		for(x=0; x< colors.length; x++){
			pickerContent += "<div class=\"colorSwatch\" style=\"background-color:"+colors[x]+";\" title=\""+colors[x]+"\" onmouseover=\"previewColor('colorExample','"+colors[x]+"')\" onclick=\"setColor('"+colorFor+"','"+colors[x]+"')\"></div>";
			t++;
			if(t == 19){
				t = 1;
			}
		}
		pickerContent += "<div style=\"clear:both\"></div><div id=\"colorExample\"></div><div style=\"clear:both\"></div>";
		picker.innerHTML = pickerContent;
	}
}



function ds_updateMessage(){
	curMessage = d.getElementById('message').value;
	while (curMessage.indexOf("\n")!= -1 ){
		curMessage = curMessage.replace("\n","<br />");
	}
	d.getElementById('cardMessage').innerHTML = curMessage;
	//d.getElementById('cardMessage').style.color = d.getElementById('messageColor').value;
}

function ds_updateCard(){
	postcard2 = d.getElementById('postcard');
	// set to values
	
	// background color
	bgColor2 = d.getElementById('bgColor').value;
	postcard2.style.backgroundColor = bgColor2;
	if(d.getElementById('to')){
		d.getElementById('to').innerHTML = "<strong>To:</strong> <a href=\"mailto:"+d.getElementById('rmail').value+"\">"+d.getElementById('rname').value+"</a>";
		
		// set from values
		d.getElementById('from').innerHTML = "<strong>From:</strong> <a href=\"mailto:"+d.getElementById('smail').value+"\">"+d.getElementById('sname').value+"</a>";
		
		ds_updateMessage();
		
		// text color
		textColor2 = d.getElementById('textColor').value;
		postcard2.style.color = textColor2;
		d.getElementById('card').style.borderColor = textColor2; // set seperator line to same as text color
		
		// link color
		var cardLinks = postcard2.getElementsByTagName('a');
		linkColor2 = d.getElementById('linkColor').value;
		for(x=0; x< cardLinks.length; x++){
			cardLinks[x].style.color = linkColor2;
		}
		d.getElementById('cardClear').style.borderColor = bgColor2; // that pesky clear border
	}
	
	
	
}
function ds_checkName(foo){
	if(foo.value == ""){
		ds_addClass(foo.parentNode.parentNode,'error');
		ds_addClass('makeForm',foo.id);
	} else {
		ds_delClass(foo.parentNode.parentNode,'error');
		ds_delClass('makeForm',foo.id);
	}
}

function ds_checkEmail(foo){
    if (foo.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1) {
		ds_addClass(foo.parentNode.parentNode,'error');
		ds_addClass('makeForm',foo.id);
	} else {
		ds_delClass(foo.parentNode.parentNode,'error');
		ds_delClass('makeForm',foo.id);
	}
}

function ds_checkForm(){
	// check for the gmail autocomplete thingy being open
	sl2 = document.getElementById('showList');
	if(sl2 && sl2.style.display == "") return false;
	hasErrors = '';
	//alert(document.getElementById('makeForm').className);

	// check for blanks
	if(document.getElementById('rname').value == ""){ 
		ds_addClass(document.getElementById('rname').parentNode.parentNode,'error');
		ds_addClass('makeForm','rname');
		if(!hasErrors)document.getElementById('rname').focus;
		hasErrors = 'true';
	}
	if(document.getElementById('rmail').value == ""){
		ds_addClass(document.getElementById('rmail').parentNode.parentNode,'error');
		ds_addClass('makeForm','rmail');
		hasErrors = 'true';
	}
	if(document.getElementById('sname').value == ""){
		ds_addClass(document.getElementById('sname').parentNode.parentNode,'error');
		ds_addClass('makeForm','sname');
		hasErrors = 'true';
	}
	if(document.getElementById('smail').value == ""){
		ds_addClass(document.getElementById('smail').parentNode.parentNode,'error');
		ds_addClass('makeForm','smail');
		hasErrors = 'true';
	}
	if(document.getElementById('message').value == ""){
		ds_addClass(document.getElementById('message').parentNode.parentNode,'error');
		ds_addClass('makeForm','message');
		hasErrors = 'true';
	}
	
	if(document.getElementById('makeForm').className != ""){ // check for existing errors
		hasErrors = 'true';
	}
	if(hasErrors){
		alert('Highlited fields must be corrected first');
		scrollTo(findPosX(document.getElementById('rname')),findPosY(document.getElementById('rname'))-30);
		return false;
	}
	return true;
}

var currentLayout = "";

function ds_cardLayout(layout){
	
	postcard2 = d.getElementById('postcard');
	postcard2.className = "img"+layout;
	d.getElementById('layout'+layout).style.borderColor = "green";
	if(currentLayout)d.getElementById('layout'+currentLayout).style.borderColor = "white";
	currentLayout = layout;
	d.getElementById('layout').value = layout;
}

function selectLater(){
	document.getElementById('whenLater').checked = "checked";
}