//* COMMON JAVASCRIPT FUNCTIONS *//

//* Change History 
//* Josh Moont		26/04/05	Created			*//
//*												*//

	
//**************************** GENERAL FUNCTIONS FROM THREE.CO.UK *//
function loadPage(URL) {
    if (URL != "" ) {
        if (URL == "divide" ) {reset();} else { document.location.href = URL;}
    }
    return false;
}
function doSubmit(hrefArg){
    document.location.href = hrefArg;
}

function openWin(URL,winName,width,height,resize,scroll){
    settings = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=' + scroll + ',resizable='+resize+',height=' + height + 'px,width='+ width +'px';
	newWin = window.open(URL,winName,settings);
	newWin.focus();
	return false;
}

//**************************** OFFER DETAILS EXPAND *//
function barcontrol(itemname, headername){
	if (document.getElementById) {
		var item = document.getElementById(itemname);
		var header = document.getElementById(headername);
		if(item.className == ''){
			item.className = 'hide';
		}
		if (header){
			if(header.className == ''){
				header.className = 'arrowhide';
			}
		}
		if(item.className == 'hide'){
			item.className = 'show';
			if (header)
				header.className = 'arrowshow';
		} else{
			item.className = 'hide';
			if (header)
				header.className = 'arrowhide';
		}
	}
}
var show = new Image();
show.src = "../images/layout/msc/AvailableOffers_show.gif";

var hide = new Image();
hide.src = "../images/layout/msc/AvailableOffers_hide.gif";

function toggleImage(obj)
{
    if (obj) {
        if (obj.src.indexOf('show') > 0) {
            obj.src = hide.src // obj.src.replace('show','hide')
        }
        else
        {
         obj.src = show.src // obj.src.replace('hide','show')
        }
   }
   
}

//**************************** AD ROTATOR *//
var items_i = 0;
items = new Array();

//items[items_i++] = new Array('href', 'src', 'alt', timeout);
//items[items_i++] = new Array('planoffers.aspx?tariffid=278','images/layout/priceplanbanner1.jpg','Half price line rental. 400 anytime, any network minutes and 250 texts - plus &pound;5 video bonus. &pound;17.50 a month for 6 months',5); 
items[items_i++] = new Array('planoffers.aspx?tariffid=431','images/layout/priceplanbanner3.gif','Half line price rental.');

function Rotator(linkID, itemID) {

	if(items == null) return;
	if(items.length == 0) return;

	//The timeout can put the next item greater than the length of links, therefore reset to zero before use.
	if( itemID >= items.length){
		itemID = 0;
	}
	//set up the link display
	var obj = document.getElementById(linkID)
	if (obj != null){
		obj.href = items[itemID][0];
		obj.childNodes[0].src = items[itemID][1];
		obj.childNodes[0].alt = items[itemID][2];	
	}
	
    if(items.length > 1){
        setTimeout("Rotator('"+linkID+"',"+ (itemID + 1)+")", items[itemID][3] * 1000);
    }
	
}
function openWindow(url,name,width,height,isScroll,isResize) 
{
	var scrolling = "no";
	var resizable = "no";
	if (isScroll)
		scrolling = "yes";
	if (isResize)
		resizable = "yes";
	var params="menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=" + scrolling + ",resizable=" + resizable + ",dependent,top=0,left=0,width="+width+",height="+height;
	popupWin = top.window.open(url, name,params);
}

function expandFeatures(id)
{var obj = document.getElementById(id);if(obj != null){obj.className = (obj.className.indexOf('show') > -1)?obj.className.replace('show','hide'):obj.className.replace('hide','show');
return false}}


function CheckDDL(ddlID, message)
{var obj = document.getElementById(ddlID); if(obj != null){if(obj.selectedIndex == -1 || obj.selectedIndex ==0){alert(message);
return false;}}return true}

/*	--[	attach/detach events to element ]-------------------------------------  */

//	the event supplied must be supplied without the "on" prefix - eg: for an 
//	"onclick" the supplied event handler would be "click".

function objectAttachEvent(obj, eventHandler, functionName, useCapture) {
	if (useCapture == null) {
		useCapture = false;
	}
	if (window.attachEvent) {
		obj.attachEvent("on" + eventHandler, functionName);
	} else if (window.addEventListener) {
		obj.addEventListener(eventHandler, functionName, useCapture);
	}
}

function showInsurance(param) {
    var displayType = "block";
    if (document.getElementById("All"+param)) {
        document.getElementById("All"+param).style.display = "none";
    }
    if (document.getElementById("AllTab"+param)) {
	    document.getElementById("allTab"+param).className = "";
	}
	document.getElementById("insTab"+param).className = "selected";
    if (!document.all) {
        displayType = "block";
    }
    document.getElementById("Insurance").style.display = displayType;
    var text = document.getElementById("hide_add_on"+param);
    text.innerHTML = "Hide Add-ons";
}

function showTopSellers(param) {
    var displayType = "block";
    if (document.getElementById("Insurance")) {
        document.getElementById("Insurance").style.display = "none";
    }
	document.getElementById("allTab"+param).className = "selected";
	if (document.getElementById("insTab"+param)) {
	    document.getElementById("insTab"+param).className = "";
	    }
    if (!document.all) {
        displayType = "block";
    }
    document.getElementById("All"+param).style.display = displayType;
    var text = document.getElementById("hide_add_on"+param);
    text.innerHTML = "Hide Add-ons";
}

