var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

function changeTitle(){
	var id="";
	var name="";
	var country = document.getElementById("countries").value;
	if(country == ''){
		id='';
		name='';
	}else{
		var countries=country.split('|');
		id =countries[0];
		name=countries[1];
	}

	$('countryName').innerHTML=name;

	var url="/services/whereItWorks.php?c="+id;

	new Ajax.Request(url,{
		method: 'get',
		onSuccess: function(response){
			$('answerContent').innerHTML=response.responseText;
		}
	});

}

function validateLogin(){
	var root = document.memberslog;

	var username = root.dtaccount.value;
	var password = root.dtpassword.value;
	if (username == 'Username'){
		alert('Please give your username.');
		root.dtaccount.focus();
		return false;
	}
	if (password == '********'){
		alert('Please give your password.');
		root.dtpassword.focus();
		return false;
	}
	//	password = hex_md5(password);
	//	root.password.value = password;
	//	root.hashed.value = 'yes';
	return true;
}
function changeFontColor(fcolor,id){
	if(fcolor == ''){
		document.getElementById(id).style.color='#737373';
	}else{
		document.getElementById(id).style.color=''+fcolor+'';
	}

}

function fieldOnFocus(t){
		if(t=='1'){
			if(document.newsletter.name.value=='Full Name'){
				document.newsletter.name.value='';
			}else{
				return true;
			}
		}else{
			if(document.newsletter.email.value=='Email'){
			
				document.newsletter.email.value='';
							
			}else{
				return true;
			}
		}
	}
	
	function fieldOnBlur(t){
		if(t=='1'){
			if(document.newsletter.name.value==''){
				document.newsletter.name.value='Full Name';
			}else{
				return true;
			}
		}else{
			if(document.newsletter.email.value==''){
				document.newsletter.email.value='Email';
			}else{
				return true;
			}
		}
	}
	
function radar(id,counter,total){
	for(var i=1; i<= total;i++){
		document.getElementById('blue_'+i+'').style.display='none';
	}
	document.getElementById('blue_'+counter+'').style.display='block';
	url='/faq/getanswer.php?qid='+id;
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function() {
		if(xmlhttp.readyState== 4) {
			if(xmlhttp.status == 200){
				radarResponse = xmlhttp.responseText;
				printAns(radarResponse,counter);
			}
		}
	}
	xmlhttp.send(null);
}

function rotate_banner(allImages){
	var image;
	imagesArray=allImages.split('|');
	var length=imagesArray.length-1;
	if(length == 0){
		return false;
	}else{
		setTimeout("eval(rotate_top_hm('"+images+"'));",9000);
		i++;
		if(i>=length){
			i=0;
		}
		image=imagesArray[i];
		new Effect.Opacity('top_pics_hm', { from: 1, to: 0, duration: 1 });
		setTimeout("new Effect.Opacity('homeBanner', { from: 0, to: 1, duration: 1 });",1000);
		setTimeout("eval(get_banner_image('"+image+"'));",1000);

		return false;
	}
}
function get_banner_image(image){

	var bannerDiv = document.getElementById('homeBanner');
	bannerDiv.style.background-image("/images/homeBanner/"+image+"");
}

function printAns(responce,counter){
	var count =document.getElementById('counter').value;
	document.getElementById('answer').innerHTML='';
	document.getElementById('answer').innerHTML=responce;

	for(var i=1;i<count;i++){
		document.getElementById("q_"+i).className='normalText';
	}
	document.getElementById('q_'+counter).className='normalTextBlue';
}



function validChars(e,goods,field,max) {

	var key, keychar;
	key = (window.event) ? window.event.keyCode : ((e) ? e.which : null);
	if (key == null) return true;

	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	goods = goods.toLowerCase();
	if(keychar<2) return false;
	if (goods.indexOf(keychar) != -1)
	return true;

	if (key==null || key==0 || key==8 || key==9 || key==13 || key==27)
	return true;

	return false;
}

