/**
 * @author enavarro
 */
function emailCheck (emailStr) {
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");	
	//the e-mail address can be blank
	if (emailStr == '') {alert("Please enter an email address");return false;}	
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		alert("Please check Email address,It seems incorrect)");
		return false;
	}
	return true;
}
/**
 * Cross Domain tagging google analytics
 * This function is called when a tracked link is clicked, tag for google anal
 */
function tagLink(link_href) {
	// Check if pageTracker or urchinTracker are present	
	if (typeof pageTracker != 'undefined') {
		pageTracker._link(link_href);
		return false;
	}
	else if (typeof urchinTracker != 'undefined') {
		__utmLinker(link_href);
		return false;
	}
	else {
		return true;
	}
}
function handleCarTrawlerOTAAvailError(errorMsg){alert(errorMsg);}
/*
Improved version for send function
More Generic.
@Attribute Email is the email to send
*/
function sendToArgusRentals(country,affId,email){	
	if (emailCheck(email)) {	
		var nWidth = 330;
		var nHeight = 150;
		var nTop = (screen.height - nHeight) / 2;
		var nLeft = (screen.width - nWidth) / 2;
		var sPref = 'toolbar=no,menubar=no,location=no,directories=no,status=yes,scrollbars=no,resizable=yes,copyhistory=no,width=' + nWidth + ',height=' + nHeight + ',screenX=' + nLeft + ',screenY=' + nTop + ',top=' + nTop + ',left=' + nLeft;		
		window.open("http://www.argusrentals.com/scripts/email/save.asp?country=" + country.toString() +"&id="+ affId.toString() +"&ad="+ email.toString(),"_blank",sPref.toString());
	}	
}

function send_info(affId) {	
	e = document.getElementById("user_email").value;
	if(emailCheck(e)) {
		x = document.getElementById("abe_residenceList");
		c = x.options[x.selectedIndex].value;
		if (c == "") c = "UK";
		sendToArgusRentals(c,affId,e);
		
		try { //Tracking GA Email Sign Up Goal
		  if (pageTracker && pageTrackerGen) {
		  	pageTracker._trackPageview("/Email_Captured");
			pageTrackerGen._trackPageview("/Email_Captured");
		  }
		}catch(err){}
	}
}
function openpopup(popurl, width, height){
var winpops=window.open(popurl, "", "width=" + width + ",height=" + height + ",status,resizable")
}

/*
* Compare to dates, format: ddmmyy 
* @param {string} dat1 Max offers to display (rows)
* @param {string} dat2 String with the corrent language for the word 
* @return true when dat1 is smaller than dat2
* @return false when dat1 is bigger than dat2 
* */
function compareDates(dat1,dat2){
d1 = new Number(dat1.substr(0,2));
m1 = new Number(dat1.substr(2,2));
y1 = new Number(dat1.substr(4,5));	

d2 = new Number(dat2.substr(0,2));
m2 = new Number(dat2.substr(2,2));
y2 = new Number(dat2.substr(4,5));	
if(y1 > y2)return false;
else if( m1 > m2 && y1 >= y2){return false;}
else if (d1>d2 && m1 >= m2 && y1 >= y2 )return false;
return true;
}

/* configYCalendar /
*  This function set the limits dates to choose a flight.
*  1 year from the current date
*  The configuration returned is JSON object. This is used for the Calendar constructor
*  @return: JSON object.
*/
function configYCalendar() {
   var _pagedate,_mindate,_maxdate;   
   date = new Date();  
   _pagedate = (date.getMonth() + 1) + "/" + date.getFullYear();
   _mindate = (date.getMonth() + 1) + "/" + date.getDate() + "/" + date.getFullYear();
   _maxdate = (date.getMonth() + 1) + "/" + date.getDate() + "/" + (date.getFullYear() + 1);   
   return {pagedate: _pagedate.toString() ,mindate:_mindate.toString() ,maxdate:_maxdate.toString(),title:"Choose a date:",close:true};
}

function cleanInput(obj){ if(obj.value.indexOf("@") < 0) obj.value=""}

function radioInputValue(radioNodeList) {
	for (var i = radioNodeList.length - 1; i > -1; i--) {
		if (radioNodeList[i].checked) {
			return radioNodeList[i].value;

		}
	}
return false;
}

