function strTrim(str) {
    return str.replace(/^\s+/,'').replace(/\s+$/,'');
}

function validation(form) {
	with(form){
		
		if(strTrim(txt_member_firstname.value) == ''){
			alert('Please specify  First Name');
			txt_member_firstname.focus();
			return  false;
		}
		
		if(strTrim(txt_member_lastname.value) == ''){
			alert('Please specify Last Name');
			txt_member_lastname.focus();
			return  false;
		}
		
		if(txt_member_email.value == '') {
			alert('Please specify Email Address ');
			txt_member_email.focus();
			return  false;
		} else if(!IsEmail(txt_member_email, 'Please specify a valid Email Address')){
					return false;
		}
		if(txt_confirm_member_email.value == '') {
			alert('Please specify Email Address ');
			txt_confirm_member_email.focus();
			return  false;
		} else if(!IsEmail(txt_confirm_member_email, 'Please specify a valid Email Address')){
					return false;
		}
		
		if(txt_member_email.value != txt_confirm_member_email.value){
			alert('Please specify same Email address');
			txt_confirm_member_email.focus();
			return  false;
		}
		
		if(strTrim(txt_member_password.value) == ''){
			alert('Please specify Password ');
			txt_member_password.focus();
			return  false;
		}
		if(strTrim(txt_confirm_password.value) == ''){
			alert('Please retype Password');
			txt_confirm_password.focus();
			return  false;
		}
		
		if(txt_confirm_password.value != txt_member_password.value){
			alert('Password Not Matched');
			txt_member_password.focus();
			return  false;
		}
		
		
		/*if(txt_member_type.value == '0'){
			alert('Please specify Type');
			txt_member_type.focus();
			return  false;
		}*/
		if(country.value == '0'){
			alert('Please specify Country');
			country.focus();
			return  false;
		}
		if(strTrim(state.value) == ''){
			alert('Please specify State');
			state.focus();
			return  false;
		}
		
		if(strTrim(txt_member_city.value) == ''){
			alert('Please specify City');
			txt_member_city.focus();
			return  false;
		}
		
		if(strTrim(txt_member_street.value) == ''){
			alert('Please specify Address');
			txt_member_street.focus();
			return  false;
		}
		
		if(strTrim(txt_member_zipcode.value) == ''){
			alert('Please specify Zip');
			txt_member_zipcode.focus();
			return  false;
		}
		
		if (opt_member_gender.value=='0' ){
       		 alert ("Please specify Gender");
			 opt_member_gender.focus();
       		 return false;
   		 }

		if(txt_member_image.value!=''){
			if(!isValidImage(txt_member_image.value)){
				alert("Please specify a valid image format (only allowed jpg,gif,tiff,bmp,png,jpeg,raw format)");
				txt_member_image.focus();
				return false;
				}
			
		}
		
		/*if(member_agree.checked == false){
			alert("Please agree the terms and conditions");
			member_agree.focus();
			return false;
		}*/
	}	
}








