﻿if (document.images)
{
	var onImgArray = new Array()	
	// functions to swap images and set status bar
	
	function imageOn(imgName)
	{	

		
		if (document.images)
		{
		
		
		//alert(document.images[imgName].src);
			document.images[imgName].src = onImgArray[imgName].src
		}
			
		return true
	}

	function imageOff(imgName, imgSrc)
	{
			
		if (document.images)
		{
			document.images[imgName].src = imgSrc
		}
				
		return true
	}
}	

function openDestination()	
	{
	var winLink		
	winLink = "mysteryDestination/checkloginDestination.aspx"
	
		
	//if user is not logged in and should be, redirect to login page which will then
	// redirect to winLink if login is okay
	
	windowPopUp_large(winLink,  "Destination")
	
}

function togglePanel(panelID, display)
{
				
	checkElement = document.getElementById(panelID).name
	//elements[panelID]
				
	//document.frmMain.elements[panelID].style = "visibility:visible";
				
	// NS 4
	if (document.layers) 
	{
		if (display == 'false')
			document.layers[panelID].visibility = 'hide';
		else
			document.layers[panelID].visibility = 'show';
	}
	// IE 5+, NS 6+, Opera 5+
	else if (document.getElementById(panelID)) 
	{
		// toLowerCase() for Opera, which always
		// sets the visibility style to uppercase
					
		if (display == 'false')
			document.getElementById(panelID).style.display = 'none';
		else
			document.getElementById(panelID).style.display = 'inline';
	}

				
}
function showPanel(panelID)
{
				
	checkElement = document.getElementById(panelID).name
	//elements[panelID]
				
	//document.frmMain.elements[panelID].style = "visibility:visible";
				
	// NS 4
	if (document.layers) 
	{
		if (document.layers[panelID].visibility == 'show')
			document.layers[panelID].visibility = 'hide';
		else
			document.layers[panelID].visibility = 'show';
	}
	// IE 5+, NS 6+, Opera 5+
	else if (document.getElementById(panelID)) 
	{
		// toLowerCase() for Opera, which always
		// sets the visibility style to uppercase
					
		if (document.getElementById(panelID).style.display.toLowerCase() == 'inline')
			document.getElementById(panelID).style.display = 'none';
		else
			document.getElementById(panelID).style.display = 'inline';
	}

				
}
			
function setCheckedToHidden(checkBoxType, checkBoxAllID, hiddenID)
{					
	checkList = document.frmMain;
	len = checkList.elements.length;
			//alert(checkBoxType + "\n" + checkBoxAllID )
	for(var i = 0 ; i < len ; i++) 
	{
		var e = checkList.elements[i];
				
		//don't interogate the 'All' option
		
		if (e.id.indexOf(checkBoxAllID) == -1 && e.id.indexOf(checkBoxType) > -1)
		{					
		
			if (e.checked) 
			{
			
				//retrieve the id from the checkbox id
				//var checkBoxElementsArray = new Array()
				//checkBoxElementsArray = e.name.split("_");
					//	alert(e.name);
						//mailID is the last digits of the name
						
						var lastPos = e.name.lastIndexOf("_");
						var mailID = e.name.substring(lastPos+1);
						//alert(lastPos);
						//alert(mailID);
				//document.frmMain.selectedMail.value += checkBoxElementsArray[2] + ";"
				document.getElementById(hiddenID).value += mailID + ";"
						
			}
		}
			
	}
				
	return true;

}			
function PopUpNotLoggedIn(pageDescription)
{
	//window.location = 'NotLoggedIn.aspx?d=Save%20Search'
	var message = "You must be logged in to perform this action"
	alert(message)
}
			