// jQuery plugins below - do not edit!
// jQuery plugin - superBox - for popups
(function(i){var l,t,r,q,a,p,h,o,j,w,b={boxId:"superbox",boxClasses:"",overlayOpacity:0.8,boxWidth:"600",boxHeight:"400",loadTxt:"Loading...",closeTxt:"Close",prevTxt:"Previous",nextTxt:"Next"},x={},m=false,s=i([]);
i.superbox=function(){w=i.extend({},b,i.superbox.settings);
if(i.browser.msie&&i.browser.version<7){s=s.add("select")
}n();
z()
};
function z(){i("a[rel^=superbox]").each(function(){var D=i(this),F=D.attr("rel"),B=F.match(/^superbox\[([^#\.\]]+)/)[1],E=F.replace("superbox","").match(/([#\.][^#\.\]]+)/g)||[],C=w.boxId,A=w.boxClasses;
this._relSettings=F.replace("superbox["+B+E.join("")+"]","");
i.each(E,function(G,H){if(H.substr(0,1)=="#"){C=H.substr(1)
}else{if(H.substr(0,1)=="."){A+=" "+H.substr(1)
}}});
if(B.search(/^image|gallery|iframe|content|ajax$/)!=-1){D.superbox(B,{boxId:C,boxClasses:A})
}})
}i.fn.superbox=function(B,A){A=i.extend({},w,A);
i.superbox[B](this,A)
};
i.extend(i.superbox,{image:function(C,A,B){var E=f(C.get(0)),D=false;
if(E&&B=="gallery"){D=E[1]
}else{if(E){D=E[0]
}}C.click(function(F){F.preventDefault();
k();
if(B=="gallery"){c(C,E[0])
}y(function(){var H=false,G;
if(D){H=D.split("x")
}G=i('<img src="'+C.attr("href")+'" title="'+(C.attr("title")||C.text())+'" />');
G.load(function(){g(G,H);
e({boxClasses:"image "+A.boxClasses,boxId:A.boxId});
u()
}).appendTo($innerbox)
})
})
},gallery:function(B,A){var C=f(B.get(0));
if(!x[C[0]]){x[C[0]]=[]
}x[C[0]].push(B);
B.get(0)._superboxGroupKey=(x[C[0]].length-1);
i.superbox.image(B,A,"gallery")
},iframe:function(B,A){var C=f(B.get(0));
B.click(function(D){D.preventDefault();
k();
y(function(){var F=false,E;
if(C){F=C[0].split("x")
}A=i.extend({},A,{boxWidth:F[0]||A.boxWidth,boxHeight:F[1]||A.boxHeight});
E=i('<iframe src="'+B.attr("href")+'" name="'+B.attr("href")+'" frameborder="0" scrolling="no" hspace="0" width="'+A.boxWidth+'" height="'+A.boxHeight+'"></iframe>');
E.load(function(){q.width(A.boxWidth+"px");
$innerbox.height(A.boxHeight+"px");
e({boxClasses:"iframe "+A.boxClasses,boxId:A.boxId});
u()
}).appendTo($innerbox)
})
})
},content:function(B,A){var C=f(B.get(0));
B.click(function(D){D.preventDefault();
k();
y(function(){var E=false;
if(C){E=C[0].split("x")
}A=i.extend({},A,{boxWidth:E[0]||A.boxWidth,boxHeight:E[1]||A.boxHeight});
q.width(A.boxWidth+"px");
$innerbox.height(A.boxHeight+"px");
i(B.attr("href")).clone().appendTo($innerbox);
e({boxClasses:"content "+A.boxClasses,boxId:A.boxId});
u()
})
})
},ajax:function(B,A){var C=f(B.get(0));
B.click(function(D){D.preventDefault();
k();
y(function(){var E=false;
if(C&&C[3]){E=C[3].split("x")
}A=i.extend({},A,{boxWidth:E[0]||A.boxWidth,boxHeight:E[1]||A.boxHeight});
q.width(A.boxWidth+"px");
$innerbox.height(A.boxHeight+"px");
i.get(C[2],function(F){i(F).appendTo($innerbox)
});
e({boxClasses:"ajax "+A.boxClasses,boxId:A.boxId});
u()
})
})
}});
function f(A){return A._relSettings.match(/([^\[\]]+)/g)
}function g(A,B){q.width(A.width()+($innerbox.css("paddingLeft").slice(0,-2)-0)+($innerbox.css("paddingRight").slice(0,-2)-0));
$innerbox.height(A.height());
if(B&&B[0]!=""){q.width(B[0]+"px")
}if(B&&B[1]!=""&&B[1]>A.height()){$innerbox.height(B[1]+"px")
}}function c(C,D){h.show();
m=true;
var A=C.get(0)._superboxGroupKey+1,B=A-2;
if(x[D][A]){o.removeClass("disabled").unbind("click").bind("click",function(){x[D][A].click()
})
}else{o.addClass("disabled").unbind("click")
}if(x[D][B]){j.removeClass("disabled").unbind("click").bind("click",function(){x[D][B].click()
})
}else{j.addClass("disabled").unbind("click")
}}function e(A){q.attr("id",A.boxId).attr("class",A.boxClasses)
}function d(){i(document).unbind("keydown");
p.hide();
h.hide();
t.hide().css({position:"fixed",top:0})
}function v(A){d();
l.fadeOut(300,function(){s.show()
});
m=false
}function y(B){var A=function(){if(i.browser.msie&&i.browser.version<7){t.css({position:"absolute",top:"150px"})
}s.hide();
p.show();
B()
};
if(m){l.css("opacity",w.overlayOpacity).show();
A()
}else{l.css("opacity",0).show().fadeTo(300,w.overlayOpacity,A)
}}function k(){t.show();
$innerbox.empty();
q.css({position:"absolute",top:"-99999px"})
}function u(){p.hide();
i(document).unbind("keydown").bind("keydown",function(A){if(A.keyCode==27){v()
}if(A.keyCode==39&&o.is(":visible")){o.click()
}if(A.keyCode==37&&j.is(":visible")){j.click()
}});
q.css({position:"static",top:0,opacity:0});
if(i.browser.msie&&i.browser.version<8){q.css({position:"relative",top:"-80%"});
if(i.browser.msie&&i.browser.version<7){t.css({position:"relative",top:"-80%"})
}}if(i(window).height()<t.height()){t.css({position:"absolute",top:(t.offset().top+10)+"px"})
}q.fadeTo(300,1)
}function n(){if(!i.superbox.elementsReady){l=i('<div id="superbox-overlay"></div>').appendTo("body").hide();
t=i('<div id="superbox-wrapper"></div>').appendTo("body").hide();
r=i('<div id="superbox-container"></div>').appendTo(t);
q=i('<div id="superbox"></div>').appendTo(r);
$innerbox=i('<div id="superbox-innerbox"></div>').appendTo(q);
h=i('<p class="nextprev"></p>').appendTo(q).hide();
j=i('<a class="prev"><strong><span>'+w.prevTxt+"</span></strong></a>").appendTo(h);
o=i('<a class="next"><strong><span>'+w.nextTxt+"</span></strong></a>").appendTo(h);
a=i('<p class="close"><a><strong><span>'+w.closeTxt+"</span></strong></a></p>").prependTo(q).find("a");
p=i('<p class="loading">'+w.loadTxt+"</p>").appendTo(r).hide();
l.add(t).add(a).click(function(){v()
});
q.click(function(A){A.stopPropagation()
});
i.superbox.elementsReady=true
}}})(jQuery);
// end of superbox
/* Helper function, describe element of a function */
function listProperties(obj) {
   var propList = "";
   for(var propName in obj) {
      if(typeof(obj[propName]) != "undefined") {
         propList += (propName + ", ");
      }
   }
   alert( "Resul: " + propList);
}

/* Black Pop Up*/
function setPopUpConfig(_w,_h) {

var bWidth = _w; // Pop up box Width 
var bHeight = _h; // Pop up box Height 
var nTop = nLeft = 0;

/* Calculate window position */
arrayPageScroll = getPageScroll();
arrayPageSize = getPageSize();

nTop = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - bHeight) / 2));
nLeft =((arrayPageSize[0] - 20 - bWidth) / 2);
/* end calculate box size */
$("#popup-window").width(_w);

	if (_h > 400) { /*This is for the a boxes bigger than 400, they will scroll down */
		$("#popup-window").height(_h);
	}
	else if ($("#popup-window").height() > 400) { /* Reset height */
		$("#popup-window").height("");
	}
		
	$("#b-overlay").height(arrayPageSize[1]);
	$("#popup-window").css("top", nTop);
	$("#popup-window").css("left", nLeft);	
	
	/*IE 6 hack*/
	if (navigator.appVersion.indexOf("MSIE 6.0") != -1) {
		$("#b-overlay").height(screen.availHeight);
		$("#b-overlay").width(arrayPageSize[0]);		
	}
	
	//Add Close function to the pop up
	$("#forgot_close").click(function(e){
		e.preventDefault();
		
		$("#b-overlay").fadeOut("slow");
		$("#popup-window").fadeOut(600);
		if($("select"))
			$("select").show();
	});
}

function showPopUp(){		 				  
	if($("select"))
		$("select").hide();
		
	$("#b-overlay").fadeIn("slow");			  
	$("#popup-window").fadeIn(500);						
}

/* end pop up functions */
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
function getPageSize(){
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
function getPageScroll() {
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	return ['',yScroll]; 	
}
// findPos()
// Returns array with x,y coordinates for the obj
// Core code from - quirksmode.org
function findPos(obj) {	
	var curleft = curtop = 0;	
	if (obj.offsetParent) {		
		do {			
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			
		} while (obj = obj.offsetParent);
	}		
return [curleft,curtop];	
}
/* end black pop up*/