var sBrowserVersion = navigator.appVersion;

var IE  = (document.all) ? true : false;
var IE4 = (IE && !document.getElementById) ? true : false;
var IE5 = (IE && document.getElementById) ? true : false;
var IE6 = IE5 ? (sBrowserVersion.match(/MSIE 5/) ? false : true) : false;

var NS4 = (document.layers) ? true : false;
var NS6 = (document.getElementById && !IE) ? true : false;


var EmailCk ="5";
var CharArray1 = new Array(
' ', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-',
'.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';',
'<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e',
'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', '', 'Ç', 'ü',
'é', 'â', 'ä', 'à', 'å', 'ç', 'ê', 'ë', 'è', 'ï', 'î', 'ì', 'Ä', 'Å',
'É', 'æ', 'Æ', 'ô', 'ö', 'ò', 'û', 'ù', 'ÿ', 'Ö', 'Ü', 'ø', '£', 'Ø',
'×', 'ƒ', 'á', 'í', 'ó', 'ú', 'ñ', 'Ñ', 'ª', 'º', '¿', '®', '¬', '½',
'¼', '¡', '«', '»', '_', '_', '_', '¦', '¦', 'Á', 'Â', 'À', '©', '¦',
'¦', '+', '+', '¢', '¥', '+', '+', '-', '-', '+', '-', '+', 'ã', 'Ã',
'+', '+', '-', '-', '¦', '-', '+', '¤', 'ð', 'Ð', 'Ê', 'Ë', 'È', 'i',
'Í', 'Î', 'Ï', '+', '+', '_', '_', '¦', 'Ì', '_', 'Ó', 'ß', 'Ô', 'Ò',
'õ', 'Õ', 'µ', 'þ', 'Þ', 'Ú', 'Û', 'Ù', 'ý', 'Ý', '¯', '´', '­', '±',
'_', '¾', '¶', '§', '÷', '¸', '°', '¨', '·', '¹', '³', '²', '_', ' ');




//-----------------------------------------------------------------------------------------

//generic function to get a field
function getElement(loField)
{
	if (loField && typeof(loField) == 'string') //loField instanceof String)
	{
		loField = document.getElementById(loField);
	}
	return (loField)
} // getElement()

//--------------------------------------------------

function maximiseBrowser(){
	try{
		window.moveTo(0,0);
		window.resizeTo(window.screen.availWidth,window.screen.availHeight);	
	}
	catch(e){
		;
	}
}

function PreLoadImages()
{
	loadImg(gsImgPath + 'home_tab_ov.gif');
	loadImg(gsImgPath + 'tabbg_ov.gif');
	loadImg(gsImgPath + 'tabendspacer_ov2.gif');	
	loadImg(gsImgPath + 'tabspacer_ov.gif');	
	loadImg(gsImgPath + 'tabspacer_ov2.gif');	
	loadImg(gsImgPath + 'tabspacer_purp1_ov2.gif');	
	loadImg(gsImgPath + 'tabspacer_purp2_ov.gif');

	gaPreloadImages = Array('Home_Tab_ov.gif', 
		'tabBg_ov.gif',
		'tabEndSpacer_ov2.gif',	
		'tabSpacer_ov.gif',	
		'tabSpacer_ov2.gif',	
		'tabspacer_purp1_ov2.gif',	
		'tabspacer_Purp2_ov.gif');
	MM_preloadImages(gaPreloadImages);

} // PreLoadImages()

//--------------------------------------------------

function MM_preloadImages(laPreloadImages) //v3.0
{ 
	var i, j; 
	if(document.images)
	{ 

		if(!document.MM_p)
		{
			document.MM_p = new Array();
		}
		j = document.MM_p.length;
		for(i=0; i<laPreloadImages.length; i++)
		{
			if (laPreloadImages[i].indexOf("#")!=0){ 
				document.MM_p[j]=new Image; 
				document.MM_p[j++].src = gsImgPath + laPreloadImages[i];
			}
		}
	}
} // MM_preloadImages

//--------------------------------------------------

function makeHomePage(elem, lsRootFolder)
{
	return makeHomePage2(elem, lsRootFolder, 'http://www.myoffers.co.uk');
}

function makeHomePage2(elem, lsRootFolder, lsUrl)
{
	try
	{
		elem.style.behavior = 'url(#default#homepage)';
		elem.setHomePage(lsUrl);
	}
	catch(e)
	{
		alert('We could not set your homepage because:\n\n' + e.message);
	}	
	if (lsRootFolder)
	{
		location.href = lsRootFolder;
	}
	return (false);

}

//--------------------------------------------------

function FrameBuster(lsServerName, lsVisitKey, lsUrl)
{
	var oRe, lsDelim; 
	oRe = new RegExp(lsServerName, "gi");
	lsUrl = lsUrl ? lsUrl : location;
	if (lsVisitKey)
	{
		lsDelim = location.search ? '&' : '?';
		lsUrl = lsUrl + lsDelim + 'VisitKey=' + escape(lsVisitKey);
	}
	try
	{
		if (top != self && top.location && !top.location.toString().match(oRe) && document.body && document.body.clientHeight > 10)
		{
			top.location = unescape(lsUrl);
		}
	}
	catch(e)
	{
		if (top != self && document.body && document.body.clientWidth > 10 && document.body.clientHeight > 10)
		{
			top.location = unescape(lsUrl);
		}
		//alert('e.description: ' + e.description);
	}
} // FrameBuster()