function ToggleCheckBox(checkBoxObject, checkBoxType, checkBoxAllID)
{

	var allCheckValue
	if (checkBoxObject.checked) 
	{
		//	Highlight(checkBoxObject);
		//	document.frmMain.toggleAll.checked = AllChecked();
		allCheckValue = AllChecked(checkBoxType, checkBoxAllID);
	
	//		alert(checkBoxType + "\n" +  checkBoxAllID);	
		//alert(AllChecked(checkBoxType, checkBoxAllID));
	}
	else {
		//	Unhighlight(checkBoxObject);
		//document.messageList.toggleAll.checked = false;
		allCheckValue = false;
	}
		
	// traverse through elements in page to find the "All" check box
	//
	var checkList = document.frmMain;
	var len = checkList.elements.length;
	for (var i = 0; i < len; i++) {
		var e = checkList.elements[i];
		if (e.id.indexOf(checkBoxAllID) > -1) 
		{
		
			e.checked=allCheckValue;
			break;
		}
	}
				
}

function ToggleCheckboxAll(checkBoxObject, checkBoxType)
{
	if (checkBoxObject.checked) 
	{
	
		CheckAll(checkBoxObject, checkBoxType);
	}
	else 
	{
		ClearAll(checkBoxObject, checkBoxType);
	}
}

function Check(e)
{
	e.checked = true;
		
			
}

function Clear(e)
{	
	e.checked = false;
		
}

function CheckAll(checkBoxAllObject, checkBoxType)
{
			
	var checkList = document.frmMain;
	var len = checkList.elements.length;
	for (var i = 0; i < len; i++) 
	{
		var e = checkList.elements[i];
				
		if (e.id.indexOf(checkBoxType) > -1) 
		{					
						
			Check(e);
		}
	}
	checkBoxAllObject.checked = true;
}

function ClearAll(checkBoxAllObject, checkBoxType)
{
	var checkList = document.frmMain;
	var len = checkList.elements.length;
	for (var i = 0; i < len; i++) {
		var e = checkList.elements[i];
		if (e.id.indexOf(checkBoxType) > -1) 
		{
			Clear(e);
		}
	}
	checkBoxAllObject.checked = false;
}

function AllChecked(checkBoxType, checkBoxAllID)
{
	checkList = document.frmMain;
	len = checkList.elements.length;
		
	for(var i = 0 ; i < len ; i++) 
	{
		var e = checkList.elements[i];
				
		//don't interogate the 'All' option
		if (e.id.indexOf(checkBoxAllID) == -1 && e.id.indexOf(checkBoxType) > -1)
		{					
			if (!e.checked) 
			{
				return false;
			}
		}
			
	}
				
	return true;
}

function ToggleRadioAll(radioObject, radioType, radioValue)
{
//alert( radioObject.id + "\n" + radioType + "\n" + radioValue);
	if (radioObject.checked) 
	{

		CheckAllRadio(radioObject, radioType, radioValue);
	}
	else 
	{
	//	ClearAllRadio(radioObject, radioType, radioValue);
	}
}


function CheckAllRadio(radioAllObject, radioType, radioValue)
{
		
	// for HTML radio buttons to work properly, the name attribute must be the same
	// for the group of related buttons.  When a radio button is checked, the value 
	// for each radio button in the group is set to the same value. We need a way
	// to uniquely identify each radio button so we know which one in the group to 
	// check.  Use the id attribute of the radio button to accompolish this.
	
	var checkList = document.frmMain;
	var len = checkList.elements.length;
	
	
	// go througha all elements in the form object
	for (var i = 0; i < len; i++) 
	{
		var e = checkList.elements[i];
		// make sure we get the correct elements by checking the radio type

		if (e.id.indexOf(radioType) > -1) 
		{	
			//alert(e.id)
			// check the correct button in the group
			if (e.id.toLowerCase().indexOf(radioValue.toLowerCase()) > -1)
			{
		
				Check(e);
				
			}
			
		}
	}
	radioAllObject.checked = true;
}

