function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function add_error(div_id,msg){
	has_err=1;
	$("#" + div_id).show();
	if(msg!=''){
		var lastMsg = $("#" + div_id).text();
		if(lastMsg.indexOf(msg) > 0){}else{
		$("#" + div_id).append(msg + "<br>");}
	}
}

function validate_email(email){
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
		return (true);
	}
	else{
		return (false);	
	}
}

function validate_url(url){
	if (/http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/.test(url)){
		return (true);
	}
	else{
		return (false);	
	}
}

function validate_textFields(value){
	if (/[\W_]/.test(value) == false){
		return (true);
	}
	else{
		return (false);	
	}
}

function stopURL(value){
	var r = /http/;
	var r2 = /www/;
	if (r.test(value) == false && r2.test(value) == false){
		return (true);
	}
	else{
		return (false);	
	}
}

function stopHtmlTags(value){
	if(value.match(/([\<])([^\>]{1,})*([\>])/i)==null)
		return true;
	else
		return false;
}

function allowAlphaOnly(b){	
	var a = b; 
	if(a >= 33 && a <= 64){
		return false;
	}
	else if(a >= 92 && a <= 96){
		return false;
	}
	else if(a >= 123 && a <= 126){
		return false;
	}
	else{
		return true;	
	}	
}

function allowAlphaNumericOnly(b){	
	var a = b; 
	
	if(a >= 33 && a <= 47){
		return false;
	}
	else if(a >= 58 && a <= 64){
		return false;
	}
	else if(a >= 92 && a <= 96){
		return false;
	}
	else if(a >= 123 && a <= 126){
		return false;
	}
	else{
		return true;	
	}	
}

function onlyNumeric(value){	
	var regex = /[0-9]|\./;
	if( !regex.test(value) ) {
		return false;
	}
	else{
		return true;
	}
}

// for data of birth at least 18
function allowSpecificAge(day, month, year){
	if(day == "") var day = 1;
	if(month == "") var month = 1;
	
	var diff = 0;
	var difference = 0;
	Christmas = new Date(month + "/" + day + "/ " + year);
	today = new Date();

	difference = today - Christmas;
	diff = (Math.round(difference/(1000*60*60*24)))/365;

	return diff;
}

function checkLength()	{
	maxnum = 500; // The maximum number of characters.
	yrTxt = myForm.yourText;
	charleft = myForm.charsLeft;
	charleft.value = maxnum - yrTxt.value.length;
	if (charleft.value <= 0){
		charleft.value = "max";
	}
	if (yrTxt.value.length > maxnum){
		yrTxt.value = yrTxt.value.substring(0,maxnum-1);
	}
}
 
// to disable when press enter while u r in input field (specially written
// for chrome)
 $.fn.DisableEnterKey =
	function(){
		return this.each(
			function(){
				$(this).keydown(
					function(e){
						var key = e.charCode || e.keyCode || 0;
						// return false for the enter key
						return (key != 13);
					}
				)
			}
		)
	};
	
function roll_over(img_name, img_src, img_title){
	// document[img_name].src = img_src;
	// document[img_name].title = img_title;
}

function setHobbies(path,img_name,img_name_sel,img_id,field_name,field_name_div){	
	var img = document.getElementById(img_id);

	if(img.alt == ""){
		img.src= path+''+img_name_sel;
		img.alt = "sel";
		$("#"+field_name_div).append(img.lang+',');
		
	}
	else{
		img.src= path+''+img_name;
		img.alt = "";
		var str3 = $("#"+field_name_div).html();
		$("#"+field_name_div).html(str3.replace(img.lang+",",""));
	}
	
	var str = $("#"+field_name_div).html();
	str = str.substring(0, str.length - 1);

	$("#"+field_name).val(str);
}
function setMoney(path,img_name,img_name_sel,img_id,unsel_img_1,unsel_img_1_id,unsel_img_2,unsel_img_2_id){
	var img = document.getElementById(img_id);
	var imgUnsel_1 = document.getElementById(unsel_img_1_id);
	var imgUnsel_2 = document.getElementById(unsel_img_2_id);
	
	if(img.alt == ""){
		img.src= path+''+img_name_sel;
		img.alt = "sel";
		$("#money").val(img.lang);
		
		imgUnsel_1.src= path+''+unsel_img_1;
		imgUnsel_1.alt = "";
		imgUnsel_2.src= path+''+unsel_img_2;
		imgUnsel_2.alt = "";
		
	}
	else{
		img.src= path+''+img_name;
		img.alt = "";
		$("#money").val('');
	}
}