//--------------------------------------------------

function IsIn(inArray, inItem)
{
	var iArrayIndex, bIsIn;
	bIsIn = false;
	for (iArrayIndex in inArray)
	{
		if (inArray[iArrayIndex] == inItem)
		{
			bIsIn = true;
			break;
		}
	}
	return(bIsIn);
}

//---------------------------------------------------------------------------

function ScrollToEnd()
{
	window.scrollTo(0,999999);
}

//---------------------------------------------------------------------------

/* use this to find width (& height) : javascript:alert(document.body.clientWidth) */

var winPopup;

function popupWindow(strUrl, liWidth, liHeight, strName, bNoScroll, bWindowFeatures, bPopunder)
{
	// IMPORTANT : don't use string with space for strName (name of window handler)... it won't work for IE

	var sParams, liScreenX, liScreenY;
	if (!strName)
	{
		strName = 'winPopup';
	}

	if(window.screen)
	{
		liWidth = (liWidth ? Math.min(liWidth, window.screen.availWidth-45) : window.screen.availWidth-45);
		liHeight = (liHeight ? Math.min(liHeight, window.screen.availHeight-60) : window.screen.availHeight-60);

		liScreenX = (window.screen.availWidth - liWidth) /2
		liScreenY = (window.screen.availHeight - 20 - liHeight) /2
	}

	//alert(liScreenX + '::' + liWidth)
	//alert(liScreenY + '::' + liHeight)

	sParams = (bWindowFeatures ? 'menubar=1;toolbar=1,titlebar=1,status=1,' : 'toolbar=0,titlebar=0,status=0,') 
		+ 'scrollbars=' + (bNoScroll ? 0 : 1) + ',resizable=' + (bNoScroll ? 0 : 1) 
		+ (liWidth ? ',width=' + liWidth : '') + (liHeight ? ',height=' + liHeight : '')
		+ ",left=" + liScreenX + ",top=" + liScreenY + ",screenX=" + liScreenX + ",screenY=" + liScreenY ;

	winPopup = window.open(strUrl, strName, sParams);

	if (bPopunder && winPopup)
	{
		window.focus()
	}
	else if (winPopup)
	{
		winPopup.focus();
	}
	return (winPopup);
}

//--------------------------------------------------

function resizeWindow(liWidth, liHeight)
{
	var liScreenX, liScreenY, liHeight, liWidth, liMarginWidth, liMarginHeight, liInnerWidth;

	if (window.screen)
	{
		liMarginWidth = 45;
		liMarginHeight = 60;
		liWidth = (liWidth ? Math.min(liWidth, window.screen.availWidth - liMarginWidth) : window.screen.availWidth - liMarginWidth);
		liHeight = (liHeight ? Math.min(liHeight, window.screen.availHeight - liMarginHeight) : window.screen.availHeight - liMarginHeight);

		liScreenX = (window.screen.availWidth - liWidth) /2
		liScreenY = (window.screen.availHeight - 20 - liHeight) /2
		
		window.moveTo(liScreenX, liScreenY);
		window.resizeTo(liWidth, liHeight);
		
		liInnerWidth = document.all ? document.body.clientWidth : window.innerWidth;
		while (liInnerWidth && liInnerWidth > 770)
		{
			liWidth-=5;
			window.resizeTo(liWidth, liHeight);
			liInnerWidth = document.all ? document.body.clientWidth : window.innerWidth;
		}
	}

	return(true);
} //resizeWindow

//--------------------------------------------------

function popupNoScrollWindow(strUrl, liWidth, liHeight, strName, bPopunder)
{
	winPopup = popupWindow(strUrl, liWidth, liHeight, strName, true, false, bPopunder)
	return (winPopup);
}

function popupNormal(strUrl, strName)
{
	if (!strName)
	{
		strName = 'winPopup';
	}
	winPopup = window.open(strUrl, 'winPopup');
	return (winPopup);
}

//---------------------------------------------------------------------------

function canHideDebugging()
{
	if (typeof(event) == 'undefined' || (event && event.ctrlKey))
	{
		if (document.body && document.body.style)
		{
			document.body.style.cursor = 'pointer';
		}
	}
}

//---------------------------------------------------------------------------

function normalCursor()
{
	document.body.style.cursor = 'auto';
}

//---------------------------------------------------------------------------

function hideDebugging(e)
{
	var iDebugCount, oDivCollection, lsDisplay;
	if (!window.ondblclick)
	{
		window.ondblclick = hideDebugging;
		document.body.ondblclick = hideDebugging;
	}
	if (typeof(event) != 'undefined')
	{
		event.cancelBubble = true;
	}
	else
	{
		e.cancelBubble = true;
	}
	lsDisplay = !window.debuggingHidden ? 'none' : 'block';
	if (window.debuggingdoubleclicked)
	{
		oDivCollection = document.getElementsByTagName('div');
		for (iDebugCount = 0;iDebugCount < oDivCollection.length; iDebugCount++)
		{
			if (oDivCollection[iDebugCount].className == 'debug')
			{
				oDivCollection[iDebugCount].style.display = lsDisplay;
			}
		}
		window.debuggingHidden = !window.debuggingHidden;
	}
	else
	{
		window.debuggingdoubleclicked = 1;
	}
	
}