function hideAddons(param) {
    var displayType = null;
    if (document.getElementById("hide_add_on"+param)) {
        var text = document.getElementById("hide_add_on"+param);
    }
    if (document.getElementById("allTab"+param)) {
        document.getElementById("allTab"+param).className = "selected";
    }
    if (document.getElementById("insTab"+param)) {
	    document.getElementById("insTab"+param).className = "";
	}
    if (text.innerHTML == "Hide Add-ons") {
        text.innerHTML = "Show Add-ons";
        displayType = "none";
    } else {
        text.innerHTML = "Hide Add-ons";
        displayType = (document.all) ? "block" : "table-row-group";
    }
    if (document.getElementById("Insurance")) {
        document.getElementById("Insurance").style.display = "none";
    }
    if (document.getElementById("All"+param)) {
        document.getElementById("All"+param).style.display = displayType;
    }
}
		// Homepage Rotating Content
		var iCount=1;
		var iTabCount = 4;
		var tTimer;
		var iTotal = 4;
		var divToShow = "tabDeal"+iTotal;
		var tabToHighlight = "img_tab"+iTabCount;
		
		// COMMENT OUT IF NOT REQUIRED
		//var sBrowser = navigator.appVersion.split("MSIE");
		//var sBrowserVersion=parseFloat(sBrowser[1]);
		
		function timedCount() {
			// Fade in tab code
			// Hide the preloader
			// COMMENT OUT IF NOT REQUIRED
			//document.getElementById("tabDeal0").style.display = "none";
			// End fade in tab code
			
			document.getElementById(divToShow).style.display = "none";
			document.getElementById(tabToHighlight).src = "images/layout/MixNMatch/portalimages/tab_deal"+iTabCount+"_off.gif";
			divToShow = "tabDeal"+iCount;
			if (iTabCount==iTotal) {
				iTabCount = 0;
			}
			iTabCount++;
			tabToHighlight = "img_tab"+iTabCount;
			
			// Fade in tab code
			// COMMENT OUT IF NOT REQUIRED
			//if (isNaN(sBrowserVersion) || sBrowserVersion>=7) {
				//changeOpac(0,divToShow);
			//}
			// End fade in tab code
			
			document.getElementById(divToShow).style.display = "block";
			document.getElementById(tabToHighlight).src = "images/layout/MixNMatch/portalimages/tab_deal"+iCount+"_on.gif";
			
			// Fade in tab code
			// COMMENT OUT IF NOT REQUIRED
			//if (isNaN(sBrowserVersion) || sBrowserVersion>=7) {
				//opacity(divToShow, 0, 100, 1000);
			//}
			// End fade in tab code
			
			if (iCount==iTotal) {
				iCount=0;
			}
			iCount++;
			tTimer=setTimeout("timedCount()",6000);
		}
		function resetHomePageTimer() {
			clearTimeout(tTimer);
		}
		
		function opacity(id, opacStart, opacEnd, millisec) { 
   	 	//speed for each frame 
		var speed = Math.round(millisec / 100); 
		var timer = 0; 
	
		//determine the direction for the blending, if start and end are the same nothing happens 
		if(opacStart > opacEnd) { 
			for(i = opacStart; i >= opacEnd; i--) { 
				setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
				timer++; 
			} 
		} else if(opacStart < opacEnd) { 
			for(i = opacStart; i <= opacEnd; i++) 
				{ 
				setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
				timer++; 
			} 
		} 
	} 

	//change the opacity for different browsers 
	function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + (opacity) + ")";
	
	} 


function FAQ()
{
   
    //alert('closing');
    
    //location.href="http://www.google.co.uk"
    //return false;
    //var result = window.confirm("'Are you sure you want to exit?");
    //if(!result)
    //{
          //alert(2);
        //window.close();
        
         //alert(1);
        //window.close();
        
       openWin("../ExitPopUp.html","FAQ",'100','300','yes','yes');
      //  return(false);
     
    //}
    //else
    //{
      //return (true);
      
    //}
  

}
function checkHouseNumber(source, arguments)
{
alert(1);

}
// Update DOB fields to only allow real dates to be selected
			function DateOfBirth()
			{							
			    
				// Get the selected month and year
				var day = aFormObj[0].value
				var month = aFormObj[2].value
				var year = aFormObj[1].value					
				
				DDL_Days = aFormObj[0];
				DaysDisplayed = DDL_Days.length - 1;
				
				// Find out how many days there are in selected month
				var DaysInMonth = 31;
				if (month == "April" || month == "June" || month == "September" || month == "November") DaysInMonth = 30;				
				
				// Check for leap year
				if (month == "February" && (year/4) != Math.floor(year/4)) {	
					DaysInMonth = 28;
				}
				if (month == "February" && (year/4) == Math.floor(year/4)) {
					DaysInMonth = 29;
				}

				// If more days are displayed than exisit in this month, remove them
				if (DaysDisplayed > DaysInMonth)
				{
					for (i=0; i<(DaysDisplayed-DaysInMonth); i++)
					{
						DDL_Days.options[DDL_Days.options.length - 1] = null
					}
				}
				
				// If more days exisit than are shown for this month, added them
				if (DaysInMonth > DaysDisplayed)
				{
					for (i=0; i<(DaysInMonth-DaysDisplayed); i++)
					{
						NewOption = new Option(DDL_Days.options.length);
						DDL_Days.add(NewOption);
					}
				}
				
				// If an invalid day in the month is selected, reset it to the 1st
				if (DDL_Days.selectedIndex < 1) 
					DDL_Days.selectedIndex = 1;				
			}

            /*window.onload = AssignFormArray;
				var aFormObj = new Array(3)
			function AssignFormArray(){
				//doing this because control elements are in a .net usercontrol and ids are dynamic
			
				aFormObj[0] = eval("document.forms[0]." + inputnames + "_ddlDOBDay")
				aFormObj[1] = eval("document.forms[0]." + inputnames + "_ddlDOBYear")
				aFormObj[2] = eval("document.forms[0]." + inputnames + "_ddlDOBMonth")
			}*/