var siteurl = 'http://' + location.host + '/';
var companyname = 'Lost & Found Pets Ireland';
function checkEmail(inputvalue){	
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test(inputvalue)){         
		return true; 
    }else{   
		return false;
    }
}
function checkNumber(inputvalue){	
    var pattern=/^(083|085|086|087|089)[ ]?[0-9]{5,8}$/;
    if(pattern.test(inputvalue))
	{         
		return true; 
    }
	else
	{   
		var patternUK=/^(071|072|073|074|075|077|078|079)[ ]?[0-9]{7,8}$/;
		if(patternUK.test(inputvalue))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}

function checkPhone(inputvalue){
	var pattern=/^[0-9 ]{5,12}$/;
	if(pattern.test(inputvalue)){
		return true;	
	}else{
		return false;	
	}
}
var imagetypes = new Array('jpg','jpeg','pjpg','pjpeg');

function processIndicator()
{
	$('#div_frm').hide('slow');
	$('#div_status').show('slow');
	setInterval('toggleStatus()', 2000);	
}
$ts = 0;
function toggleStatus()
{
		lbl_status = document.getElementById('lbl_status');
		if($ts == 0)
		{
			lbl_status.innerHTML = 'Processing, please wait...'
			$ts = 1;
		}
		else
		{
			lbl_status.innerHTML = 'Something IS happening, honest...';
			$ts = 0;
		}
}

function getHTTPObject() {

  var xmlhttp;

  /*@cc_on

  @if (@_jscript_version >= 5)

    try {

      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e) {

      try {

        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (E) {

        xmlhttp = false;

      }

    }

  @else

  xmlhttp = false;

  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

    try {

      xmlhttp = new XMLHttpRequest();

    } catch (e) {

      xmlhttp = false;

    }

  }

  return xmlhttp;

}


var callback;
var req;
function ajaxIt(data,url,async)
{
	url = siteurl + url;
	req = getHTTPObject();
	if (req)
	{
		req.onreadystatechange = processReqChange;
    	req.open("POST", url, async);
    	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.send(data);
	}
}

function processReqChange()
{
	if (req.readyState == 4)
	{
		if (req.status == 200)
		{
			eval(callback + '(req.responseText);');
        }
		else
		{
			//eval(callback + '(There was a problem returning data from the server. The specific error was:<br/><br/>' + req.statusText + ');');
		}
	}
}

function isValidDate(day,month,year)
{
/*
Purpose: return true if the date is valid, false otherwise

Arguments: day integer representing day of month
month integer representing month of year
year integer representing year

Variables: dteDate - date object

*/
var dteDate;

//set up a Date object based on the day, month and year arguments
//javascript months start at 0 (0-11 instead of 1-12)
dteDate=new Date(year,month,day);

/*
Javascript Dates are a little too forgiving and will change the date to a reasonable guess if it's invalid. We'll use this to our advantage by creating the date object and then comparing it to the details we put it. If the Date object is different, then it must have been an invalid date to start with...
*/

//return ((day==dteDate.getDate()) && (month==dteDate.getMonth()) && (year==dteDate.getFullYear()));
return true;
}

//cookie functions
function setCookie(name, value, expires, path, domain, secure) {
  now = new Date();
  now.setTime(now.getTime() + expires);
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + now.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

$.preloadImages("assets/imsages/mailinglist_on.gif");