function showDebug(loSender)
{
	loSender.style.opacity ="1";
	loSender.style.zindex = "5001";
	loSender.style.background = "red";
	
}

function transparentDebug(loSender)
{
	//loSender.style.opacity ="0.5";  
	loSender.style.zindex = "5000";
	loSender.style.background = "Aquamarine";

}

//-----------------------------------------------------------------------------------------


function ValidateFGFForm()
{
	var msg, max
	msg = new String()
	max = parseInt(document.fgf.MaxNoFriends.value,10)

	for (i=1;i <= max; i++)
	{
		// if one of the 3 has a value then check that row properly
		if (document.fgf.elements['FriendFirstName_' + i].value.length > 0 
			|| document.fgf.elements['FriendLastName_' + i].value.length > 0
			|| document.fgf.elements['FriendEmail_' + i].value.length > 0 )
		{
			// check that all 3 inputs have vals and the email is decently formed
			if (document.fgf.elements['FriendFirstName_' + i].value.length == 0 )
				msg += "On Row " + i + " Please enter a first name\n"
														
			if (document.fgf.elements['FriendLastName_' + i].value.length == 0)
				msg += "On Row " + i + " Please enter a last name\n"
													
			if (document.fgf.elements['FriendEmail_' + i].value.length == 0 )
				msg += "On Row " + i + " Please enter an email\n"
										
			if ( ! validEmail(document.fgf.elements['FriendEmail_' + i].value, false))
				msg += 'On Row ' + i + ' Please Enter a Valid email address (e.g. user@site.co.uk)\n'
												
			/*
			if ( (document.fgf.elements['FriendPrizeDrawID_' + i]) 	&& document.fgf.elements['FriendPrizeDrawID_' + i].value.length == 0 )
				msg += "On Row " + i + " Please choose a Prize to gain extra entries\n"
			*/

		}
	}


	if (msg.length > 0 )
	{
		alert(msg)
		return false
	}
											
	return(true);
} //ValidateFGFForm

//-----------------------------------------------------------------------------------------


function SelectAllCheckboxes(sCheckBoxName, bSelValue)
{
	var oCheckBoxes, j
	oCheckBoxes = document.getElementsByName(sCheckBoxName);
	for(j = 0; j < oCheckBoxes.length; j++) 
	{
		oCheckBoxes[j].checked = bSelValue
	}


}

//-----------------------------------------------------------------------------------------
//menu rollover functions

function menuRollOver(cell)
{
	if(cell.previousSibling&&cell.previousSibling.tagName.toLowerCase()=='td')
	{
		var oImg = cell.previousSibling.getElementsByTagName('img')[0];
		oImg.src = oImg.src.replace(menuRollOver.re,'_ov$1');
	}
	cell.getElementsByTagName('img')[0].src=cell.getElementsByTagName('img')[0].src.replace(menuRollOver.re,'_ov$1');
	if(cell.nextSibling&&cell.nextSibling.tagName.toLowerCase()=='td')
	{
		var oImg = cell.nextSibling.getElementsByTagName('img')[0];
		oImg.src=oImg.src.replace(menuRollOver.re,'_ov2$1');
	}
}

function menuRollOut(cell)
{
	if (cell.previousSibling&&cell.previousSibling.tagName.toLowerCase()=='td')
	{
		var oImg = cell.previousSibling.getElementsByTagName('img')[0];
		oImg.src=oImg.src.replace(menuRollOut.re1,'$1');
	}
	cell.getElementsByTagName('img')[0].src=cell.getElementsByTagName('img')[0].src.replace(menuRollOut.re1,'$1');
	if(cell.nextSibling&&cell.nextSibling.tagName.toLowerCase()=='td')
	{
		var oImg = cell.nextSibling.getElementsByTagName('img')[0];
		oImg.src=oImg.src.replace(menuRollOut.re2,'$1');
	}
}
menuRollOver.re = /(\.gif)/;
menuRollOut.re1=/_ov(\.gif)/;
menuRollOut.re2=/_ov2(\.gif)/;
//generic rollover function
function flipImg(sImg){
	var oImg = document.images[sImg];
	if(oImg.src.indexOf('_on')>0){
		oImg.src=oImg.src.replace('_on.gif', '.gif')
	}else{
		oImg.src=oImg.src.replace('.gif', '_on.gif')
	}
}
//generic preload function
function loadImg(sPath){
	if(!window.aImages){
		window.aImages = new Array();
	}
	var oImg = new Image()
	//oImg.onload=function(){alert(this.src)};
	oImg.src=sPath;
	aImages[aImages.length] = oImg;
}

//-----------------------------------------------------------------------------------------

function DateAdd(startDate, numDays, numMonths, numYears)
{
	var returnDate = new Date(startDate.getTime());
	var yearsToAdd = numYears;
	
	var month = returnDate.getMonth() + (numMonths || 0);
	if (month > 11)
	{
		yearsToAdd = Math.floor((month+1)/12);
		month -= 12*yearsToAdd;
		yearsToAdd += (numYears || 0);
	}
	returnDate.setMonth(month);
	returnDate.setFullYear(returnDate.getFullYear()	+ (yearsToAdd || 0));
	
	returnDate.setTime(returnDate.getTime()+60000*60*24* (numDays || 0));
	
	return returnDate;

}

