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


function checkLength(textField,max,errorField){
	
	var textFieldValue=trim(textField.value);
	

	if(textFieldValue.length>=max){
		
		errorField.innerHTML="Field Lenght is More Then Size";
		errorField.style.visibility='visible';
		textField.style.border='#FF3333 solid 1px';
		textField.focus();
		return false;
	
	}else{

		errorField.style.visibility='hidden';
		textField.style.border='#339900 solid 1px';
		return "";
		//return true;
	}


}

function checkFieldEmpty(textField,errorField){
	
	var textFieldValue=trim(textField.value);
	

	if(textField=="" || textFieldValue.length==0){// && textField=" "){

		errorField.innerHTML="Field Can't Leave Empty";
		errorField.style.visibility='visible';
		textField.style.border='#FF3333 solid 1px';
		textField.focus();
		return false;
		
	}else{

		errorField.style.visibility='hidden';
		textField.style.border='#339900 solid 1px';
				//return true;
		return "";
	}


}

function checktextareaLength(textareaField,max,errorField){
	
	var areaValue=trim(textareaField.value);

	if(areaValue.length>=max){
	
		errorField.innerHTML="Text Area Length Is More Then Limit ";
		errorField.style.visibility='visible';
		textareaField.style.border='#FF3333 solid 1px';
		
		textareaField.focus();
		return false;
	
	}else{

		errorField.style.visibility='hidden';
		textareaField.style.border='#339900 solid 1px';
		return "";
			//return true;
	}

}

function checktextareaEmpty(textareaField,errorField){
	
	var areaValue=trim(textareaField.value);

	if(textareaField=="" && areaValue.length==0){
	
		errorField.innerHTML="Text Area Can't Empty ";
		errorField.style.visibility='visible';
		
		textareaField.focus();
		return false;
	
	}else{

		errorField.style.visibility='hidden';
		return "";
			//return true;
	}

}


function onSubmited(theForm){
	
	var reason = "";

  
  reason += checkFieldEmpty(document.getElementById('visiter_name'),document.getElementById('errorshow'));
  
  reason += chkEmail(document.getElementById('visiter_email'),document.getElementById('emailerrorshow'));
  
  reason += checkFieldEmpty(document.getElementById('add_line1'),document.getElementById('line1errorshow'));
  
  reason += checkFieldEmpty(document.getElementById('add_city'),document.getElementById('cityerrorshow'));
  
  reason += checkFieldEmpty(document.getElementById('add_state'),document.getElementById('stateerrorshow'));
  
  reason += checkFieldEmpty(document.getElementById('add_country'),document.getElementById('countryerrorshow'));
  
  reason += checkFieldEmpty(document.getElementById('pnoneno'),document.getElementById('pnonenoerrorshow'));
  
  reason += checkFieldEmpty(document.getElementById('f_guru'),document.getElementById('f_guruerrorshow'));
  
  reason += checkFieldEmpty(document.getElementById('katha_date'),document.getElementById('katha_dateerrorshow'));
  
  reason += checkFieldEmpty(document.getElementById('date_start'),document.getElementById('date_starterrorshow'));
  
  reason += checkFieldEmpty(document.getElementById('date_end'),document.getElementById('date_enderrorshow'));
  
  reason += checkFieldEmpty(document.getElementById('tot_day'),document.getElementById('tot_dayerrorshow'));
  
  reason += checkFieldEmpty(document.getElementById('katha_country'),document.getElementById('katha_countryerrorshow'));
  
  reason += checkFieldEmpty(document.getElementById('katha_state'),document.getElementById('katha_stateerrorshow'));
  
  reason += checkFieldEmpty(document.getElementById('katha_city'),document.getElementById('katha_cityerrorshow'));
  
  reason += checkFieldEmpty(document.getElementById('org_name'),document.getElementById('org_nameerrorshow'));
  
  reason += checkFieldEmpty(document.getElementById('inviter_desi'),document.getElementById('inviter_desierrorshow'));
  
  
  
  //reason += checkFieldEmpty(document.getElementById('user'),document.getElementById('errorshowid'));
  
  if(document.getElementById('hide_orgStatus').style.visibility == "visible"){
  	
	reason += checkFieldEmpty(document.getElementById('other_status'),document.getElementById('other_statuserrorshow'));
  
  }
  
  
      
  if(reason !="") {
   // alert("Some fields need correction:\n" + reason);
    
  }else{
		theForm.submit();
  }

 


}

function selectionShow(selectionId,option,showItem,txtbox){
		

	var selectionValue=trim(selectionId.value);
	//alert(selectionValue);
	var opt=trim(option);
	if(selectionValue==opt){

		showItem.style.visibility='visible';
		txtbox.style.visibility='visible';

	}else{
	
		showItem.style.visibility='hidden';
		txtbox.style.visibility='hidden';
	}

}


function selectRadioButton(buttonID,ShowItem){
	
	var buttonValue=trim(buttonID.value);
	alert(buttonValue);

	if(buttonValue=="all"){
		
		showItem.style.visibility='visible';
		
	}else{
		
		showItem.style.visibility='hidden';
	
	}
	
}

function chkEmail(elem, errorField){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		
		return "";
	}else{
		errorField.innerHTML="Please Enter Valid Email Address";
		errorField.style.visibility='visible';
		elem.style.border='#FF3333 solid 1px';
		elem.focus();
		return false;
		
		
	}
}