function ToggleRadio(radioObject, radioType, radioAllID, radioValue)
{
	var allCheckValue
	//alert(radioObject.id + "\n" + radioType + "\n" + radioAllID + "\n" + radioValue);
	if (radioObject.checked) 
	{

		allCheckValue = AllRadioChecked(radioType, radioAllID, radioValue);
			
		
	}
	else {
		//	Unhighlight(checkBoxObject);
		//document.messageList.toggleAll.checked = false;
		allCheckValue = false;
	}
				
	// traverse through elements in page to find the "All" check box
	//
	
	var checkList = document.frmMain;
	var len = checkList.elements.length;
	
	for (var i = 0; i < len; i++) {
		var e = checkList.elements[i];
				
		if (e.name.toLowerCase().indexOf(radioAllID.toLowerCase()) > -1) 
		{
	
	
			if (allCheckValue)		
			{


				if (e.id.toLowerCase().indexOf(radioValue.toLowerCase()) > -1)
				{

					//if all items are checked, be sure to check off the all radio button for this column
					e.checked=allCheckValue;
					//break;

				}
				else
				{
					// if not all checked, uncheck ALL of the parent radio buttons
					e.checked=false;
//					break;
				}
			}
			else
			{
				e.checked=false;
			}
		}
	}
				
}
function AllRadioChecked(radioType, radioAllID, radioValue)
{
	checkList = document.frmMain;
	len = checkList.elements.length;
			
	for(var i = 0 ; i < len ; i++) 
	{
		var e = checkList.elements[i];
				
		//don't interogate the 'All' option

		if (e.name.toLowerCase().indexOf(radioAllID.toLowerCase()) == -1)
		{ 
//alert(radioAllID);		
			if (e.id.toLowerCase().indexOf("radio") > -1)
			{
				//alert('Type= ' + radioType + '\nValue= ' + radioValue + '\nid= ' + e.id + '\nname= ' + e.name)
			}
		// 
			if (e.name.toLowerCase().indexOf(radioType.toLowerCase()) > -1 && e.id.toLowerCase().indexOf(radioValue.toLowerCase()) > -1)
			{					
				//alert(e.checked);
				if (!e.checked) 
				{
					return false;
				}
			}
			
		}
	
			
	}
				
	return true;
}
function windowPopUp_medium(url)
{

	window.open(url,"","toolbar=0,status=1,scrollbars=1,resizable=1,menubar=0,width=720,height=550, screenX=15, screenY=50, top=15, left=50","")		

}

function windowPopUp_small(url)
{
	window.open(url,"","toolbar=0,status=0,scrollbars=1,resizable=1,menubar=0,width=400,height=300, screenX=15, screenY=50, top=15, left=50","")		

}
function windowPopUp_large(url,windowname)
{
	

	
	if (screen.width<=800)
	{
		width = 700;
		height=500;
	}
	else
	{
		width = 885;
		height=675;
	}
	
	if (typeof(windowname)=="undefined")
	{
	window.open(url,"","toolbar=0,status=1,scrollbars=1,resizable=1,menubar=0,width=" + width + ",height=" + height + ", screenX=15, screenY=50, top=15, left=50","");
	}
	else
	{
	window.open(url,windowname,"toolbar=0,status=1,scrollbars=1,resizable=1,menubar=0,width=" + width + ",height=" + height + ", screenX=15, screenY=50, top=15, left=50","");
	}
	
	
}
function windowPopUp_exlarge(url,windowname)
{
		
	if (screen.width<=800)
	{
		width = 750;
		height=550;
	}
	else
	{
		width = 950;
		height=675;
	}
	
	if (typeof(windowname)=="undefined")
	{
	window.open(url + "&width=" + width,"","toolbar=0,status=1,scrollbars=1,resizable=1,menubar=0,width=" + width + ",height=" + height + ", screenX=10, screenY=25, top=10, left=25","");
	}
	else
	{
	window.open(url + "&width=" + width,windowname,"toolbar=0,status=1,scrollbars=1,resizable=1,menubar=0,width=" + width + ",height=" + height + ", screenX=10, screenY=25, top=10, left=25","");
	}
	
	
}
function windowPopUp_editor(url,windowname)
{
	

	
	if (screen.width<=800)
	{
		width = 750;
		height=500;
	}
	else
	{
		width = 900;
		height=675;
	}
	
	if (typeof(windowname)=="undefined")
	{
	window.open(url,"","toolbar=0,status=1,scrollbars=1,resizable=1,menubar=0,width=" + width + ",height=" + height + ", screenX=15, screenY=50, top=15, left=50","");
	}
	else
	{
	window.open(url,windowname,"toolbar=0,status=1,scrollbars=1,resizable=1,menubar=0,width=" + width + ",height=" + height + ", screenX=15, screenY=50, top=15, left=50","");
	}
	
	
}
function windowPopUp_mailBanner(url)
{
if (screen.width<=800)
	{
		window.open(url,"","toolbar=0,status=0,scrollbars=1,resizable=1,menubar=0,width=770,height=300, screenX=15, screenY=20, top=15, left=20","")		

	}
	else
	{
		window.open(url,"","toolbar=0,status=0,scrollbars=1,resizable=1,menubar=0,width=770,height=300, screenX=15, screenY=50, top=15, left=50","")		

	}

}