// Function for email validation
function IsEmail(field, msg)
{
	var regex = /^[\w]+(\.[\w]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/ ;
	if(!regex.test(field.value)) 
	{
		alert(msg);
		field.focus();
		return false;
	}
	return true;
}

function LoginValidation(form) {
	with(form){
		
		if(txt_member_user_name.value == ''){
			alert('Please specify User Name');
			txt_member_user_name.focus();
			return  false;
		}
		
		if(txt_member_password.value == ''){
			alert('Please specify Password');
			txt_member_password.focus();
			return  false;
		}
	}	
}

function AddToCartValidation(form) {
	with(form){
		
		if(txt_quantity.value == '' || txt_quantity.value <= 0){
			alert('Please specify number of quantity greater then ZERO!');
			txt_quantity.value = '';
			txt_quantity.focus();
			return  false;
		}
		
		if (isNaN(txt_quantity.value)) {
			alert("Please specify quantity in numeric");
			txt_quantity.value = '';
			txt_quantity.focus();
			return false;
		}
	}	
}


function checkB(){

var b=document.getElementsByTagName('input');
var count=0;
	for (i=0;i<b.length;i++){
	var box=b[i];
		if(	box.value == '' || box.value == '0') {
		count++;
		break;
		}
	}
	if (count!=0){
		alert('Value must be numeric and greater then zero');
	}

}

function ForgotPasswordValidation(form) {
	with(form){
		
		if(txt_email_user_name.value == ''){
			alert('Please specify User Name ');
			txt_email_user_name.focus();
			return  false;
		}

	}	
}


// Javascript Hit Counter Start From Here

 function nameDefined(ckie,nme)
{
   var splitValues
   var i
   for (i=0;i<ckie.length;++i)
   {
      splitValues=ckie[i].split("=")
      if (splitValues[0]==nme) return true
   }
   return false
}

function delBlanks(strng)
{
   var result=""
   var i
   var chrn
   for (i=0;i<strng.length;++i) {
      chrn=strng.charAt(i)
      if (chrn!=" ") result += chrn
   }
   return result
}
function getCookieValue(ckie,nme)
{
   var splitValues
   var i
   for(i=0;i<ckie.length;++i) {
      splitValues=ckie[i].split("=")
      if(splitValues[0]==nme) return splitValues[1]
   }
   return ""
}
function insertCounter() {
 readCookie()
 displayCounter()
}
 function displayCounter() {
 document.write('<H3 ALIGN="CENTER">')
 document.write("You've visited this page ")
 if(counter==1) document.write("the first time.")
 else document.write(counter+" times.")
 document.writeln('</H3>')
 }
function readCookie() {
 var cookie=document.cookie
 counter=0
 var chkdCookie=delBlanks(cookie)  //are on the client computer
 var nvpair=chkdCookie.split(";")
 if(nameDefined(nvpair,"pageCount"))
 counter=parseInt(getCookieValue(nvpair,"pageCount"))
 ++counter
 var futdate = new Date()
 var expdate = futdate.getTime()
 expdate += 3600000 * 24 *30  //expires in 1 hour
 futdate.setTime(expdate)

 var newCookie="pageCount="+counter
 newCookie += "; expires=" + futdate.toGMTString()
 window.document.cookie=newCookie
}
// Javascript Hit Counter End Here


// Javascript Numeric Validation (No decimal + No Character and Special Character and No Negative value will be allowed

// version: beta
// created: 2005-08-30
// updated: 2005-08-31
// mredkj.com
function extractNumber(obj, decimalPlaces, allowNegative)
{
	var temp = obj.value;
	
	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	
	obj.value = temp;
}
function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}

// Javascript Numeric Validation (No decimal + No Character and Special Character and No Negative value will be allowed End Here
								  
								  
								  




function quoteValidation(form) {
	with(form){
	
		if(category_id.value == 0) {
			alert('Please specify a Category ');
			category_id.focus();
			return  false;
		} 
		
		if(txt_library_quote_author.value == '') {
			alert('Please specify a Author');
			txt_library_quote_author.focus();
			return  false;
		} 
		
		if(opt_library_topics_id.value == 0) {
			alert('Please specify a Topic');
			opt_library_topics_id.focus();
			return  false;
		} 
		
		/*if(opt_library_types_id.value == 0) {
			alert('Please specify a Type');
			opt_library_types_id.focus();
			return  false;
		} 
		*/
		
		if(file_library_quote_image.value!=''){
			if(!isValidImage(file_library_quote_image.value)){
				alert("Please specify a valid image format (only allowed jpg,gif,tiff,bmp,png,jpeg,raw format)");
				file_library_quote_image.focus();
				return false;
			}
		}
	
	}	
}


function tipValidation(form) {
	with(form){
	
		if(category_id.value == 0) {
			alert('Please specify a Category ');
			category_id.focus();

			return  false;
		} 
		
		if(txt_library_tips_title.value == '') {
			alert('Please specify a Title');
			txt_library_tips_title.focus();
			return  false;
		} 
		
		if(opt_library_topics_id.value == 0) {
			alert('Please specify a Topic');
			opt_library_topics_id.focus();
			return  false;
		} 
	
		if(file_library_tips_image.value!=''){
			if(!isValidImage(file_library_tips_image.value)){
				alert("Please specify a valid image format (only allowed jpg,gif,tiff,bmp,png,jpeg,raw format)");
				file_library_tips_image.focus();
				return false;
			}
		}
		
		
	}	
}


