// JavaScript Document

function blindchoicechange(id) {
	if($(id).className == "") {
		$(id).className = "imagechoice-on";
	}
	else {
		$(id).className = "";
	}
	
	blindcoloursARRAY = $('blindcolours').select('.imagechoice-on');
	
	if(blindcoloursARRAY.size() > 3){
		$('blindcolourserror').style.display = "";
		$(id).className = "";
	}
	else {
		$('blindcolourserror').style.display = "NONE";
	}
	
	dynamic_height();
	
}

function tapechoicechange(id) {
	if($(id).className == "") {
		$(id).className = "imagechoice-on";
	}
	else {
		$(id).className = "";
	}
		
	tapecoloursARRAY = $('tapecolours').select('.imagechoice-on');
	
	if(tapecoloursARRAY.size() > 2){
		$('tapecolourserror').style.display = "";
		$(id).className = "";
	}
	else {
		$('tapecolourserror').style.display = "NONE";
	}

	dynamic_height();
	
}

//	blindcolours.each(function(s) {
//		alert(s.title);
//	});

function dynamic_height() {	
	$$('.columns').each(function(item) {item.style.height = "";});
	setEqualHeightColumns('columns');
}


function formValidate(){
	var error=0;
	$("errorname").style.display="none";
 	$("erroremail").style.display="none";
	$("errorsaddress").style.display="none";
	$("erroremailinvalid").style.display="none";
	
	if($("txtName").value== "") {
		error=1;
		$("errorname").style.display="block";
	}
		
	if($("txtAddress").value== "") {
		error=1;
		$("errorsaddress").style.display="block";		
	}

	if($("txtEmail").value == ""){
		error=1;
		$("erroremail").style.display="block";		
	}
	else {
		if (!echeck($("txtEmail").value)) { 
			$("erroremailinvalid").style.display="block";		
			error=1
		}

	}
	dynamic_height();
	if(error==0){
		blindcoloursTEXT = "";
		blindcoloursARRAY = $('blindcolours').select('.imagechoice-on');
		
		blindcoloursARRAY.each(function(s) {
			blindcoloursTEXT += s.title + ", ";
		});
		
		tapecoloursTEXT = "";
		tapecoloursARRAY = $('tapecolours').select('.imagechoice-on');

		tapecoloursARRAY.each(function(s) {
			tapecoloursTEXT += s.title + ", ";
		});

		var pars = 'name=' + $('txtName').value + '&email=' + $('txtEmail').value + '&telephone=' + $('txtTelephone').value + '&address=' + $('txtAddress').value + '&heardfrom=' + $('cmb_hear').value + '&blinds=' + blindcoloursTEXT + '&tapes=' + tapecoloursTEXT;
		new Ajax.Request('/sitestyle/modules/htmlcontent/blindssamples/sendmail.php', { method:'get', parameters: pars, onSuccess: emailsent});

	}
}

function emailsent(transport) { 
	 $("msgThankyou").style.display="block"; 
	 $("bs-wrapper").style.display="none";
	 dynamic_height();
}

function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){return false;}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){return false;}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){return false}
	if (str.indexOf(at,(lat+1))!=-1){return false;}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){return false;}
	if (str.indexOf(dot,(lat+2))==-1){return false;}
	if (str.indexOf(" ")!=-1){return false;}
	return true;			
}
