// JavaScript Functions
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function createFooter(){
	document.write('<div style="float:right; margin-right:30px; margin-top:30px"><a href="http://twitter.com/#!/kioskgroupinc"><img src="images/twitter_button.jpg" width="163" height="50" alt="Follow us on Twitter!"></a></div><div><br><hr width="990" size="1"><a href="index.php">Home</a> | <a href="page.php?title=Kiosks">Kiosks</a> | <a href="page.php?title=Digital Signs">Digital Signs</a> | <a href="page.php?title=Services">Services</a> | <a href="page.php?title=Company">Company</a> | <a href="quote.php">Get a Pricing Quotation</a> | <a href="contact.php">Contact Us</a><br>Phone: 1-888-569-5467 | Fax: 1-240-206-0387 | E-mail: <a href="mailto:info@kioskgroup.com">info@kioskgroup.com</a><br>Copyright © 2011 Kiosk Group, Inc. All Rights Reserved. <a href="page.php?title=Privacy">Privacy Policy</a><br><br></div>');
}

function swapImage(img){
	var newimg=img.split("img.php?img=");
	var imgarr=newimg[1].split("&");
	img = imgarr[0];
	/*var newimg=img.split("/");
	img=newimg[newimg.length-1];*/
	show('loading');
	//document.getElementById('image_holder').src=img;
	document.getElementById('image_holder').src='img.php?img='+img+'&w=498';
}

function show(e){
	document.getElementById(e).style.display="";
}