function storiesValidation(form) {
	with(form){
	
		if(category_id.value == 0) {
			alert('Please specify a Category ');
			category_id.focus();
			return  false;
		} 
		
		if(txt_library_stories_title.value == '') {
			alert('Please specify a Title');
			txt_library_stories_title.focus();
			return  false;
		} 
		
		if(txt_library_stories_person_name.value == '') {
			alert('Please specify a Author');
			txt_library_stories_person_name.focus();
			return  false;
		} 
		if(opt_library_topics_id.value == 0) {
			alert('Please specify a Topic');
			opt_library_topics_id.focus();
			return  false;
		} 
		

		if(file_library_stories_image.value!=''){
			if(!isValidImage(file_library_stories_image.value)){
				alert("Please specify a valid image format (only allowed jpg,gif,tiff,bmp,png,jpeg,raw format)");
				file_library_stories_image.focus();
				return false;
			}
			
		}
	
	}	
}


function ideaValidation(form) {
	with(form){
	
		if(category_id.value == 0) {
			alert('Please specify a Category ');
			category_id.focus();
			return  false;
		} 
		
		if(txt_library_ideas_title.value == '') {
			alert('Please specify a Title');
			txt_library_ideas_title.focus();
			return  false;
		} 
		
		if(opt_library_topics_id.value == 0) {
			alert('Please specify a Topic');
			opt_library_topics_id.focus();
			return  false;
		} 

		
		if(file_library_ideas_image.value!=''){
			if(!isValidImage(file_library_ideas_image.value)){
				alert("Please specify a valid image format (only allowed jpg,gif,tiff,bmp,png,jpeg,raw format)");
				file_library_ideas_image.focus();
				return false;
			}
			
		}
		
		
		
		
	}	
}

function poemValidation(form) {
	with(form){
	
		if(category_id.value == 0) {
			alert('Please Select a Category ');
			category_id.focus();
			return  false;
		} 
		
		if(txt_library_poem_title.value == '') {
			alert('Please Select a Title');
			txt_library_poem_title.focus();
			return  false;
		} 
		
		if(txt_library_poem_author.value == '') {
			alert('Please Select a Author');
			txt_library_poem_author.focus();
			return  false;
		} 
		
		if(opt_library_topics_id.value == 0) {
			alert('Please specify a Topic');
			opt_library_topics_id.focus();
			return  false;
		} 

			
		if(file_library_poem_image.value!=''){
			if(!isValidImage(file_library_poem_image.value)){
				alert("Please specify a valid image format (only allowed jpg,gif,tiff,bmp,png,jpeg,raw format)");
				file_library_poem_image.focus();
				return false;
			}
		}
		
		
		
	}	
}	


function inspireValidation(form) {
	with(form){
	
		if(category_id.value == 0) {
			alert('Please Select a Category ');
			category_id.focus();
			return  false;
		} 
		
		if(txt_library_inspire_title.value == '') {
			alert('Please Select a Title');
			txt_library_inspire_title.focus();
			return  false;
		} 
		
		if(txt_library_inspire_personality.value == '') {
			alert('Please Select a Personality');
			txt_library_inspire_personality.focus();
			return  false;
		} 
		if(opt_library_topics_id.value == 0) {
			alert('Please specify a Topic');
			opt_library_topics_id.focus();
			return  false;
		} 
		
		if(opt_library_types_id.value == 0) {
			alert('Please specify a Type');
			opt_library_types_id.focus();
			return  false;
		} 
		
		
		if(file_library_inspire_image.value!=''){
			if(!isValidImage(file_library_inspire_image.value)){
				alert("Please specify a valid image format (only allowed jpg,gif,tiff,bmp,png,jpeg,raw format)");
				file_library_inspire_image.focus();
				return false;
			}
		}
		
		
	}	
}

function jokeValidation(form) {
	with(form){
	
		if(category_id.value == 0) {
			alert('Please Select a Category ');
			category_id.focus();
			return  false;
		} 
		
		if(txt_library_joke_title.value == '') {
			alert('Please Select a Title');
			txt_library_joke_title.focus();
			return  false;
		} 
		
		if(opt_library_topics_id.value == 0) {
			alert('Please specify a Topic');
			opt_library_topics_id.focus();
			return  false;
		} 

		if(file_library_joke_image.value!=''){
			if(!isValidImage(file_library_joke_image.value)){
				alert("Please specify a valid image format (only allowed jpg,gif,tiff,bmp,png,jpeg,raw format)");
				file_library_joke_image.focus();
				return false;
			}
			
		}
		
		
		
	}	
}