function validateCheckoutForm(){

	var root = document.checkout;
	if(root.first_name.value==''){
		alert('Please enter your first name');
		root.first_name.focus();
		return false;
	}
	if(root.last_name.value==''){
		alert('Please enter your last name');
		root.last_name.focus();
		return false;
	}

	if(root.country.value==''){
		alert('Please select your country from the drop down menu');
		root.country.focus();
		return false;
	}

	if(root.city.value==''){
		alert('Please enter your city');
		root.city.focus();
		return false;
	}

	if(root.phone.value==''){
		alert('Please enter your telephone number');
		root.phone.focus();
		return false;
	}

	if(root.address.value==''){
		alert('Please enter home address');
		root.address.focus();
		return false;
	}

	return true;
}


function validateLocalCLIForm(){

	var root = document.localCLI;
	if(root.name.value==''){
		alert('Please enter your name');
		root.name.focus();
		return false;
	}
	if(root.phone.value==''){
		alert('Please enter your telephone number');
		root.phone.focus();
		return false;
	}

	if(root.email.value==''){
		alert('Please enter your email');
		root.email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	flag=root.email.value.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		root.email.select();
		return false;
	}
	if(root.callBack.value==''){
		alert('Please specify your location');
		return false;
	}
	if(root.vcode.value==''){
		alert('Please enter the visual code');
		root.vcode.focus();
		return false;
	}


	return true;
}

function validateBusinessForm(){

	var root = document.business;
	if(root.name.value==''){
		alert('Please enter your name');
		root.name.focus();
		return false;
	}
	if(root.phone.value==''){
		alert('Please enter your telephone number');
		root.phone.focus();
		return false;
	}
	if(root.address.value==''){
		alert('Please enter your address');
		root.address.focus();
		return false;
	}
	if(root.country.value==''){
		alert('Please enter your country');
		root.country.focus();
		return false;
	}

	if(root.email.value==''){
		alert('Please enter your email');
		root.email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	flag=root.email.value.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		root.email.select();
		return false;
	}
	if(root.callBack.value==''){
		alert('Please specify your location');
		return false;
	}
	if(root.destinations.value==''){
		alert('Please specify the destinations');
		root.destinations.focus();
		return false;
	}
	if(root.volume.value==''){
		alert('Please enter your projected monthly volume');
		root.volume.focus();
		return false;
	}
	if(root.vcode.value==''){
		alert('Please enter the visual code');
		root.vcode.focus();
		return false;
	}

	return true;
}


function validateWholesaleForm(){

	var root = document.wholesaleform;
	if(root.name.value==''){
		alert('Please enter your full name');
		root.name.focus();
		return false;
	}
	if(root.phone.value==''){
		alert('Please enter your telephone number');
		root.phone.focus();
		return false;
	}
	if(root.address.value==''){
		alert('Please enter home address');
		root.address.focus();
		return false;
	}

	if(root.country.value==''){
		alert('Please select your country from the drop down menu');
		root.country.focus();
		return false;
	}
	if(root.email.value==''){
		alert('Please enter your email');
		root.email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	flag=root.email.value.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		root.email.select();
		return false;
	}
	if(root.volume.value==''){
		alert('Please enter your monthly volume');
		root.volume.focus();
		return false;
	}
	if(root.destinations.value==''){
		alert('Please enter the destinations you wish to terminate.');
		root.destinations.focus();
		return false;
	}

	return true;
}


function validateEditMember(){
	var root = document.members;
	if(root.first_name.value==''){
		alert('Please enter your first name');
		root.first_name.focus();
		return false;
	}
	if(root.last_name.value==''){
		alert('Please enter your last name');
		root.last_name.focus();
		return false;
	}

	if(root.telephone.value==''){
		alert('Please enter your telephone number');
		root.telephone.focus();
		return false;
	}

	if(root.email.value==''){
		alert('Please enter your email');
		root.email.focus();
		return false;
	}

	if(root.city.value==''){
		alert('Please enter your city');
		root.city.focus();
		return false;
	}

	if(root.country.value==''){
		alert('Please select a country from the drop down menu');
		root.country.focus();
		return false;
	}

	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	flag=root.email.value.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		root.email.select();
		return false;
	}

	if(root.home_address.value==''){
		alert('Please enter home address');
		root.home_address.focus();
		return false;
	}

	return true;
}


