function isEMailAddr(elem) {
    var str = elem.value;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        return false;
    } else {
        return true;
    }
}

function verifica(e)
	{
	variab = event.keyCode ;
		//alert (variab);
	if (variab != 8) {
			if (variab==46|| variab>=48 && variab<=57 ){
			event.returnValue = variab ;
			}
			else
			{event.returnValue = false ;}
		}
	}
var sErrorFields = '';
var sErrorTexts = '';
function addError(errorText, errorField) {
	sErrorTexts += '   ' + errorText + '\n';
	sErrorFields += errorField + ',';
}
function setFormFocus(f, e) {
	if(e) {
		f.elements[e].focus();
	}
}
function unhighlightErrors(f, s) {
	a = s.split(',');
	if(a.length > 0) {
		for(i = 0; i < (a.length -1); i++) {
			if(a[i].toString().length > 0) { f.elements[a[i]].style.backgroundColor = ''; f.elements[a[i]].style.borderColor = ''; }
		}
	}
}
function highlightErrors(f, s) {
	if(s.length > 0) {
		a = s.split(',');
		if(a.length > 0) {
			for(i = 0; i < (a.length -1); i++) {
				if(a[i].toString().length > 0) { f.elements[a[i]].style.backgroundColor = '#FFFFFF'; f.elements[a[i]].style.borderColor = '#F17192'; }
			}
			setFormFocus(f, a[0])
		}
	}
}

/////////////////////////////////////////////////////////


function validareContact(f) {
	unhighlightErrors(f, sErrorFields)
	sErrorTexts = '';
	sErrorFields = '';

	if(f.nume.value.length == 0) { addError('Va rugam specificati numele dumneavoastra ', 'nume') }
	if(f.prenume.value.length == 0) { addError('Va rugam specificati prenumele dumneavoastra ', 'prenume') }
	if(f.telefon.value.length == 0) { addError('Va rugam specificati numarul de telefon', 'telefon') }	
	if(f.email.value.length == 0 || (f.email.value.length > 0 && !isEMailAddr(f.email))) {
		addError('Va rugam specificati adresa dumneavoastra de email', 'email')
	}

	if(f.mesaj.value.length == 0) { addError('Va rugam introduceti mesajul dumneavoastra', 'mesaj') }
	
	if(sErrorTexts.length > 0) {
		highlightErrors(f, sErrorFields)
		alert('S-au detectat urmatoarele probleme:\n\n' + sErrorTexts);
		return false
	} else {
		document.contact.submit.disabled="true";
		return true
	}
}

function putImage(image){
  var h = document.getElementById('loadContainer');
  while(h.firstChild){
    h.removeChild(h.firstChild);
  }
  h.appendChild(image);
}

function displayAnimation(){
  document.getElementById("anim").style.display="block";
}

function hideAnimation(){
  document.getElementById("anim").style.display="none";
}

function loadImage(picurl,picname){
	var loader = new ImageLoader(picurl);
	displayAnimation();
	loader.loadEvent = function(url, image){
	  hideAnimation();
	  putImage(image);
      document.getElementById("cName").innerHTML = picname;
	}
	loader.load();
}

function zoomColors(image,colorName) {
	document.getElementById("bigColor").src = image;
	document.getElementById("cName").innerHTML = colorName;
}