function YearAdd(startDate, numYears)
{
		return DateAdd(startDate,0,0,numYears);
}

function MonthAdd(startDate, numMonths)
{
		return DateAdd(startDate,0,numMonths,0);
}

function DayAdd(startDate, numDays)
{
		return DateAdd(startDate,numDays,0,0);
}

//-----------------------------------------------------------------------------------------

function checkSkyscraper(liPromotionID){
	var liMinWinWidth=910;//width at which to show skyscraper
	if(liPromotionID){
		if(!window.promotionIDs){
			window.promotionIDs = new Array()
		}
		window.promotionIDs[window.promotionIDs.length]=liPromotionID;
	}
	if(document.body&&document.getElementById){
		for(var i=0;i<window.promotionIDs.length;i++){
			document.getElementById('Promotion' + window.promotionIDs[i]).style.display=(document.body.clientWidth>liMinWinWidth)?'block':'none';
		}
	}
	window.onresize=checkSkyscraper;
}

//-----------------------------------------------------------------------------

// Body onload utility (supports multiple onload functions)
function TS_SafeAddOnload(f)
{
	if (window.onload)
	{
		if (!window.safeOnload)
		{
			window.safeOnload = new Array();
		} // !window.safeOnload
		if (window.onload != TS_SafeOnload)
		{
			window.safeOnload[0] = window.onload;
			window.onload = TS_SafeOnload;
		}  
		window.safeOnload[window.safeOnload.length] = f;
	}
	else
	{
		window.onload = f;
	}
}

function TS_SafeOnload()
{
	for (var i=0;i<window.safeOnload.length;i++)
	{
		window.safeOnload[i]();
	}
}

//-----------------------------------------------------------------------------


function ShowHideElements(sElementName)
{
	var argv = ShowHideElements.arguments;
	var argc = ShowHideElements.arguments.length;
   	var cells, j, sCookieVal
    var sCookieName = (argc > 1) ? argv[1] : null;
    var sForceDisplay = (argc > 2) ? argv[2] : null;

	if (sCookieName != null)
	{
		sCookieVal = GetCookie(sCookieName)
	}

	cells = document.getElementsByName(sElementName);
	if (cells.length > 0)
	{
		if (sForceDisplay == null)
		{

			// check the first object and do the opposite of it self, default to hide
			if (cells[0].style.display == 'none' ) //hidden
			{
				// Show cells
				if (document.all)
				{
					tDisplay = 'block'
				}
				else
				{
				
					// different 
					switch(cells[0].tagName.toUpperCase())
					{
						case 'TR':
							tDisplay = 'table-row'
							break;
						case 'TABLE':
							tDisplay = 'table'
							break;
						case 'DIV':
							tDisplay = 'block'
							break;
						case 'SPAN':
							tDisplay = 'inline'
							break;
						case 'TD', 'TH':
							tDisplay = 'table-cell'
							break;
						default:
							tDisplay = 'block'
							break;
						
					}//switch
					
				}
				
				//tDisplay = document.all ? 'block' : 'table'; // non-ie needs table-row
			}
			else
			{
				// Hide cells
				tDisplay = 'none'
			}
			if (sCookieName != null)
				SetCookie(sCookieName, tDisplay, '/')
		} //if (sForceDisplay == null)
		else
		{
			// if a display is being forced, set the cookie to that value
			tDisplay = sForceDisplay
			if (sCookieName != null)
			{
				SetCookie(sCookieName, tDisplay, '/')
			}
		}
		
		for(j = 0; j < cells.length; j++) 
		{
	//alert('sElementName: ' + sElementName + tDisplay)
			cells[j].style.display = tDisplay
		}
	} // if
}
//--------------------------------------------------------------------------------

function ShowHideElementsCookies(sElementName, sCookieName)
{
	var cells, j, sCookieVal

	sCookieVal = GetCookie(sCookieName)

	if (sCookieVal != null)
	{
		cells = document.getElementsByName(sElementName);
		if (cells.length > 0)
		{
			tDisplay = sCookieVal
			
			
			
			for(j = 0; j < cells.length; j++) 
			{
				cells[j].style.display = tDisplay
			}
		} // if (cells.length > 0)

	}//if (sCookieVal != null)
}
//--------------------------------------------------------------------------------


function getCookieVal (offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}

//--------------------------------------------------------------------------------

function GetCookie (name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
        return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
    }
    return null;
}

//--------------------------------------------------------------------------------

function SetCookie (name, value) {
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var path = (argc > 2) ? argv[2] : null;
    var expires = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}

//--------------------------------------------------------------------------------