function validateFinalStep(){
	var root = document.members;
	if(root.first_name.value==''){
		alert('Please enter your first name');
		root.first_name.focus();
		return false;
	}
	if(root.last_name.value==''){
		alert('Please enter your last name');
		root.last_name.focus();
		return false;
	}

	if(root.telephone.value==''){
		alert('Please enter your telephone number');
		root.telephone.focus();
		return false;
	}

	if(root.email.value==''){
		alert('Please enter your email');
		root.email.focus();
		return false;
	}

	if(root.country.value==''){
		alert('Please select a country from the drop down menu');
		root.country.focus();
		return false;
	}

	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	flag=root.email.value.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		root.email.select();
		return false;
	}

	var purchase_amount = root.purchase_amount;
	if(purchase_amount[0].checked==false&&purchase_amount[1].checked==false&&purchase_amount[2].checked==false){
		alert('Please specify the purchase amount before submitting.');
		return false;
	}

	return true;
}

function passValidation(){
	var root = document.change_password;
	var oldp = root.old.value;
	var newp = root.newp.value;
	var confnew = root.confnew.value;

	if (oldp == '' || newp == '' || confnew == ''){
		alert('Please fill up all the fields');
		root.old.focus();
		return false;
	}
	if (!isNaN(newp)){
		alert('Please insert a password that contains characters.');
		root.newp.focus();
		return false;
	}

	if (newp != confnew){
		alert('The password and it\'s confirmation do not match');
		root.confnew.focus();
		return false;
	}

	oldp = hex_md5(oldp);
	newp = hex_md5(newp);
	confnew = hex_md5(confnew);

	root.old.value = oldp;
	root.newp.value = newp;
	root.confnew.value = confnew;
	root.enc.value = '1';

	return true;
}



function clearMembersForm(){
	var root=document.members;

	var username=root.username;
	var pass=root.pass;
	var conpass=root.conpass;
	var fname=root.fname;
	var lname=root.lname;
	var tel=root.tel;
	var fax=root.fax;
	var email=root.email;
	var add=root.add;

	if(confirm('Are you sure you want to clear this form?')){
		username.value="";
		pass.value="";
		conpass.value="";
		fname.value="";
		lname.value="";
		tel.value="";
		fax.value="";
		email.value="";
		add.value="";

		return false;
	}

	return false;
}
function clearBusinessForm(){
	var root=document.business;

	var name=root.name;
	var phone=root.phone;
	var email=root.email;
	var country=root.country;
	var destinations=root.destinations;
	var volume=root.volume;
	var comments=root.comments;
	var vcode=root.vcode;
	var amount=root.amount;
	var product=root.product;
	var experience=root.experience;
	var address=root.address;


	if(confirm('Are you sure you want to clear this form?')){
		name.value="";
		phone.value="";
		email.value="";
		country.value="";
		destinations.value="";
		volume.value="";
		comments.value="";
		vcode.value="";
		document.getElementById('product').checked=true;
		document.getElementById('amount').checked=true;
		document.getElementById('experience').checked=true;
		address.value="";

		return false;
	}

	return false;
}

function validateAddMember(){

	var root = document.members;

	var firstName = root.fname.value;
	var lastName = root.lname.value;
	var address = root.add.value;
	var tel = root.tel.value;
	var email = root.email.value;
	var city = root.city.value;
	var country = root.country.value;
	var username = root.username.value;
	var password = root.pass.value;
	var confirm_password = root.conpass.value;
	if (username == ''){
		alert('Please give your username');
		root.username.focus();
		return false;
	}

	if (password == ''){
		alert('Please specify your password');
		root.pass.focus();
		return false;
	}

	if (password != confirm_password){
		alert('Your password and its confirmation do not match');
		root.conpass.focus();
		return false;
	}
	if (firstName == ''){
		alert('Please specify your first name');
		root.fname.focus();
		return false;
	}

	if (lastName == ''){
		alert('Please specify your last name');
		root.lname.focus();
		return false;
	}

	if (tel == ''){
		alert('Please give your home phone');
		root.tel.focus();
		return false;
	}

	if (email == ''){
		alert('Please give your email address');
		root.email.focus();
		return false;
	}

	if (country== ''){
		alert('Please select a country from the drop down menu');
		root.country.focus();
		return false;
	}

	if (city == ''){
		alert('Please give your city');
		root.city.focus();
		return false;
	}

	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;

	flag=email.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		root.email.select();
		return false;
	}

	if (address == ''){
		alert('Please specify your address');
		root.add.focus();
		return false;
	}

	password = hex_md5(password);
	confirm_password = hex_md5(confirm_password);

	root.hashed.value = '1';
	root.pass.value = password;
	root.conpass.value = confirm_password;
	return true;
}

