function validateComment(){

	var author = document.getElementById('author');
	var email = document.getElementById('email');
	var url = document.getElementById('url');
	var comment = document.getElementById('comment');
	var errs = new Array();
	var valid = true;
	var islogged = document.getElementById('islogged');
	if ((author && email && url && comment) || (islogged && comment))
	{

		if (!islogged)
		{
			if (!author.value.trim().length || author.value== 'Enter your name')
			{
				errs[errs.length] = 'author';
			}

			if (!isEmail(email.value))
			{
				errs[errs.length] = 'email';
			}

			if (url.length)
			{
				errs[errs.length] = 'url';
			}
		}


		if (!comment.value.trim().length || comment.value== 'Enter the comment')
		{
			errs[errs.length] = 'comment';
		}

		showValidates(errs);
		if (errs.length)
		{
			return false;
		}
		return true;
	}else{
		return false;
	}
}


function isEmail(elementValue) {
	var emailPattern = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;
	return emailPattern.test(elementValue); 
}


String.whiteSpace = [];
String.whiteSpace[0x0009] = true;
String.whiteSpace[0x000a] = true;
String.whiteSpace[0x000b] = true;
String.whiteSpace[0x000c] = true;
String.whiteSpace[0x000d] = true;
String.whiteSpace[0x0020] = true;
String.whiteSpace[0x0085] = true;
String.whiteSpace[0x00a0] = true;
String.whiteSpace[0x1680] = true;
String.whiteSpace[0x180e] = true;
String.whiteSpace[0x2000] = true;
String.whiteSpace[0x2001] = true;
String.whiteSpace[0x2002] = true;
String.whiteSpace[0x2003] = true;
String.whiteSpace[0x2004] = true;
String.whiteSpace[0x2005] = true;
String.whiteSpace[0x2006] = true;
String.whiteSpace[0x2007] = true;
String.whiteSpace[0x2008] = true;
String.whiteSpace[0x2009] = true;
String.whiteSpace[0x200a] = true;
String.whiteSpace[0x200b] = true;
String.whiteSpace[0x2028] = true;
String.whiteSpace[0x2029] = true;
String.whiteSpace[0x202f] = true;
String.whiteSpace[0x205f] = true;
String.whiteSpace[0x3000] = true;


String.prototype.trim = function trim14() {
	var str = this;
    var len = str.length, whiteSpace, i;

    if (!len) {
        return '';
    }

    whiteSpace = String.whiteSpace;

    if (len && whiteSpace[str.charCodeAt(len-1)])
    {
        do{
            --len;
        }
        while (len && whiteSpace[str.charCodeAt(len - 1)]);

        if (len && whiteSpace[str.charCodeAt(0)]){
            i = 1;
            while (i < len && whiteSpace[str.charCodeAt(i)]){
                ++i;
            }
        }
        return str.substring(i, len);
    }
    if (len && whiteSpace[str.charCodeAt(0)]) {
        i = 1;
        while (i < len && whiteSpace[str.charAt(i)]){
            ++i;
        }
        return str.substring(i, len);
    }
    return str;
};

function showValidates(arr){
	var i;
	for (i=0;i<arr.length ;i++ )
	{
		if (arr[i]!='url' && arr[i]!='email')
		{
			if (document.getElementById(arr[i]))
			{
				if (arr[i]=='author')
				{
					document.getElementById(arr[i]).value = 'Enter your name';
				}else{
					document.getElementById(arr[i]).value = 'Enter the '+arr[i];
				}
				document.getElementById(arr[i]).style.color='#df2719';
			}
		}
		if (arr[i]=='email')
		{
			if (document.getElementById(arr[i]))
			{
				document.getElementById(arr[i]).value = 'Enter a valid email';
				document.getElementById(arr[i]).style.color='#df2719';
			}
		}

	}

}

function unsetColor(obj){
	if (obj)
	{
		if (obj.style.color!='')
		{
			obj.style.color = '';
			obj.value = '';
		}
	}
}