function memberMailSend(form) {
	with(form){
		if(txt_email.value == ''){
			alert('Please specify an Emailaddress');
			txt_email.focus();
			return  false;
		}else if(!IsEmail(txt_email, 'Please specify a valid Email address')){
					return false;
		}
		if(txt_subject.value == ''){
			alert('Please specify a subject');
			txt_subject.focus();
			return  false;
		}
		
		if(txtarea_message.value == ''){
			alert('Please specify a subject');
			txtarea_message.focus();
			return  false;
		}
	}	
}

function addEditEvent(form) {
	with(form){
		
		if(txt_date_check.value == '0'){
			alert('Please specify a date in Calendar');
			return  false;
		}
		if(txt_cal_event_title.value == ''){
			alert('Please specify an Event Title');
			txt_cal_event_title.focus();
			return  false;
		}
		if(file_cal_event_image.value!=''){
			if(!isValidImage(file_cal_event_image.value)){
				alert("Please specify a valid image format (only allowed jpg,gif,tiff,bmp,png,jpeg,raw format)");
				file_cal_event_image.focus();
				return false;
				}
			
		}
		if(txt_cal_event_detail.value == ''){
			alert('Please specify an Event Description');
			txt_cal_event_detail.focus();
			return  false;
		}
	}	
}

function isValidImage(imagename)
{

	imagefile_value 	= imagename;
	var checkimg 		= imagefile_value.toLowerCase();
	if (!checkimg.match(/(\.jpg|\.gif|\.png|\.JPG|\.GIF|\.PNG|\.jpeg|\.JPEG|\.tiff|\.TIFF|\.bmp|\.BMP|\.raw|\.RAW)$/))
	{
	return false;
	}
	else
	{
	return true;
	}
}

function addEditHumanitarian(form, hType) {
	with(form){
		txt_website.value = Trim(txt_website.value);
		txt_url.value = Trim(txt_url.value);
		if(txt_website.value == ''){
			alert('Please specify a website');
			txt_website.focus();
			return  false;
		}
		if(txt_url.value == ''){
			alert('Please specify the URL');
			txt_url.focus();
			return  false;
		}
		if(opt_category_id.value == '0' || opt_category_id.value == ''){
			alert('Please specify the category');
			opt_category_id.focus();
			return  false;
		}
	}	
	if (hType=='LOCAL' || hType=='local')
	{
		if(form.opt_country.value == '0' || form.opt_country.value == ''){
			alert('Please specify the country');
			form.opt_country.focus();
			return  false;
		}
		if(form.opt_state.value == '0' || form.opt_state.value == '' || form.opt_state.value == 'State'){
			alert('Please specify the state');
			form.opt_state.focus();
			return  false;
		}
	}
}

function validateEventInvitation(form){
	with(form){
		if(file_event_invitation_image.value!=''){
				if(!isValidImage(file_event_invitation_image.value)){
					alert("Please specify a valid image format (only allowed jpg,gif,tiff,bmp,png,jpeg,raw format)");
					file_event_invitation_image.focus();
					return false;
				}	
		}
		
		if(txt_event_invitation_date.value==''){
			alert("Please specify a date with time");
			txt_event_invitation_date.focus();
			return false;
		}
		if(txt_event_invitation_name.value==''){
			alert("Please specify an Event Name");
			txt_event_invitation_name.focus();
			return false;
		}
		if(country.value=='0'){
			alert("Please specify a Country Name");
			country.focus();
			return false;
		}
		if(state.value==''){
			alert("Please specify a State Name");
			state.focus();
			return false;
		}
		
		if(txt_event_invitation_city.value==''){
			alert("Please specify a City Name");
			txt_event_invitation_city.focus();
			return false;
		}
		/*if(txt_event_invitation_location.value==''){
			alert("Please specify a Location Name");
			txt_event_invitation_location.focus();
			return false;
		}*/
		if(txt_event_invitation_street.value==''){
			alert("Please specify a Street Name");
			txt_event_invitation_street.focus();
			return false;
		}
		if(txt_event_invitation_suburb.value==''){
			alert("Please specify a Suburb Name");
			txt_event_invitation_suburb.focus();
			return false;
		}
		if(txt_event_invitation_to.value==''){
			alert("Please specify a atleast one user");
			add_user.focus();
			return false;
		}
	
	}
	
}

