var mode = '';
var action = '';
var gridQString = "";
var motos = new Array();
var currentMoto = 0;
motos[0] = "Setting the standard in Telemarketing Software";
motos[1] = "Improve your productivity today!";
motos[2] = "Telemarketing Call Centre and Lead Tracking Software";

$(document).ready(function()
	{
		if (document.getElementById('menubar')) {
			$('#menubar').corner({
				  tl: { radius: 6 },
				  tr: { radius: 6 },
				  bl: { radius: 6 },
				  br: { radius: 6 }
				  });
		}
		if (document.getElementById('adminbar')) {
			$('#adminbar').corner({
				  tl: { radius: 6 },
				  tr: { radius: 6 },
				  bl: { radius: 6 },
				  br: { radius: 6 }
				  });
		}
		if (document.getElementById('mainimage')) {
			$('#mainimage').corner({
				  tl: { radius: 6 },
				  tr: { radius: 6 },
				  bl: { radius: 6 },
				  br: { radius: 6 }
				  });	
		}
		if (document.getElementById('wide')) {
			$('#wide').corner({
				  tl: { radius: 6 },
				  tr: { radius: 6 },
				  bl: { radius: 6 },
				  br: { radius: 6 }
				  });			
		}
		if (document.getElementById('l1')) {
			$('#l1').corner({
				  tl: { radius: 6 },
				  tr: { radius: 6 },
				  bl: { radius: 6 },
				  br: { radius: 6 }
				  });
		}
		if (document.getElementById('l2')) {
			$('#l2').corner({
				  tl: { radius: 6 },
				  tr: { radius: 6 },
				  bl: { radius: 6 },
				  br: { radius: 6 }
				  });
		}
		if (document.getElementById('l3')) {
			$('#l3').corner({
				  tl: { radius: 6 },
				  tr: { radius: 6 },
				  bl: { radius: 6 },
				  br: { radius: 6 }
				  });
		}
		if (document.getElementById('l4')) {
			$('#l4').corner({
				  tl: { radius: 6 },
				  tr: { radius: 6 },
				  bl: { radius: 6 },
				  br: { radius: 6 }
				  });			
		}
		if (document.getElementById('l5')) {
			$('#l5').corner({
				  tl: { radius: 6 },
				  tr: { radius: 6 },
				  bl: { radius: 6 },
				  br: { radius: 6 }
				  });			
		}
		if (document.getElementById('l6')) {
			$('#l6').corner({
				  tl: { radius: 6 },
				  tr: { radius: 6 },
				  bl: { radius: 6 },
				  br: { radius: 6 }
				  });			
		}
		
		//$(document).pngFix(); 
		setInterval( function() {
			if (mode != 'admin') {
				ping();
			}
			currentMoto++;
			if (currentMoto == motos.length) {
				currentMoto = 0;
			} 
			$('#moto').fadeOut('slow', function() {
				$('#moto').html(motos[currentMoto]);
				$('#moto').fadeIn('slow');
				});
		
		
		}, 5000);
	}
);

function showFAQ( id ) {

	if ($('#answer'+id).is(':hidden')) {
		$( ".answer" ).each(	
			function() {
				if ($(this).is(':visible')) {
					$(this).slideUp();		
				}
			}
		);
		$('#answer'+id).slideDown();
		$('#actor').load('ajax/faqclick/' + id);
	} else {
		$('#answer'+id).slideUp();
	}

}

function stripNAN( strString ) {

	var strValidCharacters = "1234567890";
	var strReturn = "";
	var strBuffer = "";
	var intIndex = 0;
	for( intIndex = 0; intIndex < strString.length; intIndex++ ) {
          strBuffer = strString.substr( intIndex, 1 );

          if( strValidCharacters.indexOf( strBuffer ) > -1 ) {
               strReturn += strBuffer;
          }
	}
	return strReturn;
	
}

function uenc( text ) {
	return encodeURIComponent( text );
}

function getInputs( divId ) {

	var inputs = [];
	
	$(':input','#'+divId).each(function() {
		if (this.type == "checkbox" || this.type == "radio") {
			if (this.checked == true) {	
				inputs.push(this.name + '=' + uenc(this.value));
			}
		} else {
			inputs.push(this.name + '=' + uenc(this.value));
		}
	});
	
	return inputs.join('&');

}

function postContactForm() {

	$('#ajaxloader').fadeIn();

	var formdata = getInputs('l4');
	
	$.ajax({
	type: 'POST',
	url: 'ajax/contact',
	data: formdata,
	success: function(html) {
		eval(html);
	}
	});

}

function postRegForm() {

	$('#ajaxloader').fadeIn();

	var formdata = getInputs('customerreg');
	 
	$.ajax({
	type: 'POST',
	url: 'ajax/register',
	data: formdata,
	success: function(html) {
		eval(html);
	}
	});

}

function forgotPass() {

	var formdata = getInputs('customerforgot');
	 
	$.ajax({
	type: 'POST',
	url: 'ajax/forgot',
	data: formdata,
	success: function(html) {
		eval(html);
	}
	});

}

function ping() {

	$.ajax({
	type: 'POST',
	url: 'ajax/ping',
	data: '',
	success: function(html) {
		
	}
	});


}

function popUp(URL,w,h) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+w+",height="+h+"');");
}

function checkVal ( eid ) {
	if (document.getElementById(eid)) {
		if (document.getElementById(eid).checked) {
return "T";
		} else {
			return "F";
		}
	} else {
		return "U";
	}
}

function searchSite( text ) {

	var url = 'http://www.google.com/cse?cx=016478480100170485256%3A5bq1vwuoaj0&ie=UTF-8&q='+uenc(text)+'&sa=Search';
	window.location.href=url;
	
}

function checkForReturn(e) {
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
	if (KeyID == 13) { return true; } else { return false;}
}

function newsletterSuscribe( email ) {

	$.ajax({
	type: 'POST',
	url: 'ajax/suscribe',
	data: 'email='+email,
	success: function(html) {
		eval(html);
	}
	});
}

function navTo( url ) {
	window.location.href=url;
}

