function printSpecial()
{
if (document.getElementById != null)
{
var html = '<html>\n<head>\n';
html += '<title>Multi Web Vista - Web Development Services</title>\n';
html += '<link href="print_style.css" rel="stylesheet" type="text/css">\n';
html += '\n</head>\n<body>\n';

var printReadyElem = document.getElementById("maintext");

if (printReadyElem != null)
{
html += printReadyElem.innerHTML;
}
else
{
alert("Could not find the maintext section in the HTML");
return;
}

html += '\n</body>\n</html>';

var printWin = window.open("","printSpecial");
printWin.document.open();
printWin.document.write(html);
printWin.document.close();
if (gAutoPrint)
printWin.print();
}
else
{
alert("Sorry, this feature is only available in modern browsers.");
}
}

function setActiveStyleSheet(title) {
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1
        && a.getAttribute("title")) {
       a.disabled = true;
       if(a.getAttribute("title") == title) a.disabled = false;
     }
   }
}


function showElement(element) {
		var el=document.getElementById(element);
			el.style.visibility='visible';
			el.style.display='block';
	}
	
function hideElement(element) {
		var el=document.getElementById(element);
			el.style.visibility='hidden';
			el.style.display='none';
	}

function addEvent(elm, evType, fn, useCapture) {
// Cross-browser event handling for IE5+, NS6+ and Mozilla/Gecko
// By Scott Andrew
   if (elm.addEventListener) {
   elm.addEventListener(evType, fn, useCapture);
   return true;
   } else if (elm.attachEvent) {
   var r = elm.attachEvent('on' + evType, fn);
   return r;
   } else {
   elm['on' + evType] = fn;
   }
}


simplexhr = {
   doxhr : function( container, url ) {
   if( !document.getElementById || !document.createTextNode) {
      return;
   }
   simplexhr.outputContainer = document.getElementById( container );
   if( !simplexhr.outputContainer ){ return; }
   var request;
   try{
      request = new XMLHttpRequest();
   } catch ( error ) {
      try {
      request = new ActiveXObject( "Microsoft.XMLHTTP" );
      } catch ( error ) {
         return true;
      }
   }
   request.open( 'get', url );
   request.onreadystatechange = function() {
   if( request.readyState == 1 ) {
   simplexhr.outputContainer.innerHTML = '<h3>loading...</h3><hr /><p>Please wait while the server retrieves the requested information.</p>';
   }
   if( request.readyState == 4 ) {
      if ( /200|304/.test( request.status ) ) {
      simplexhr.retrieved(request);
      } else {
      simplexhr.failed(request);
      }
   }
   }
   request.send( null );
   return false;
   },
   
   failed : function( requester ) {
   simplexhr.outputContainer.innerHTML = '<p>Could not retrieve the requested data.</p>';
   return true;
   },
   retrieved : function( requester ) {
   var data = requester.responseText;
   simplexhr.outputContainer.innerHTML = data;
   return false;
   }
}

function ajaxLink(el) {
   remSelected();
   if (el.href!='#') {
      var script = el.href;
   }
   else { var script = el.title; }
   el.className='selected';
   var concat='&';
   if (!/\?/.test(script)) { concat='?'; }
   script += concat + 'temp=1';
   simplexhr.doxhr('body-text',script);
   window.location='#head';
   return false;
}

function ajaxSearch(type) {
   if (type==2) {
      var f = document.asearch;
   }
   else {
      var f = document.search;
   }
   var w = f.searcht.value;
   var script = 'search.php?temp=1&w=' + escape(w);
   if (type==2) { 
      var sm='all';
      var rb=document.getElementsByName('smode');
      for (var i=0;i<rb.length;i++) {
         if (rb[i].checked) { sm=rb[i].value; }
      }
      script += '&smode=' + sm; 
   }
   simplexhr.doxhr('body-text',script);
   return false;
}

function remSelected() {
   var aTags=document.getElementsByTagName('a');
   for (var i=0;i<aTags.length;i++) {
      if (/\bselected\b/.test(aTags[i].className)) {
         aTags[i].className=aTags[i].className.replace(/\s*selected/,'');
      }
   }
}

function addAjaxLinks() {
   var aTags=document.getElementsByTagName('a');
   for (var i=0;i<aTags.length;i++) {
      var rel=aTags[i].getAttribute('rel');
      if (rel=='internal') {
         aTags[i].onclick=function() {
            ajaxLink(this);
            return false;
         }
      }
      else if (rel=='search') {
         aTags[i].onclick=function() {
            ajaxSearch(1);
            return false;
         }
      }
      else if (rel=='asearch') {
         aTags[i].onclick=function() {
            ajaxSearch(2);
            return false;
         }
      }
   }
}

window.onload=addAjaxLinks;


function checkForm() {
   var f=document.nbmsg;
   var sd=trim(f.sender.value);
   var su=trim(f.subject.value);
   var e=trim(f.email.value);
   var ms=trim(f.msg.value);
   var error=false; var errorMsg='';
   if (sd.length<3) { error=true; errorMsg+='<li>Please enter your name</li>'; }
    if (!validEmail(e)) { error=true; errorMsg+='<li>Please enter a valid e-mail address</li>'; }
   if (su.length<6) { error=true; errorMsg+='<li>Please enter a subject (minimum 6 characters)</li>'; }
   if (ms.length<20) { error=true; errorMsg+='<li>Please enter a message (at least 20 characters or around 4 words)</li>'; }
   
   if (error && errorMsg.length>5) {
      var em=document.getElementById('errorMsg');
      em.innerHTML='<ul>' + errorMsg + '</ul>';
      window.location='#fb';
   }
   else {
      f.submit();
   }
}

function validEmail(email) {
	return /[a-zA-Z0-9_.-]+@\w+([a-zA-Z0-9_-]+\.)+[a-z][a-z]+/.test(email);
}

function trim(s) {
	return s.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
}