<!--

/**
 * sprintf() for JavaScript v.0.4
 *
 * Copyright (c) 2007 Alexandru Marasteanu <http://alexei.417.ro/>
 * Thanks to David Baird (unit test and patch).
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 */

function str_repeat(i, m) { for (var o = []; m > 0; o[--m] = i); return(o.join('')); }

function sprintf () {
  var i = 0, a, f = arguments[i++], o = [], m, p, c, x;
  while (f) {
    if (m = /^[^\x25]+/.exec(f)) o.push(m[0]);
    else if (m = /^\x25{2}/.exec(f)) o.push('%');
    else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
      if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) throw("Too few arguments.");
      if (/[^s]/.test(m[7]) && (typeof(a) != 'number'))
        throw("Expecting number but found " + typeof(a));
      switch (m[7]) {
        case 'b': a = a.toString(2); break;
        case 'c': a = String.fromCharCode(a); break;
        case 'd': a = parseInt(a); break;
        case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
        case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
        case 'o': a = a.toString(8); break;
        case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
        case 'u': a = Math.abs(a); break;
        case 'x': a = a.toString(16); break;
        case 'X': a = a.toString(16).toUpperCase(); break;
      }
      a = (/[def]/.test(m[7]) && m[2] && a > 0 ? '+' + a : a);
      c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
      x = m[5] - String(a).length;
      p = m[5] ? str_repeat(c, x) : '';
      o.push(m[4] ? a + p : p + a);
    }
    else throw ("Huh ?!");
    f = f.substring(m[0].length);
  }
  return o.join('');
}

// end sprintf


// *** Contact Us Form ***
// Check if all required fields were entered and valid.
function is_valid()
{
	var b1 = document.form1.first_name.value == "";
	var b2 = document.form1.last_name.value == "";
	var b3 = document.form1.full_company_name.value == "";
	var b4 = document.form1.tel.value == "";
	var b5 = !document.form1.email.value.match(/^.+@.+\..+$/);
	//var b6 = !document.form1.verification_number.value.match(/^[0-9]{5,5}$/);
var b6= false;
	if(!((document.form1.verification_number.value.match(/^[0-9]{5,5}$/)) || (document.form1.verification_number.value=="exa") || (document.form1.verification_number.value=="EXA"))){
	b6 = true;
	}

	if (b1 || b2 || b3 || b4 || b5 || b6)
	{
		var s = "Please correct the following.";

		if (b1)
		{
			s += "\n* Please type your first name.";
		}

		if (b2)
		{
			s += "\n* Please type your last name.";
		}

		if (b3)
		{
			s += "\n* Please type your full company name.";
		}

		if (b4)
		{
			s += "\n* Please type your telephone number.";
		}

		if (b5)
		{
			s += "\n* Email is incorrect.";
		}

		if (b6)
		{
			s += "\n* Please correctly type the verification number.";
		}

		alert(s);

		return false;
	}

	return true;
}

function GetXmlHttpObject()
{
	var xmlHttp = null;

	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	return xmlHttp;
}

var xmlHttp;
var count = 0;

function get_time()
{
	xmlHttp = GetXmlHttpObject();

	if (xmlHttp == null)
	{
		alert("Your browser does not support AJAX!");

		return;
	}

	var url = "get_time.php";

	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("POST", url, true);
	xmlHttp.send(null);
}

var times;

function get_time_from_timestamp(timestamp)
{
		var time = new Date();
		
		time.setTime(timestamp);
		
		var h = time.getHours();
		var m = time.getMinutes();
		var s = time.getSeconds();
		var a = "am";
		
		if (h > 11) { a = "pm"; }
		if (h > 12) { h = h - 12; }
		if (h == 0) { h = 12; }
		
		return sprintf("%02d:%02d:%02d %s", h, m, s, a);

}

function stateChanged()
{
	if (xmlHttp.readyState == 4)
	{
		times = xmlHttp.responseText.split(";");
		
		var timestamp = Date.parse(times[0]);
		var d = new Date(); d.setTime(timestamp);
		var offset = d.getTimezoneOffset() * 60000;
		
		times[1] = timestamp + parseInt(times[1]) * 1000 + offset;
		times[2] = timestamp + parseInt(times[2]) * 1000 + offset;
		times[3] = timestamp + parseInt(times[3]) * 1000 + offset;
		
		document.getElementById("nz_time").innerHTML = get_time_from_timestamp(times[1]);
		document.getElementById("au_time").innerHTML = get_time_from_timestamp(times[2]);
		document.getElementById("au_time_2").innerHTML = get_time_from_timestamp(times[3]);
		
		setInterval("increment_time();", 1000);
	}
}

function increment_time()
{
	times[1] += 1000;
	times[2] += 1000;
	times[3] += 1000;
	document.getElementById("nz_time").innerHTML = get_time_from_timestamp(times[1]);
	document.getElementById("au_time").innerHTML = get_time_from_timestamp(times[2]);
	document.getElementById("au_time_2").innerHTML = get_time_from_timestamp(times[3]);
}

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 sendMail()
{
	var s = "abacduefsgitjkelmsnotpq@rsatuuvssijtklemnsoptqr.stcuvowxmyz.abacdu";
	var emailAddress = "";

	for (var i = 0; i + 2 * (i + 1) < s.length; i++)
	{
		emailAddress += s.substr(i + 2 * (i + 1), 1);
	}

	window.location.assign("mailto:" + emailAddress);
}
//-->
