// Checkout
url = document.location.href;
xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0, xend);
var showinglocationbox = 0;


function ajax_do (url) {
	// Does URL begin with http?
	if (url.substring(0, 4) != 'http') {
			url = base_url + url;
	}

	// Create new JS element
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = url;

	// Append JS element (therefore executing the 'AJAX' call)
	document.body.appendChild (jsel);
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function getobject_main(obj){
	  if (document.getElementById)
		 return document.getElementById(obj)
	  else if (document.all)
		 return document.all[obj]
}

function isEmailAddr(str) {
  return str.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/);
}


function submitEmail() {
	var email = getobject_main("addemail").value;
	var name = getobject_main("addname").value;
	
	var randomString = new Date().getTime();
	
	if (isEmailAddr(email)) {
		
	getobject_main("request").style.display = 'none';
	getobject_main("thanks").style.display = '';
		
	ajax_do('http://www.kelcom.com/save_email.php?email=' + email + '&name=' + name + '&m=' + randomString);
	
	} else {
		alert("Please enter a valid email address.");
	}

}

function startOverlay() {
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 15);
	
	Element.setHeight('cartoverlay', arrayPageSize[1]);
	Element.setTop('cartlightbox', lightboxTop);
	
	new Effect.Appear('cartoverlay', { duration: 0.2, from: 0.0, to: 0.8 });
	getobject_main("cartlightbox").style.display = '';
}


function showLocations() {
	
	if (showinglocationbox == 0) {
		showinglocationbox = 1;
		getobject_main("showlocations").style.display = 'block';
		getobject_main("linktolocations").src = "images/hide_locations_04.jpg";
		getobject_main("KELCOMlogo").src = "images/hide_locations_03.jpg";
	} else {
		showinglocationbox = 0;
		getobject_main("showlocations").style.display = 'none';
		getobject_main("linktolocations").src = "images/kelcom_new_head_cell_phone_ontario_04.jpg";
		getobject_main("KELCOMlogo").src = "images/kelcom_new_head_cell_phone_ontario_03.jpg";
	}
}

function showRoaming() {
	getobject_main("thisfocus").style.display = 'block';
	getobject_main("thisfocus").style.width = '550px';
	getobject_main("moretext").innerHTML = '<img src="images/title_roaming.gif" width="259" height="31" border="0" /><br><b>Automatic</b><br>U.S. Roaming allows you to take your TELUS 1X phone or data device to hundreds of cities across the United States. There is no signup, simply take your phone and go. All airtime and long distance is billed in Canadian dollars.<br><br><b>Data Roaming</b> - Billed by the megabyte in EVDO/1X areas.<br><b>Calls in the US \(local\)</b> - 95 cents / minute <br><b>Calls in the US \(long distance\)</b> - $1.45 / minute <br><b>Calls Received in the US</b> - $1.45 / minute<br><br>Note: Minutes used while roaming in the U.S. are not applied towards any included monthly and unlimited weekend or weeknight minutes offered with your TELUS Mobility rate plan. In addition to the U.S., TELUS International Roaming gives you access to service in over 140 countries using your TELUS mobile or "world" phone. ';
}

function showLongDistance() {
	getobject_main("thisfocus").style.display = 'block';
	getobject_main("thisfocus").style.width = '550px';
	getobject_main("moretext").innerHTML = '<img src="images/map_canada.gif" width="154" height="123" align="right" style="margin-top:10px;" /><img src="images/title_longdistance.gif" width="259" height="31" border="0" /><br><b>Calls within Canada</b> - 35 cents / minute<br><b>Calls to the U.S.</b> - 35 cents / minute<br>';
}

function showCoverage() {
	getobject_main("thisfocus").style.display = 'block';
	getobject_main("thisfocus").style.width = '770px';
	getobject_main("moretext").innerHTML = '<img src="images/title_coverage.gif" width="259" height="31" border="0" /><br><br><img src="images/coverage_ontario.jpg" id="coveragemap" width="757" height="525" border="0" /><br><br><b>Voice & Data:</b> <a href="javascript:showCanada\(\);" class="style12">All of Canada</a> | <a href="javascript:showCoverage\(\);" class="style12">Ontario</a><br><b>GPS Service:</b> <a href="javascript:showGPSCanada\(\);" class="style12">All of Canada</a> | <a href="javascript:showGPS\(\);" class="style12">Ontario</a>';
}

function showCanada() {
	getobject_main("moretext").innerHTML = '<img src="images/title_coverage.gif" width="259" height="31" border="0" /><br><br><img src="images/coverage_canada.jpg" id="coveragemap" width="761" height="452" border="0" /><br><br><b>Voice & Data:</b> <a href="javascript:showCanada\(\);" class="style12">All of Canada</a> | <a href="javascript:showCoverage\(\);" class="style12">Ontario</a><br><b>GPS Service:</b> <a href="javascript:showGPSCanada\(\);" class="style12">All of Canada</a> | <a href="javascript:showGPS\(\);" class="style12">Ontario</a>';
}

function showGPS() {
	getobject_main("moretext").innerHTML = '<img src="images/title_coverage.gif" width="259" height="31" border="0" /><br><br><img src="images/coverage_gps.jpg" id="coveragemap" width="752" height="486" border="0" /><br><br><b>Voice & Data:</b> <a href="javascript:showCanada\(\);" class="style12">All of Canada</a> | <a href="javascript:showCoverage\(\);" class="style12">Ontario</a><br><b>GPS Service:</b> <a href="javascript:showGPSCanada\(\);" class="style12">All of Canada</a> | <a href="javascript:showGPS\(\);" class="style12">Ontario</a>';
}

function showGPSCanada() {
	getobject_main("moretext").innerHTML = '<img src="images/title_coverage.gif" width="259" height="31" border="0" /><br><br><img src="images/coverage_gps_canada.jpg" id="coveragemap" width="752" height="410" border="0" /><br><br><b>Voice & Data:</b> <a href="javascript:showCanada\(\);" class="style12">All of Canada</a> | <a href="javascript:showCoverage\(\);" class="style12">Ontario</a><br><b>GPS Service:</b> <a href="javascript:showGPSCanada\(\);" class="style12">All of Canada</a> | <a href="javascript:showGPS\(\);" class="style12">Ontario</a>';
}

function closeWindow() {
	getobject_main("thisfocus").style.width = '550px';
	getobject_main("thisfocus").style.display = 'none';
}


function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}