function DeleteCookie (name) {

    var exp = new Date();
    //exp.setTime (exp.getTime() - 1000000000);  // This cookie is history
	exp.setDate(exp.getDate() - 7);

    var cval = GetCookie (name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
} // DeleteCookie

//--------------------------------------------------------------------------------

function debug(lsDescription, lsValue, lsDebugLayer)
{
	var loDebug;
	lsDebugLayer = lsDebugLayer ? lsDebugLayer : 'elDebug';
	loDebug = document.getElementById('elDebug');
	if (loDebug)
	{
		loDebug.innerHTML += lsDescription + ': ' + lsValue + '<br>';
	}
	return(true);
} //debug

//--------------------------------------------------------------------------------

function waitCursor(lsWaitLayer, lbReturnToAuto)
{
	var lsCursorStyle;
	lsCursorStyle = lbReturnToAuto ? 'auto' : 'wait';
	document.body.style.cursor = lsCursorStyle;

	loElement = document.getElementById(lsWaitLayer);
	if (loElement)
	{
		laElements = loElement.getElementsByTagName('*');
		//alert(laElements.length);
		for (var i=0;i < laElements.length; i++)
		{
			if (!lbReturnToAuto)
			{
				laElements[i].originalCursor = laElements[i].style.cursor;
				laElements[i].style.cursor = lsCursorStyle;
			}
			else
			{
				laElements[i].style.cursor = laElements[i].originalCursor ? laElements[i].originalCursor : lsCursorStyle;
			}
		}
	}
	return(true);
} //waitCursor

//--------------------------------------------------

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}
//--------------------------------------------------

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

//--------------------------------------------------
    
function addListener(element, event, listener, bubble) 
{
    if(element.addEventListener) 
    {
        if(typeof(bubble) == "undefined") bubble = false;
        element.addEventListener(event, listener, bubble);
    } 
    else if(this.attachEvent) 
    {
        element.attachEvent("on" + event, listener);
    }
}
    
//--------------------------------------------------

function getCookies(){
	/*returns js object to work like ASP cookie object*/
	if(!window.goCookies){
		var laCookies		= document.cookie.split(';');
		goCookies			= new Object();
		goCookies.getValue	= function(lsName){return this[lsName.toLowerCase()]}
		goCookies.keyExists = function(lsName){return Boolean(this.getValue(lsName.toLowerCase()))}
		goCookies.length	= laCookies.length;
		
		for(var i=0;i<laCookies.length;i++){
			var laCookie	= laCookies[i].split('=');
			var lsName		= laCookie[0].toLowerCase().replace(/^\s+|\s+$/gi, '');
			var lsValue		= laCookie[1];
			if(lsName&&lsValue){
				goCookies[lsName] = lsValue;
			}
		}
	}
	return goCookies;
}

//--------------------------------------------------

function ShowHideDiv(loDiv, lbCollapse, lbForceShow)
{
	var lsVisibility;
	loDiv = getElement(loDiv);
	if (loDiv)
	{
		if (lbCollapse)
		{
			lsVisibility = (lbForceShow || (typeof(lbForceShow)=='undefined' && loDiv.style.display == 'none')) ? 'block' : 'none';
			loDiv.style.display = lsVisibility;
		}
		else
		{
			lsVisibility = (lbForceShow || (typeof(lbForceShow)=='undefined' && loDiv.style.visibility == 'none')) ? 'block' : 'none';
			loDiv.style.visibility = lsVisibility;
		}
	}
}

//-----------------------------------------------------------------------------

function TextAreaMaxLength(loTextArea, liMaxLength)
{
	var liAscii = event.keycode
	var liLength = loTextArea.value.length
	
	if (
		(liLength  <= liMaxLength) 
		|| (liAscii == 8) //backspace
		|| (liAscii == 46) //delete
	   )
	{
		return true
	}
	else
	{
		return false
	}
}

//Javascript error reporting

function handleError(lsMessage, lsUrl, liLineNumber){
	var lsErrorMessage, lsErrorUrl, loImage;

	lsErrorMessage		=	' MachineID: ' + window.serverMachineID + '|' +
							' File: ' + lsUrl + '|' + 
							' Description: ' + lsMessage +  '|' +
							' Line: ' + liLineNumber + ';' + 
							' UserAgent: ' + navigator.userAgent +  '|';



	if(window.trackJSErrors){
		if(!(window.errorCount&&(window.errorCount > window.maxJSErrorsPerPage))){

			loImage				= new Image();
			lsErrorUrl			= window.rootFolder + 'misc/jsErrorTracking.asp?jserror=' + escape(lsErrorMessage);
			loImage.src			= lsErrorUrl;
			window.errorCount	= (window.errorCount||0)+1;
		}	
	}

	return !window.debug;
}//handleError

//////////////////////////////////////////////////////////////////////////////////////////////////

function moveObjNearPointer(obj, evt, paddingTop, paddingLeft)
{
	// Example call <img src="..." onclick="javaScrip:displayObjNearPointer(divId, event, 20, -50);divId.style.visibility='visibile';"
	var sError = "";
	try
	{
		evt = (evt) ? evt : event;
		paddingTop = (paddingTop) ? paddingTop : 20;
		paddingLeft = (paddingLeft) ? paddingLeft : (-50);

		if(obj && evt)
		{
			obj.style.position = "absolute";
			obj.style.left = (getMouseXPos(evt) + paddingLeft) + "px";
			obj.style.top = (getMouseYPos(evt) + paddingTop) + "px";
		}
	}
	catch(err)
	{
		sError = "Error : " + err.description;
		window.status = sError;
	}
	return sError;
}	// moveObjNearPointer

//////////////////////////////////////////////////////////////////////////////////////////////////

// Get the horizontal position of the mouse
function getMouseXPos(e)
{
	if (document.layers || (document.getElementById && !document.all))
		return parseInt(e.pageX + 10);
	else
		return (parseInt(event.clientX + 10) + parseInt(document.body.scrollLeft));
}

