// JavaScript Document
function showTerms(){
	document.getElementById('terms-details').style.display = document.getElementById('terms-details').style.display != 'block' ? 'block' : 'none';
	
	//moveFooter(); //KC(29-Sept-2009) - Commented out; Footer remains@stagnant...else it wil disappear
}
//
//----KC(25-Sept-2009)-----
function collapseAllTerms(){
	document.getElementById('terms-details').style.display = document.getElementById('terms-details').style.display != 'block' ? 'block' : 'none';
	
	//moveFooter();	//KC(29-Sept-2009) - Commented out; Footer remains@stagnant...else it wil disappear
	
	document.getElementById('terms-details').style.display = document.getElementById('terms-details').style.display != 'block' ? 'block' : 'none';
	//moveFooter();	//KC(29-Sept-2009) - Commented out; Footer remains@stagnant...else it wil disappear
}
function showFAQ(intQ){

	document.getElementById('q'+ intQ).style.display = document.getElementById('q'+ intQ).style.display != 	'block' ? 'block' : 'none';
	//moveFooter();	//KC(29-Sept-2009) - Commented out; Footer remains@stagnant...else it wil disappear
}
function collapseAllFAQ(intTotalQ){
	for (i=1; i<=intTotalQ; i++){
		showFAQ(i);
		showFAQ(i);
	}
}
//----KC(25-Sept-2009)-----
//
function showInstallationAddress(){
	document.getElementById('installation-address').style.display = document.getElementById('installation-address').style.display != 'block' ? 'block' : 'none';
}
function showOtherGroup(source){
	document.getElementById('other-sporting-group').style.display = (source.options[11].selected) ? 'block' : 'none';
}






function MM_validateForm() { //v4.0
	  if (document.getElementById){
		var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
		for (i=0; i<(args.length-2); i+=4) { test=args[i+2]; val=document.getElementById(args[i]);
		  if (val) { nm=args[i+3]; if ((val=val.value)!="") {
			if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
			  if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
			} else if (test!='R') { num = parseFloat(val);
			  if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
			  if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
				min=test.substring(8,p); max=test.substring(p+1);
				if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
		  } } } else if (test.charAt(0) == 'R') {
		  	if(isIE){
				val = document.getElementById(args[i]);
				if (val.type == "select-one"){
					if(val.selectedIndex == 0) errors += '- '+nm+' is required.\n';
				}else if(val.type == "select-multiple"){
					var found = false;
					for(i1=1; !found && i1<val.options.length; i1++){
						found = val.options[i1].selected;
					}
					if(!found) errors += '- '+nm+' is required.\n';
				}else{
					errors += '- '+nm+' is required.\n';
				}
			  }else{
				  errors += '- '+nm+' is required.\n'; 
		  		}}}
		} if (errors) alert('The following error(s) occurred:\n'+errors);
		document.MM_returnValue = (errors == '');
	} }
	
/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}
function checkExpiryDate(){
	var strDay, strMonth, strYear;
	
	if (isIE6 || isIE7){
		strDay = selectedText('expiry-date-day');
		strYear = selectedText('expiry-date-year');
	}else{
		strDay = selectedValue('expiry-date-day');
		strYear = selectedValue('expiry-date-year');
	}
		strMonth = selectedValue('expiry-date-month');
	if (document.MM_returnValue){
		document.MM_returnValue = isDate(strDay + "/" + strMonth + "/" + strYear);																																	
		if (document.MM_returnValue){
			document.MM_returnValue = (new Date(strYear, strMonth - 1, strDay) > new Date());
		}
		if(!document.MM_returnValue) alert('The following error(s) occurred:\n- Invalid Expiry Date');
	}
}
function selectedValue(strID){
	return document.getElementById(strID).options[document.getElementById(strID).selectedIndex].value;
}
function selectedText(strID){
	return document.getElementById(strID).options[document.getElementById(strID).selectedIndex].text;
}
function productSelectCheck(){
	if (document.MM_returnValue){
		document.MM_returnValue = (document.getElementById('mobile-check').checked || document.getElementById('broadband-check').checked || document.getElementById('ezipack-check').checked || document.getElementById('miohome-check').checked);
		if(!document.MM_returnValue) alert('The following error(s) occurred:\n- Please select a product');
	}
}

function moveFooter(){
	if (document.getElementById('fixed-footer')){
		try{
			
			var intScreenTop, intTop;
			intScreenTop = (window.innerHeight ? (window.innerHeight + window.scrollY) : (document.documentElement.scrollTop + document.documentElement.clientHeight)) - 120;
			
			intTop = intScreenTop < document.getElementById('footer-holder').offsetTop ? intScreenTop : document.getElementById('footer-holder').offsetTop;
			
			//intTop = intTop;
			document.getElementById('fixed-footer').style.top = intTop + "px";
			
			//document.getElementById('floating-footer').style.left = document.getElementById('footer-holder').offsetLeft + "px";
		}catch(err){
			showErr(err);
		}
	}
}












var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


var isIE = (BrowserDetect.browser == "Explorer");
var isIE6 = (isIE && BrowserDetect.version == 6);
var isIE7 = (isIE && BrowserDetect.version == 7);

//alert("isIE6 " + isIE6);
//alert("isIE7 " + isIE7);

if (isIE6){
	window.onscroll = function(){
		moveFooter();
	}
	window.onresize = function(){
		moveFooter();
	}
	window.onload = function(){
		document.getElementById('fixed-footer').style.position = "absolute";
		moveFooter();
	}
}