/**
 * Adodis Blog package
 * @author J-Extension <contact@jextn.com>
 * @link http://www.jextn.com
 * @copyright (C) 2012 - 2013 J-Extension
 * @license GNU/GPL, see LICENSE.php for full license.
**/

function validateAU(){
	var userval 	= document.getElementById('userval').value;
	document.getElementById('jform_email').style.border 					="none"
	document.getElementById('jform_website').style.border 					="none"
	if(userval==0) {
		var email 	= document.getElementById('jform_email').value;
		if ((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email) == false)){
			document.getElementById('jform_email').style.border 			= "1px solid #FF0000";
			document.getElementById('jform_email').focus();
			document.getElementById("jform_email").title 					="Please Enter valid e-mail";
			return false;
		}

		var theurl		= document.getElementById('jform_website');
		if( theurl != null ) {
			var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
			if( theurl.value != '' ) {
			     if (tomatch.test(theurl.value)) {
			        return true;
			     } else {
			     	document.getElementById('jform_website').style.border 			= "1px solid #FF0000";
					document.getElementById('jform_website').focus();
					document.getElementById("jform_website").title 					="Please Enter valid Website";
					return false;
			     }
			}
		}
	}
}

function validateAUBlog(){
	var userval 	= document.getElementById('userval').value;

	if(userval==0) {
		var email 	= document.getElementById('jform_e_mail').value;
		document.getElementById('jform_e_mail').style.border 				="none"
		document.getElementById('jform_website').style.border 				="none"
		if ((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email) == false)){
			document.getElementById('jform_e_mail').style.border 			= "1px solid #FF0000";
			document.getElementById('jform_e_mail').focus();
			document.getElementById("jform_e_mail").title 					="Please Enter valid e-mail";
			return false;
		}

		var theurl		= document.getElementById('jform_website');
		if( theurl != null ) {
			var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
			if( theurl.value != '' ) {
			     if (tomatch.test(theurl.value)) {
			        return true;
			     } else {
			     	document.getElementById('jform_website').style.border 	= "1px solid #FF0000";
					document.getElementById('jform_website').focus();
					document.getElementById("jform_website").title 			="Please Enter valid Website";
					return false;
			     }
			}
		}
	}
}

//To Check Registered or anonymous user
function nonRegistered(){

	var userval = document.getElementById('userval').value;
	if(userval==0) {
		addClass(document.getElementById("jform_name"), "required");
		addClass(document.getElementById("jform_email"), "required");
	}
}

function nonRegisteredBlog(){

	var userval = document.getElementById('userval').value;
	if(userval==0) {
		addClass(document.getElementById("jform_name"), "required");
		addClass(document.getElementById("jform_e_mail"), "required");
	}
}

function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ');
	}
}

function addClass(ele,cls) {
	if (!this.hasClass(ele,cls))
		ele.className += " "+cls;
}
function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}