function openTravelTip(tipID, userID)
{
	var winLink		
	winLink = "displayTravelTip.aspx?i=" + tipID
//winLink = "http://localhost/mp2004/mp2004/DisplayTravelTip.aspx?i=" + tipID
	//if user is not logged in and should be, redirect to login page which will then
	// redirect to winLink if login is okay
	if (userID == "")
	{
	
		windowPopUp_large("loginPopup.aspx?d=Display Tip&rp=true&i=" + winLink)
		
	}
	else
	
	{
		windowPopUp_large(winLink)
	}

}

function openOffer(mailId, category,  userID)	
{
	
	var winLink		
	//winLink = "http://www.mailpound.com/DisplayOffer.aspx?mail=" + mailId + "&category=" + category		
	winLink = "DisplayOffer.aspx?mail=" + mailId + "&category=" + category	
	//if user is not logged in and should be, redirect to login page which will then
	// redirect to winLink if login is okay
	if (userID == "")
	{
	
		windowPopUp_large("loginPopup.aspx?d=Display Offer&rp=true&i=" + winLink)
		
	}
	else
	
	{
		windowPopUp_large(winLink)
	}

}

function openReadyOffer(mailId, source)	
{
	
	var winLink		
	//winLink = "http://www.mailpound.com/DisplayOffer.aspx?mail=" + mailId + "&category=" + category		
	winLink = "CheckLogin.aspx?mail=" + mailId + "&s=" + source	
	//Link will check if logged in 
	windowPopUp_large(winLink)
	

}


function autoTab(iCtl, iMax) 
{
	var nextElement, textValue = iCtl.value;

	if (textValue.length==iMax) 
	{
		nextElement = getNextElement(iCtl);
		if (nextElement) 
		{
			if (nextElement.type == "text")
			{
				nextElement.select();
				nextElement.focus();
			}
		}
	}
}
  
function preventEnterKey()
{
   if (window.event.keyCode == 13)  // checks whether the ENTER key is pressed
   {
    window.event.cancelBubble = true;
    window.event.returnValue = false;   
   }
}   
function getNextElement(iElement) 
{
	var parentForm = iElement.form;

	for (i=0; i<parentForm.length; i++) 
	{
		if (parentForm.elements[i]==iElement)
			if (parentForm.elements[i+1])
				return parentForm.elements[i+1];
	}
	return null;
}

function replace(string,text,by) {
// Replaces text with by in string
   var i = string.indexOf(text);
   var newstr = '';
   if ((!i) || (i == -1)) return string;
   newstr += string.substring(0,i) + by;


   if (i+text.length < string.length)
       newstr += replace(string.substring(i+text.length,string.length),text,by);


   return newstr;



}

