// Checkout
url = document.location.href;
xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0, xend);
var showinglocationbox = 0;
var isshowing = new Array(0,0,0,0,0,0,0,0,0,0,0,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 showAnswer(thisid) {
	
	if (isshowing[thisid] == 0) {
		getobject_main("question"+thisid).style.display = 'block';
		isshowing[thisid] = 1;
	} else {
		getobject_main("question"+thisid).style.display = 'none';
		isshowing[thisid] = 0;
	}
}


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;
}
