
function isEmpty(s) {
	if (s.length == 0) return true;
	if (trim(s).length == 0) return true;
	return false;
}

//	TODO: check the function
function isEmail(s) {
   
	return chkEmail(s);
	
}

/**
 * Validates the email address.
 */
function isValidEmail(s) {
 
	var v = trim(s);
	var we_had_monkey = false, relief = true;
	var we_had_dot = false;
	var count = 0;
	
	// sta je dobra email adresa?
	// mora da ima jedno majmunce
	// ne sme da ima razmake, moze da ima slova, cifre, crtice
	for(i = 0; i < v.length; i++) {
		c = v.charAt(i);
		count++;
		
		// tacka ne sme da ide iza majmunceta i
		// dve tacke ne smeju da idu jedna za drugom
		if (we_had_monkey == true) {
			if (c == '.') {
				we_had_dot = true;
				if (relief == true) {
					relief = false;
					continue;
				} else {
					return false;
				}
			}
			if (relief == false) relief = true;
		} else {
			if (c == '.') continue;
			if (c == '@') {
				// ima li znakova ispred majmunceta?
				if (count == 1) {
					return false;
				}
				count = 0;
				we_had_monkey = true;
				relief = false;
				continue;
			}
		}
		
		// standardno, slova, cifre i crtice su dozvoljeni
		if ((c >= 'a')&&(c <= 'z')) continue;
		if ((c >= 'A')&&(c <= 'Z')) continue;
		if ((c >= '0')&&(c <= '9')) continue;
		if ((c == '-')||(c == '_')) continue;
		if ((c == "'")) continue;
		
		return false;
	}
}

//function trim(s) {
	//var i = 0;
	//while(isspace(s.charAt(i))) i++;
	//if (i == s.length) return new String('');
		
	//var j = s.length - 1;
	//while(isspace(s.charAt(j))) j--;
		
	//return s.substring(i, j + 1);
//}

function validate_quote() {
	
	var error_occured = false;
	
	/*if (isEmpty(document.getElementById("category").value)) {
		document.getElementById("category").style.background = 'Yellow';
		category_err.style.display = 'block';
		error_occured = true;	
	}*/
	if (isEmpty(document.getElementById("txtname").value)) {
		document.getElementById("txtname").style.background = 'Yellow';
		txtname_err.style.display = 'block';
		error_occured = true;	
	}
	if (isEmpty(document.getElementById("txtemail").value)) {
		document.getElementById("txtemail").style.background = 'Yellow';
		txtemail_err.style.display = 'block';
		error_occured = true;	
	}
	if (isEmpty(document.getElementById("details").value)) {
		document.getElementById("details").style.background = 'Yellow';
		details_err.style.display = 'block';
		error_occured = true;	
	}
		
if(!(isEmail(document.getElementById("txtemail").value)))
	{
	document.getElementById("txtemail").style.background = 'Yellow'; 
	txtemail_err.style.display = 'block';
	error_occured = true;	
	}	
if (isEmpty(document.getElementById("entercode").value)) {
		document.getElementById("entercode").style.background = 'Yellow';
		txtcode_err.style.display = 'block';
		error_occured = true;	
	}
	
if (!error_occured) {
		 //addquote();
		 return true;
		}
	else
	{
		return false; 
	}
}

function changecss(obj,errid) {
	if (obj.value!= '') {
		obj.style.background = 'White';
		eval(errid + ".style.display = 'none'");
	}
}

function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 


function chkEmail(strEmail)
{
	strIndex= strEmail.indexOf("@");
	
	len=strEmail.length;
	strFind = strEmail.substring(strIndex,len);
	if(strEmail.indexOf("@")< 1 || strEmail.indexOf(".")< 1 ||strEmail.length < 5)
	{
		return false;
	}
	if  (strFind.indexOf(".")< 3) 
		return false;
	else
		return true;
}
function hide_error(obj,panel)
{
	if (obj.value != '') 
	{
	    obj.style.background = 'White';
		//eval(panel+".style.display = 'none'");
		document.getElementById(panel).style.display = 'none';	
	}
}	