function validateForgotPass(){
	var root=document.forgot_pass;
	if(root.username.value==''){
		alert('Please insert your username');
		root.username.focus();
		return false;
	}

	if(root.email.value==''){
		alert('Please insert your email address');
		root.email.focus();
		return false;
	}

	return true;
}


function validateSearch(){
	if(document.search.keyword.value==''){
		alert('Please insert a keyword before submitting');
		document.search.keyword.focus();
		return false;
	}
	return true;
}

function validateFaq(){
	var root=document.submit_faq;
	if(root.email.value==''){
		alert('Please provide your email address');
		root.email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	flag=root.email.value.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		root.email.select();
		return false;
	}

	if(root.question.value==''){
		alert('Please add your question');
		root.question.focus();
		return false;
	}

	return true;
}

function validateSearch(){
	if(document.search.keyword.value==''){
		alert('Please insert a keyword before submitting');
		document.search.keyword.focus();
		return false;
	}
	return true;
}


function checkContactform(){
	var root=document.contact;

	var name=root.name;
	var email=root.email;
	var subject=root.subject;
	var message=root.message;
	var vcode=root.vcode;

	if(name.value==""){
		alert('Please enter your full name.');
		name.focus();
		return false;
	}
	if(email.value==""){
		alert('Please enter an email address.');
		email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	flag=email.value.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		email.focus();
		return false;
	}
	if(subject.value==""){
		alert('Please enter the subject.');
		subject.focus();
		return false;
	}
	if(message.value==""){
		alert('Please enter your message.');
		message.focus();
		return false;
	}
	if(vcode.value==""){
		alert('Please supply the visual code before submitting.');
		vcode.focus();
		return false;
	}
}

function checkBusinessform(){
	var root=document.contact;

	var name=root.name;
	var email=root.email;
	var subject=root.subject;
	var purpose=root.purpose;
	var message=root.message;
	var vcode=root.vcode;

	if(name.value==""){
		alert('Please enter your full name.');
		name.focus();
		return false;
	}
	if(email.value==""){
		alert('Please enter an email address.');
		email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	flag=email.value.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		email.focus();
		return false;
	}
	if(purpose.value==""){
		alert('Please enter the purpose.');
		purpose.focus();
		return false;
	}if(subject.value==""){
		alert('Please enter the subject.');
		subject.focus();
		return false;
	}
	if(message.value==""){
		alert('Please enter your message.');
		message.focus();
		return false;
	}
	if(vcode.value==""){
		alert('Please supply the visual code before submitting.');
		vcode.focus();
		return false;
	}
}

function clearContactForm(){
	var root=document.contact;

	var name=root.name;
	var email=root.email;
	var subject=root.subject;
	var message=root.message;
	var vcode=root.vcode;

	if(confirm('Are you sure you want to clear this form?')){
		name.value="";
		email.value="";
		subject.value="";
		message.value="";
		vcode.value="";

		return false;
	}

	return false;
}

function clearWholesaleForm(){
	var root=document.wholesaleform;

	var name=root.name;
	var email=root.email;
	var address=root.address;
	var country=root.country;
	var volume=root.volume;
	var destinations=root.destinations;
	var otherInput=root.otherInput;
	var phone=root.phone;
	var comments=root.comments;
	var vcode=root.vcode;

	if(confirm('Are you sure you want to clear this form?')){
		//		var name=document.getElementById('name').value;
		name.value="";
		email.value="";
		phone.value="";
		address.value="";
		country.value="";
		destinations.value="";
		volume.value="";
		comments.value="";
		vcode.value="";
		otherInput.value="Please Specify";
		otherInput.disabled='true';




		return false;
	}

	return false;
}


function changeVisibility(form){

	var vis = document.getElementById(form).style.visibility;
	if(vis=='hidden'){
		document.getElementById(form).style.visibility='visible';
	}else{
		document.getElementById(form).style.visibility='hidden';
	}

	if(form=='newsletter'){
		document.getElementById('tellafriend').style.visibility='hidden';
	}else{
		document.getElementById('newsletter').style.visibility='hidden';
	}
}

