var baseurl ='http://gofrostfire.com/';

$(document).ready(function() {	
	
		$("#placeaddform").submit(function () {	
 		
			if($(this).validation()==true)
			{	
	     	
			 	   if((document.getElementById("checkcrct").checked)==true) { 
		                       
				   						 		return true;
	  							}
  							 	alert("Please approve that the  address and location set in the map are correct");
  							 	return false; 
			}
			return false; 	
	});
	
			
});

/* Global Functions */

(function($) {

$.fn.validation = function() {		

    var error = 0;
		
	$('.required', this).each(function() {																																													
		var input = $(':input', this).attr("value");	
			
		var display_name = $(':input', this).attr("id");		
		input = jQuery.trim(input);
		
		if (input == "") {
			//$('span.error-message', this).remove();
			//$(this).append('<span class="error-message"><span class="error"></span></span>');
		//	$('span.error', this).html(' mandatory field.');
			$(':input', this).addClass("error-highlight");
			display_name = ((display_name.replace('_',' ')).replace('_',' ')).replace('_',' ');
			error++;
			$(':input', this).val('');
			$(':input', this).focus();
			
			alert('Please enter '+ display_name.toLowerCase());			
		 return false;		
		} else {
			$('span.error-message', this).remove();
			$(':input', this).removeClass("error-highlight");
		}
	});
	
	if (error == 0) {
		return true;
	} else {
		return false;
	}
};

})(jQuery);



/* email address validation */
function checkEmail(emailString)
{
	splitVal = emailString.split('@');
	
	if(splitVal.length <= 1) 
	{
		alert("Please enter a valid email address ");
		return false;
	}
	if(splitVal[0].length <= 0 || splitVal[1].length <= 0) 
	{
		alert("Please enter a valid email address ");
		return false;
	}
	
	splitDomain = splitVal[1].split('.');
	if(splitDomain.length <= 1) 
	{
		alert("Please enter a valid email address  ");
		return false;
	}
	
	if(splitDomain[0].length <= 0 || splitDomain[1].length <= 1) 
	{
		alert("Please enter a valid email address  ");
		return false;
	}
	return true;
}

// Function To Check Whether The Value Entered Is A Non Negative Integer 

function check_number(sText)
{   
   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;        
         }
      }
   return IsNumber;
}





// Function To Check Whether The Value Entered Is A Non Negative Float 

function check_numeric(sText)
{   
   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;        
         }
      }
   return IsNumber;
}





  function specialCharCheck(strng)
		{
		  var iChars = "\\";
		  var a1 = new Array();
		  a1 = strng.split("\\");		  
    a_count = (a1.length)-1;    
    strng = a1[a_count];

					 var iChars = "!@#$%^&*()+=-[]\'';,/{}|\":<>?~`";
						var iCharsspace = " ";
						for (var i = 0; i < strng.length; i++) 
						{
								if (iChars.indexOf(strng.charAt(i)) != -1) 
								{								    
												alert("Filename contains special characters. \n These are not allowed.\n Please remove them and try again.");
												return false;
								} 	
								if (iCharsspace.indexOf(strng.charAt(i)) != -1) 
								{
												alert("Filename contains special characters. \n These are not allowed.\n Please remove them and try again.");
												return false;
								} 	
						}	
					return true;
					
	 }
	 
	 
/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtdq = new Date();
var dtCh= "-";
var minYear = dtdq.getFullYear();
var maxYear=2100;

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 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 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 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 isDate(dtStr){
	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 (pos1==-1 || pos2==-1){
		alert("The date format should be : mm-dd-yyyy")
		return false
	}
	
	if (strMonth.length<2)
	{
	 alert("The month format should be : mm")
		return false
	}
	
	if (strDay.length<2)
	{
	 alert("The day format should be : dd")
		return false
	}
	
	
	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 (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function resize_iframe(){
document.getElementById("sizeframe").height=100 // required for Moz, value can be "", null, or integer
document.getElementById('sizeframe').height=window.frames["sizeframe"].document.body.scrollHeight+20;
}
