if (window.ActiveXObject&&document.all)var IE=true;  // Internet Explorer
else if (window.XMLHttpRequest)var MOZ=true; // Mozilla, Safari

var act=false;var r=false;
function a(p,id,t){var u=siteURL+'/ajax.php';if(!act){if(window.ActiveXObject&&document.all)try{r=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{r=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){}}else if(window.XMLHttpRequest){r=new XMLHttpRequest();if(r.overrideMimeType)r.overrideMimeType('text/html');}if(!r){alert('Cannot create XMLHTTP instance');return;}r.onreadystatechange = function(){var s=r.readyState;var e='There was a problem with request. Please try again';if(s==4){

if(r.status==200){var o=document.getElementById(id);
	if(t=='i'&&o){o.innerHTML=r.responseText;if(id=='winPopUp')updateWindowPosition('winPopUp');}
	else if(t=='m')modalWin(id, r.responseText);
				 }
else alert(r.status+' - '+e);act=false;window.status='Ready';}

				   }
r.open('POST',u,true);r.setRequestHeader('Content-type','application/x-www-form-urlencoded');r.setRequestHeader('Content-length',p.length);r.setRequestHeader('Connection','close');window.status='Sending';act=true;r.send(p);}}
function b(sID,dID){var s=[];var ins=document.getElementById(sID).getElementsByTagName('INPUT');for(var i=0;i < ins.length;i++)if(ins[i].type=='checkbox'&&ins[i].checked==true)s.push(ins[i].value);a('filterCatIDs='+arr2str(s,','),dID,'i');}
function arr2str(arr, d){var str='';for(var i=0;i < arr.length;i++) {dlm=(i==0)?'':d;str += dlm+arr[i];}return str;} 
function limitText(o,limitCount,limitNum){if(o.value.length>limitNum)o.value=o.value.substring(0,limitNum);else document.getElementById(limitCount).value=limitNum-o.value.length;}
function changeImage(value) {var img = document.getElementById('AmountImage');img.src = siteURL+'/template/media/voucher/'+value+'pounds.png';}

// Declaring required variables
var digits = "0123456789";
var validWorldPhoneChars = ""; //"+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 11;
var maxDigitsInIPhoneNumber = 11;
function isInteger(s){var i;for(i=0;i<s.length;i++){var c=s.charAt(i);if(((c<"0")||(c>"9")))return false;}return true;}
function stripCharsInBag(s, bag){var i;var returnString="";for(i=0;i<s.length;i++){var c=s.charAt(i);if(bag.indexOf(c)==-1)returnString += c;}return returnString;}

function checkPhone(strPhone){s=stripCharsInBag(strPhone,validWorldPhoneChars);return (isInteger(s) && s.length >= minDigitsInIPhoneNumber && s.length <= maxDigitsInIPhoneNumber);}

/////////////////////////////////////////////////////////////////////////////////////////////////
function $ssOpct(o,n){o.style.opacity=(n/100);o.style.MozOpacity=(n/100);
					  o.style.KhtmlOpacity=(n/100);o.style.filter="alpha(opacity="+n+")";}
function winScrlY(){return window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0;} 
function winScrlX(){return window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft||0;}

function winWidth(){return window.innerWidth!=null?window.innerWidth:document.documentElement &&document.documentElement.clientWidth?document.documentElement.clientWidth:document.body!=null ?document.body.clientWidth:null;}
function winHeight(){return window.innerHeight!=null?window.innerHeight:document.documentElement&& document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}

var WINDOWS = [];
var wsX = null; 
var wsY = null; 
function modalWin(id, html){
	controlsSwitch('hidden');document.onkeypress=kp;switchWinScroll('hidden');
	WINDOWS.push(id);
	var bg=document.createElement('DIV');bg.style.background='#000';bg.id='ModalBackground_'+id;$ssOpct(bg,50);
	bg.style.position='absolute';bg.style.top=0+'px';bg.style.left=0+'px';
	bg.style.width=winWidth()+winScrlX()+'px';bg.style.height=winHeight()+winScrlY()+'px';document.body.appendChild(bg);
	var box=document.createElement('DIV');
	box.style.visibility='hidden';box.id='ModalBox_'+id;box.className='modalBox';document.body.appendChild(box);
	box.style.maxWidth = winWidth()-20+'px';	box.style.maxHeight = winHeight()-20+'px';
	var panel=document.createElement('DIV');panel.className='modalTopPanel';
	panel.innerHTML='<input type="button" class="but_close" onclick="closeModalWin(\''+id+'\');">';
	box.appendChild(panel);
	var content=document.createElement('DIV');content.id=id;box.appendChild(content);
	//content.style.overflow='auto';
	content.innerHTML = html;
	content.style.maxWidth = winWidth()-40+'px';content.style.maxHeight = winHeight()-40+'px';
	//alert(winHeight()+'|'+winWidth());
	//Fix for firefox The reason for the behavior FireFox has is that it doesn't update the DOM element properly until after the event or active function call completes and the browser event loop gets control back.
	window.setTimeout("updateWindowPosition('" + id +"')",1000);  
}

function updateWindowPosition(id){
	var box = document.getElementById('ModalBox_'+id);
	var width=box.offsetWidth;	var height=box.offsetHeight;
	var top = (winHeight()-height)/2+winScrlY();
	var left = (winWidth()-width)/2+winScrlX();
	box.style.top = top+'px'; box.style.left=left+'px';
	box.style.visibility='';
}

function closeModalWin(id){
	WINDOWS.pop(id);
	controlsSwitch('');if(o=document.getElementById('ModalBox_'+id))o.parentNode.removeChild(o);document.onkeypress=''; 
	if(o=document.getElementById('ModalBackground_'+id)){switchWinScroll('');o.parentNode.removeChild(o);}
}

function switchWinScroll(n){
	if(WINDOWS.length==0){
		if(n=='hidden'){wsY = winScrlY(); wsX = winScrlX();}
		document.body.style.overflow=n;document.getElementsByTagName('HTML')[0].style.overflow=n;
		window.scrollTo(wsX, wsY);
						 }
}
function kp(e){var kC=(IE)?event.keyCode:e.keyCode;var Esc=(IE)?27:e.DOM_VK_ESCAPE;if(kC==Esc)closeModalWin(WINDOWS.pop());}
function controlsSwitch(n){
	var tag=document.getElementsByTagName('SELECT');for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=n;
	var tag=document.getElementsByTagName('IFRAME');for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=n;
	var tag=document.getElementsByTagName('OBJECT');for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=n;
}

function validateForgottenForm(form) {
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (!filter.test(form.email.value)){alert('Please enter valid email address');form.email.select();return false;}
	else return true;
}