function validatemailinglist(){
	var root=document.newsletter;
	if(root.name.value=='Full Name'){
		alert('Please provide your full name');
		root.name.focus();
		return false;
	}
	if(root.email.value=='Email'){
		alert('Please provide your email');
		root.email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	flag=root.email.value.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		root.email.select();
		return false;
	}
	return true;
}

function validateTellAFriend(e){
	var root = document.tell_a_friend;
	var name = root.name.value;
	if (name=='Your Name'){
		alert('Please fill up your name');
		root.name.focus();
		return false;
	}
	var email = root.email.value;
	if (email=='Your Email'){
		alert('Please fill up your email');
		root.email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	flag=email.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		root.email.select();
		return false;
	}
	var count=0;
	for(var i=0;i<e;i++){
		var f_name= eval('root.f_name'+i+'.value');
		var f_email= eval('root.f_email'+i+'.value');
		if(f_name=='Friends Name'&&f_email=='Friends Email'){
			count++;
		}
		if(f_name=='Friends Name'&&f_email!='Friends Email'){
			alert('Please fill up your friends name');
			eval('root.f_name'+i+'.focus()');
			return false;
		}
		if(f_name!='Friends Name'&&f_email=='Friends Email'){
			alert('Please fill up your friends email');
			eval('root.f_email'+i+'.select()');
			return false;
		}
		var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
		if(f_name!=''){
			flag=f_email.match(pattern);
			if(!flag){
				alert('Please insert a valid email address.');
				eval('root.f_email'+i+'.select()');
				return false;
			}
		}
	}
	if(count==e){
		alert('Please provide a friend\'s email');
		root.f_name0.focus();
		return false;
	}

	return true;
}

function validChars(e,goods,field,max) {

	var key, keychar;
	key = (window.event) ? window.event.keyCode : ((e) ? e.which : null);
	if (key == null) return true;

	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	goods = goods.toLowerCase();

	if (goods.indexOf(keychar) != -1)
	return true;

	if (key==null || key==0 || key==8 || key==9 || key==13 || key==27)
	return true;

	return false;
}

function SetUnitPrice(){
	var calling= document.getElementById("calling_from").value;
	document.rate_form.rate.value = calling;
}

function SetGlobalReceivePrice(){
	var calling= document.getElementById("global_receive").value;
	document.getElementById('global_receive_rate').value = calling;
}

function SetGlobalSMSPrice(){
	var calling= document.getElementById("global_sms").value;
	document.getElementById('global_sms_rate').value = calling;
}

function SetUnitPriceGlobal(){
	var calling= document.getElementById("calling_from_global").value;
	document.getElementById('global_from_to_rate').value = calling;
}

function SetUnitPriceIp(){
	var calling= document.getElementById("calling_to").value;
	document.rate_form.rate.value = calling;
}

function SetBothPrice(){
	var calling= document.getElementById("calling_from").value;
	if(calling == ''){
		alert('Please choose from where you want to call');

	}
	var to = document.getElementById("calling_to").value;
	var all = parseFloat(calling)+ parseFloat(to);
	sum = String(all);
	var array = sum.split('.');
	var dec2 = sum.substring(2,5);
	if(dec2 == ''){
		var nb1 = array[0];
		var dec = '00';
	}
	else{
		var nb1 = array[0];
		var dec = array[1];
	}
	dec = dec.substring(0,3);
	sum = nb1+'.'+dec;
	document.rate_form.rate.value = sum;
}
function SetBothPriceGlobal(){
	var calling= document.getElementById("calling_from_global").value;

	if(calling == ''){
		alert('Please choose from where you want to call');

	}
	var to = document.getElementById("calling_to_global").value;
	var all = parseFloat(calling)+ parseFloat(to);
	sum = String(all);
	var array = sum.split('.');
	var dec2 = sum.substring(2,5);
	if(dec2 == ''){
		var nb1 = array[0];
		var dec = '00';
	}
	else{
		var nb1 = array[0];
		var dec = array[1];
	}
	dec = dec.substring(0,3);
	sum = nb1+'.'+dec;
	document.getElementById('global_from_to_rate').value = sum;
}