function hide(e){
	document.getElementById(e).style.display="none";
}
function addLoadEvent(func) { 
	var oldonload = window.onload; 
		if (typeof window.onload != 'function') { 
			window.onload = func; 
		} else { 
			window.onload = function() { 
			if (oldonload) { 
				oldonload(); 
			} 
			func(); 
		}
	} 
}
function expandHeight(h) {
	for(tmpval=0;tmpval<document.getElementsByName('links_header').length;tmpval++){
		document.getElementsByName('links_header')[tmpval].height=h;
	}
}
function contractHeight() {
	for(tmpval=0;tmpval<document.getElementsByName('links_header').length;tmpval++){
		document.getElementsByName('links_header')[tmpval].height=120;
	}
}
function initImager(){
	document.write('<style>#displaybox{z-index: 20000; filter: alpha(opacity=75); filter:progid:DXImageTransform.Microsoft.Alpha(opacity=75); -moz-opacity: .75; -khtml-opacity: 0.75; opacity: 0.75; background-color:#000000; position:fixed; top:0px; left:0px; width:100%; height:100%; color:#FFFFFF; text-align:center; vertical-align:middle;} #disimg{color:#FFFFFF; z-index: 20001; position:fixed; top:0px; width:100%; height:100%; text-align:center; vertical-align:middle;}</style>');
	document.write("<div id='disimg' style='display:none;'></div><div id='displaybox' style='display:none;'></div>");
}
function searchBoxCheck(target){
    if(target.value=="Search BeYOND"){
        target.value="";
    } else if(target.value==""){
        target.value="Search BeYOND";
    }
}
function showImage(img){
	var newimg=img.split("/");
	img=newimg[newimg.length-1];
	var e=document.getElementById('displaybox');
	if(e.style.display == "none") {
		e.style.display = "";
		window.scroll(0,0);
		var _docHeight = document.height || document.body.offsetHeight;
		var res=((Client.viewportSize().height-570)/2)<=10?0:((Client.viewportSize().height-570)/2);
		document.getElementById('disimg').style.top=res+'px';
		e.style.position = "absolute";
		document.getElementById('disimg').style.position = "fixed";
		e.style.height=Client.webpageHeight()+'px';
		document.getElementById('disimg').style.display = "";
		document.getElementById('disimg').innerHTML = '<img src="img.php?img=images/products/lrg/'+img+'&wm=true&w=1000" onClick="closeWindow();" title="Click to close" alt="Click to close" style="cursor:pointer;">';
	} else {
		closeWindow();
	}
}
function viewImage(img,h){
	var e=document.getElementById('displaybox');
	if(e.style.display == "none") {
		e.style.display = "";
		window.scroll(0,0);
		var _docHeight = document.height || document.body.offsetHeight;
		var res=((Client.viewportSize().height-h)/2)<=10?0:((Client.viewportSize().height-h)/2);
		document.getElementById('disimg').style.top=res+'px';
		e.style.position = "absolute";
		document.getElementById('disimg').style.position = "fixed";
		e.style.height=Client.webpageHeight()+'px';
		document.getElementById('disimg').style.display = "";
		document.getElementById('disimg').innerHTML = '<img src="'+img+'" onClick="closeWindow();" title="Click to close" alt="Click to close" style="cursor:pointer;">';
	} else {
		closeWindow();
	}
}
function closeWindow(){
	var e=document.getElementById('displaybox');
	e.style.display = "none";
	document.getElementById('disimg').style.display = "none";
	document.getElementById('disimg').innerHTML = '';
}
function checkFormat(e,t){
	var ele=document.getElementById(e);
	if(ele.value){
		return validate(e,t);
	}
	ele.style.backgroundColor='#FFFFFF';
	return true;
}
function validate(e,t){
	var ele=document.getElementById(e);
	var valid_color = '#FFFFFF';
	var invalid_color = '#FF6666';
	if(t.toLowerCase()=="email"){
		var regexp = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/;
		if(!regexp.test(ele.value)){
			ele.focus();
			ele.style.backgroundColor=invalid_color;
			return false;
		}
	} else if(t.toLowerCase()=="iverify"){
		if(!iVerify.verify()){
			ele.focus();
			ele.style.backgroundColor=invalid_color;
			return false;
		}
	} else if(t.toLowerCase()=="phone"){
		var tmp=ele.value;
		tmp=tmp.split("-").join("").split("(").join("").split(")").join("").split(" ").join("");
		if(ele.value==""||ele.value.length<10||isNaN(tmp)){
			ele.focus();
			ele.style.backgroundColor=invalid_color;
			return false;
		}
	} else if(t.toLowerCase()=="select"){
		if(ele.value==-1){
			ele.focus();
			ele.style.backgroundColor=invalid_color;
			return false;
		}
	} else if(t.toLowerCase()=="selection"){
		c=0;
		for (i=0; i<ele.length; i++) {
			if (ele.options[i].selected) {
				c++;
			}
		}
		if(!c){
			ele.focus();
			ele.style.backgroundColor=invalid_color;
			return false;
		}
	} else if(t.toLowerCase()=="radio"){
		c=0;
		for (i=0;i<document.getElementsByName(e).length;i++) {
			if (document.getElementsByName(e)[i].checked) {
				c++;
			}
		}
		if(!c){
			document.getElementsByName(e)[0].parentNode.focus();
			for (i=0;i<document.getElementsByName(e).length;i++) {
				document.getElementsByName(e)[i].parentNode.style.backgroundColor=invalid_color;
			}
			return false;
		} else {
			for (i=0;i<document.getElementsByName(e).length;i++) {
				document.getElementsByName(e)[i].parentNode.style.backgroundColor='';
			}
		}
	} else if(t.toLowerCase()=="number"){
		var tmp=ele.value;
		tmp=tmp.split(".").length;
		if(ele.value==""||isNaN(ele.value)||tmp>=2){
			ele.focus();
			ele.style.backgroundColor=invalid_color;
			return false;
		}
	} else if(t.toLowerCase()=="date"){
		//FORMAT: MM/DD/YYYY, MM-DD-YYYY
		var regexp = /\d{2}(\/|-)\d{2}(\/|-)\d{4}/;
		if(!regexp.test(ele.value)){
			ele.focus();
			ele.style.backgroundColor=invalid_color;
			return false;
		}
	} else {
		if(ele.value==""){
			ele.focus();
			ele.style.backgroundColor=invalid_color;
			return false;
		}
	}
	if(ele){
		ele.style.backgroundColor=valid_color;
	}
	return true;
}
function randomWord(){
	var words = new Array("touchscreen","sound","beyond","kiosk","quotation","component","enclosure","printer","magnetic","rfid","barcode","digital","secure","thermal");
	var num = Math.floor(Math.random()*(words.length));
	return randomCase(words[num]);
}
function randomCase(w){
	var nw="";
	for(var i=0;i<w.length;i++){
		if(Math.round(Math.random())&&w.charAt(i).toLowerCase()!="i"||w.charAt(i).toLowerCase()=="l"){
			nw+=w.charAt(i).toUpperCase();
		} else {
			nw+=w.charAt(i).toLowerCase();
		}
	}
	return nw;
}
function iVerifyRefresh(){
	var rw=randomWord();
	document.getElementById('iVerifyImage').name=rw;
	document.getElementById('iVerifyImage').src='text2img.php?font=FUTURAB.TTF&size=10&color=666666&bg=EFEFEF&n=75&text='+rw;
}
function iVerify(){
	var rw=randomWord();
	document.write('<img id="iVerifyImage" name="'+rw+'" src="text2img.php?font=FUTURAB.TTF&size=10&color=666666&bg=EFEFEF&n=75&text='+rw+'" style="height:20px; border:solid 1px #666; margin-bottom:3px;"><br><input name="iVerifyInput" id="iVerifyInput" type="text" style="width:250px;"><br><span class="smalltext">Can\'t read the word? <img src="images/iverify_refresh.jpg" onClick="iVerifyRefresh(); return false;" align="absmiddle" style="margin:3px; outline:none; border:none; cursor:pointer;" title="Refresh Image"></span>');
}
//var http_request = false;
function sendEmail(params) {
	http_request = false;
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Cannot create XMLHTTP instance.');
		return false;
	}
	//http_request.onreadystatechange = changeevent;
	http_request.open('GET', "mail.php?to="+params.recipient+"&subject="+params.subject+"&message="+params.message, true);
	http_request.send(null);
	//alert('Email sent.');
}