//////////////////////////////////////////////////////////////////////////////////////////////////

// Get the vartical position of the mouse
function getMouseYPos(e)
{
	if (document.layers || (document.getElementById && !document.all))
		return parseInt(e.pageY);
	else
		return (parseInt(event.clientY) + parseInt(document.body.scrollTop));
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function ShufflePrizes(){
	if(document.getElementById('PrizeIdList')!=null && document.getElementById('PrizeDrawIdList')!=null && document.getElementById('PrizeNoList')!=null){
		if((document.getElementById('PrizeIdList').value.split(",").length==document.getElementById('PrizeDrawIdList').value.split(",").length) && (document.getElementById('PrizeDrawIdList').value.split(",").length==document.getElementById('PrizeNoList').value.split(",").length) && document.getElementById('PrizeIdList').value.length!=0){

			document.getElementById('ShufflePrizeIdList').value=document.getElementById('PrizeIdList').value
			document.getElementById('ShufflePrizeDrawIdList').value=document.getElementById('PrizeDrawIdList').value
			document.getElementById('ShufflePrizeNoList').value=document.getElementById('PrizeNoList').value
			document.getElementById('ShuffleTotalFreePrizeCount').value=document.getElementById('totalFreePrizeCount').value
		}
	}
	document.forms.PrizeDrawShuffle.submit();							
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function PagePrizes(liNewPage){
	if(document.getElementById('PrizeIdList')!=null && document.getElementById('PrizeDrawIdList')!=null && document.getElementById('PrizeNoList')!=null){
		if((document.getElementById('PrizeIdList').value.split(",").length==document.getElementById('PrizeDrawIdList').value.split(",").length) && (document.getElementById('PrizeDrawIdList').value.split(",").length==document.getElementById('PrizeNoList').value.split(",").length) && document.getElementById('PrizeIdList').value.length!=0){

			document.getElementById('PrizePageIdList').value=document.getElementById('PrizeIdList').value
			document.getElementById('PrizePageDrawIdList').value=document.getElementById('PrizeDrawIdList').value
			document.getElementById('PrizePageNoList').value=document.getElementById('PrizeNoList').value
			document.getElementById('PrizePageTotalFreePrizeCount').value=document.getElementById('totalFreePrizeCount').value
        }
    }

  	document.getElementById('PrizePage').value = liNewPage;
	document.forms.PrizeDrawPage.submit();					
}

function SelectTopFreePrizeChkBox(chkBoxID)
{
    chkBox = document.getElementById(chkBoxID);
    chkBox.checked = !chkBox.checked;
}

//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//  IPT Http Request Framework
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

var Ipt;

if (!Ipt)
{
    Ipt = {};
    Ipt.MyOffers = {};    
}
else if (!Ipt.MyOffers)
{
   Ipt.MyOffers = {};
}

if (!Ipt.MyOffers.Ajax)
{
  Ipt.MyOffers.Ajax = function ()
  {
    this.GetDomain = function ()
        {
            var lsCurrentLocation = (document.location) ? document.location.toString().toLowerCase() : "";

            if (lsCurrentLocation.match(/http:\/\/localhost\/[a-z]+/gi) && lsCurrentLocation.match(/http:\/\/localhost\/[a-z]+/gi).length  == 1)
            {
                return lsCurrentLocation.match(/http:\/\/localhost\/[a-z]+/gi)[0];    
            }
            else if(lsCurrentLocation.match(/http:\/\/[a-z.12:-]*/gi) && lsCurrentLocation.match(/http:\/\/[a-z.12:-]*/gi).length == 1)
            {
                return lsCurrentLocation.match(/http:\/\/[a-z.12:-]*/gi)[0];
            }
            else
            {
                return lsCurrentLocation;
            }
        };
        
    this.HttpRequest = false;
    this.MimeType = HttpMimeType.MimeTypeHtml;
    this.ErrorHandler = function() {};  
    
    this.SetErrorHandler = function (loErrorHandler)
        {
            if(typeof loErrorHandler == "function")
            {
                this.ErrorHandler = loErrorHandler;                
            }
            else if(typeof loErrorHandler == "function")
            {
                alert("Error: expected function as error handler")
            }            
        }   
  };
}

Ipt.MyOffers.Ajax.prototype.OpenHttpConnection = function(lsRelativeUrl, lsParameters, loCallBackEvntHandler,liMimeTypeXml,liHttpType)
{
    if(!liMimeTypeXml && liMimeTypeXml != "")
    {
        this.MimeType = liMimeTypeXml;
    }
    
    
    if (window.XMLHttpRequest) 
    { 
        this.HttpRequest = new XMLHttpRequest();
        
        if (this.HttpRequest.overrideMimeType && this.MimeType == HttpMimeType.MimeTypeXml) 
        {
            this.HttpRequest.overrideMimeType('text/xml');
        }
    } 
    else if (window.ActiveXObject) 
    { 
        try 
        {
            this.HttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) 
        {
            try 
            {
               this.HttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e) 
            {
            }
         }
    }
    
    if ((!this.HttpRequest || !lsRelativeUrl || lsRelativeUrl=="") && !this.ErrorHandler) 
    {    
        if(!this.HttpRequest)
        {
            lsErrorMessage = "Error could not create http connection to server";
        }
        else if(!lsRelativeUrl || lsRelativeUrl=="") 
        {
            lsErrorMessage = "Error you must provide the url to connect too";
        }
        
         this.ErrorHandler(this, this.GetDomain() + lsRelativeUrl, lsParameters, lsErrorMessage);
         return false;     
    }
    
    this.HttpRequest.onreadystatechange = loCallBackEvntHandler;
    if(liHttpType ==  HttpRequestType.Get)
    {
        this.HttpRequest.open('GET', this.GetDomain() + lsRelativeUrl + "?" + lsParameters, true);
        this.HttpRequest.send(null);
    } else {
        this.HttpRequest.open('POST', this.GetDomain() + lsRelativeUrl, true);
        this.HttpRequest.send(lsParameters);
    }
    
    
    
}

Ipt.MyOffers.Ajax.prototype.ReadyState = new function() 
{
    this.UnInitialized = 0;
    this.Loading = 1;
    this.Loaded = 2;
    this.Interactive = 3;
    this.Complete = 4;
}

Ipt.MyOffers.Ajax.prototype.HttpRequestType= new function() 
{
    this.Post = 0;
    this.Get  = 1;
}


HttpReadyState = Ipt.MyOffers.Ajax.prototype.ReadyState;

Ipt.MyOffers.Ajax.prototype.MimeType = new function() {this.MimeTypeHtml=1;this.MimeTypeXml=2;}
HttpMimeType = Ipt.MyOffers.Ajax.prototype.MimeType;
HttpRequestType = Ipt.MyOffers.Ajax.prototype.HttpRequestType;

/*************************************************************************************************/
function charToByte(c)
{
	var i;
	for(i=0; i < CharArray1.length; i++) {
		if(c == CharArray1[i]) return i+32;
	}
	return 0;
}

function byteToChar(n)
{
	if(n < 32 || n > 255) return " ";
	return CharArray1[n-32];
}

function codeEmail(lsEmai)  
{    
    var lsCodetString = "";
    var lsCodetOneChar= "";
    var lsTemp = "";
    
    for(i=0; i< lsEmai.length; i++)
    {        
        lsCodetOneChar = charToByte(lsEmai.charAt(i)) * charToByte(EmailCk); 
        lsCodetString += lsCodetOneChar;
        if(i!= (lsEmai.length))
			lsCodetString += ",";
    }
    return lsCodetString; 
}
    
function dcEmail(lsxCCC)  
{    
    var lsdCString = "";
    var lsdCChar= "";
    
    for(i=0; i< lsxCCC.length; i++)
    {
        if(lsxCCC.charAt(i) != ",")
        {
			lsdCChar += lsxCCC.charAt(i);	
        }
        else
        { 
			lsdCChar = lsdCChar / charToByte(EmailCk);
			lsdCChar = byteToChar(lsdCChar);			
			lsdCString  += lsdCChar;
			lsdCChar = "";
		}	
        
    }
    return lsdCString; 
}    

/*************************************************************************************************/

function validate_form()
{
var sError;
var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
var emChars = "!#$%^&*()+=[]\\\';,/{}|\":<>?";
var pcChars = "!#$%^&*()+=[]\\\';,/{}|\":<>?";
var inums = "0123456789";

var iflag =0;
var jflag =0;
var mflag =0;
var emflag =0;
var pcflag =0;
var cnt=0;
var pcnt=0;
var Charlast=0;
var posdot=0;
var posemail=0;
var nflag=0;

var fnlast=0;
var lnlast=0;
var hnlast=0;
var pclast=0;

Charlast = (document.register.Email.value.length) - 1;
fnlast = (document.register.NameFirst.value.length) - 1;
lnlast = (document.register.NameLast.value.length) - 1;
hnlast = (document.register.StreetNumber.value.length) - 1;
pclast = (document.register.Postcode.value.length) - 1;

sError = "Please complete the following in your form :\n\n";


for (var i = 0; i < document.register.NameFirst.value.length; i++) {
if (iChars.indexOf(document.register.NameFirst.value.charAt(i)) != -1)
{ 
iflag =1;
}
}

for (var j = 0; j < document.register.NameLast.value.length; j++) {
if (iChars.indexOf(document.register.NameLast.value.charAt(j)) != -1)
{ 
jflag =1;
}
}

for (var em = 0; em < document.register.Email.value.length; em++) {
if (emChars.indexOf(document.register.Email.value.charAt(em)) != -1)
{ 
emflag =1;
}
}


for (var p = 0; p < document.register.Postcode.value.length; p++) {
if (inums.indexOf(document.register.Postcode.value.charAt(0)) != -1)
{ 
pcflag =1;
}
}

for (var x = 0; x < document.register.Postcode.value.length; x++) {
if (pcChars.indexOf(document.register.Postcode.value.charAt(x)) != -1)
{ 
pcflag =1;
}
}

if(document.register.Postcode.value.length > 9 || document.register.Postcode.value.length < 5) {
pcflag =1;
}

for (var y = 0; y < document.register.Postcode.value.length; y++) 
{
    if(document.register.Postcode.value.charAt(y) == " ")
    {
    pcnt = pcnt + 1;
    }
}

if (pcnt == 2) 
{
pcflag =1;
  //alert('there are two blank spaces in postcode.....');
}

vemail = document.register.Email.value;
posdot = vemail.indexOf(".");
posemail = vemail.indexOf("@");

for (var c = 0; c < document.register.Email.value.length; c++) 
{
    if(document.register.Email.value.charAt(c) == ".")
    {
    cnt = cnt + 1;
    }
}

if (cnt == 1 && (posdot < posemail)) 
{
emflag=1;
//  alert('there is only one dot in email...');
}

if (document.register.NameTitleID.selectedIndex == 0)
{ sError = sError + "Valid Title\n"; }

if (document.register.NameFirst.value.charAt(fnlast) == " " || document.register.NameFirst.value.charAt(0) == " " || document.register.NameFirst.value.search(/[0-9]+/) > -1 || document.register.NameFirst.value == "" || document.register.NameFirst.value == " " || iflag == 1)
{ sError = sError + "Valid First Name\n"; }

if (document.register.NameLast.value.charAt(lnlast) == " " || document.register.NameLast.value.charAt(0) == " " || document.register.NameLast.value.search(/[0-9]+/) > -1 || document.register.NameLast.value == "" || document.register.NameLast.value == " " || jflag == 1)
{ sError = sError + "Valid Last Name\n" ; }

if (document.register.StreetNumber.value.charAt(hnlast) == " " || document.register.StreetNumber.value.charAt(0) == " " || document.register.StreetNumber.value == "" || !(document.register.StreetNumber.value.search(/[0-9]+/) > -1))
{ sError = sError + "Valid House/Flat No\n" ; }

if (document.register.Postcode.value.charAt(pclast) == " " || pcflag == 1 || document.register.Postcode.value.charAt(0) == " " || document.register.Postcode.value == "" ||
!(document.register.Postcode.value.search(/[0-9]+/) > -1) ||
!((document.register.Postcode.value.search(/[a-z]+/) > -1) || (document.register.Postcode.value.search(/[A-Z]+/) > -1)))
{ sError = sError + "Valid Postcode\n"; }

if(document.register.Email.value.charAt(Charlast) == " " || document.register.Email.value.charAt(Charlast) == "." || document.register.Email.value.charAt(Charlast) == "@")
{
    nflag =1;
}

for (var m = 0; m < document.register.Email.value.length; m++) {
if ((document.register.Email.value.charAt(m) == "." && document.register.Email.value.charAt(m+1) == "@") 
     || (document.register.Email.value.charAt(m) == "@" && document.register.Email.value.charAt(m+1) == "."))
    { 
        mflag =1;
    }
}

if (document.register.Email.value == "" || document.register.Email.value.indexOf("@") == -1 || document.register.Email.value.indexOf(".") == -1 || mflag == 1 || emflag == 1 || nflag == 1 || document.register.Email.value.charAt(0) == " ")

{ sError = sError + "Valid Email Address\n"; }

if (sError.length > 46)
    { 
    alert(sError); 
    }
else
    { 
    document.register.submit(); 
    }

} // End of validate_form() function

/*************************************************************************************************/

function popupWindow(strUrl, liWidth, liHeight, strName, bNoScroll, bWindowFeatures, bPopunder)
{
	// IMPORTANT : don't use string with space for strName (name of window handler)... it won't work for IE

	var sParams, liScreenX, liScreenY;
	if (!strName)
	{
		strName = 'winPopup';
	}

	if(window.screen)
	{
		liWidth = (liWidth ? Math.min(liWidth, window.screen.availWidth-45) : window.screen.availWidth-45);
		liHeight = (liHeight ? Math.min(liHeight, window.screen.availHeight-60) : window.screen.availHeight-60);

		liScreenX = (window.screen.availWidth - liWidth) /2
		liScreenY = (window.screen.availHeight - 20 - liHeight) /2
	}

	//alert(liScreenX + '::' + liWidth)
	//alert(liScreenY + '::' + liHeight)

	sParams = (bWindowFeatures ? 'menubar=1;toolbar=1,titlebar=1,status=1,' : 'toolbar=0,titlebar=0,status=0,') 
		+ 'scrollbars=' + (bNoScroll ? 0 : 1) + ',resizable=' + (bNoScroll ? 0 : 1) 
		+ (liWidth ? ',width=' + liWidth : '') + (liHeight ? ',height=' + liHeight : '')
		+ ",left=" + liScreenX + ",top=" + liScreenY + ",screenX=" + liScreenX + ",screenY=" + liScreenY ;

	winPopup = window.open(strUrl, strName, sParams);

	if (bPopunder && winPopup)
	{
		window.focus()
	}
	else if (winPopup)
	{
		winPopup.focus();
	}
	return (winPopup);
}

/*************************************************************************************************/

// Function for finding the querystring value by passing Querystring field name as a argument.

function querySt(ji) 
{
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i=0;i<gy.length;i++) 
    {
        ft = gy[i].split("=");
        if (ft[0] == ji) 
        {
            return ft[1];
        }
    }
}


/*************************************************************************************************/


function owMessage(c,f)
{
if(c.checked)
{document.getElementById('SpanowMsg').innerHTML='<br>An email will be sent to your email inbox, please click on the link provided to confirm your membership. Once you have done this, you are on your way to earning that extra cash.' }
 else{document.getElementById('SpanowMsg').innerHTML='';} 
    
}

/*************************************************************************************************/
