/* WapoLabs reg view footer scripts
 *
 * Call this script AFTER JQuery
 */

/* Cancel link */


function cancelAndClose(href) {
	try {
		document.domain = clientDomain; 
		if(typeof(window.parent.tb_remove) !== 'undefined') {
			//iframe and access to parent
			window.parent.tb_remove();
			if (typeof(window.parent.wapoThickBoxCloseCallback) !== 'undefined') {
				window.parent.wapoThickBoxCloseCallback();
			}
		} else {
			//not an iframe, but access to parent, so made it past the try (but we also don't care)
			if(self !== top){
				//an iframe
  				window.location = close_url;
			} else {
			window.location = href;
			}
		}
		return false;
	} catch(e) {
		try {
			//an iframe, but no access to parent (set it and forget it)
	 		window.location = close_url;
		} catch(e) {
			//not an iframe and no access to parent
			window.location = href;
		}
		return false;
	}
}


$wpjQ(function(){
	$wpjQ('#wapolabs_wrapperCancel a').click(function () {
		cancelAndClose($wpjQ(this).attr('href'));
		return false;
	});
});

$wpjQ(function(){
	$wpjQ('#wapolabs_wrapperCancelTop a').click(function () {
		cancelAndClose($wpjQ(this).attr('href'));
		return false;
	});
});