function addEditGiving(form) {
	with(form){
		giving_name.value = Trim(giving_name.value);
		giving_description.value = Trim(giving_description.value);

		if (cat_type[0].checked)
		{
			if(pro_cat_id.value == '' || pro_cat_id.value == '0'){
				alert('Please specify Product Category');
				pro_cat_id.focus();
				return  false;
			}
		} else {
			if(ser_cat_id.value == '' || ser_cat_id.value == '0'){
				alert('Please specify Service Category');
				ser_cat_id.focus();
				return  false;
			}
		}
		if(giving_name.value == ''){
			alert('Please specify Title');
			giving_name.focus();
			return  false;
		}
		if(giving_description.value == ''){
			alert('Please specify the description');
			giving_description.focus();
			return  false;
		}
		if(country.value == '0' || country.value == ''){
			alert('Please specify the country');
			country.focus();
			return  false;
		}
		if(state.value == '0' || state.value == '' || state.value == 'State'){
			alert('Please specify the state');
			state.focus();
			return  false;
		}
	}	
}


function addEditReceiving(form) {
	with(form){
		receiving_name.value = Trim(receiving_name.value);
		receiving_description.value = Trim(receiving_description.value);

		if (cat_type[0].checked)
		{
			if(pro_cat_id.value == '' || pro_cat_id.value == '0'){
				alert('Please specify Product Category');
				pro_cat_id.focus();
				return  false;
			}
		} else {
			if(ser_cat_id.value == '' || ser_cat_id.value == '0'){
				alert('Please specify Service Category');
				ser_cat_id.focus();
				return  false;
			}
		}
		if(receiving_name.value == ''){
			alert('Please specify Title');
			receiving_name.focus();
			return  false;
		}
		if(receiving_description.value == ''){
			alert('Please specify the description');
			receiving_description.focus();
			return  false;
		}
		if(country.value == '0' || country.value == ''){
			alert('Please specify the country');
			country.focus();
			return  false;
		}
		if(state.value == '0' || state.value == '' || state.value == 'State'){
			alert('Please specify the state');
			state.focus();
			return  false;
		}
	}	
}

function addEditWhatsOnEventvalidation(form) {
	with(form){
		
		if(event_type.value =="" || event_type.value == 0){
			alert('Please specify an Event Type');
			event_type.focus();
			return  false;
		}
		
		if(event_date.value ==""){
			alert('Please specify a Event Date');
			event_date.focus();
			return  false;
		}

		if(category_id.value == 0){
			alert('Please specify a Category');
			category_id.focus();
			return  false;
		}

		/*if(sub_category_id.value == 0){
			alert('Please specify a Sub Category');
			sub_category_id.focus();
			return  false;
		}	*/	
		
		
		if(event_name.value ==""){
			alert('Please specify an Event');
			event_name.focus();
			return  false;
		}
		
		
		if(location.value ==""){
			alert('Please specify a Location');
			location.focus();
			return  false;
		}
		
		if(street.value ==""){
			alert('Please specify the Street');
			street.focus();
			return  false;
		}
		if(city.value ==""){
			alert('Please specify the City');
			city.focus();
			return  false;
		}
		if(state.value =="" || state.value =="0"){
			alert('Please specify State');
			state.focus();
			return  false;
		}
		if(country.value =="" || country.value =="0"){
			alert('Please specify Country');
			country.focus();
			return  false;
		}
		if(event_detail.value ==""){
			alert('Please specify Event Details');
			event_detail.focus();
			return  false;
		}
		
		if(txt_url_name.value!=""){
			if(txt_url_link.value==""){
				alert("Please specify a URL");
				txt_url_link.focus();
				return false;
			}
			if (txt_url_link.value != "") {
			if(!isUrl(txt_url_link.value)){
				alert("Please specify a valid URL (URL must be starting with http:// or https://)");
				txt_url_link.focus();
				return false;
			}
			else{
				return true;
			}
		}
			
		}
		
		if(txt_url_link.value!=""){
			if(txt_url_name.value==""){
				alert("Please specify a URL name");
				txt_url_name.focus();
				return false;
			}
		}
		
		

	}	
}


function isUrl(s) {
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}
