// Javascript File

function change_type() {
	document.getElementById('changetype').submit();
}

function changecategory() {
	document.getElementById('changecategory').submit();
}

function loginvalidate() {
	var username = document.form2.username.value;
	var password = document.form2.password.value;
	if(username == "") {
		alert("Please fill in username");
		document.form2.username.select();
		return false;
	} else if(password == "") {
		alert("Please fill in password");
		document.form2.password.select();
		return false;
	}
}


// Call php page for membercategory change
function GetXmlHttpObject() {
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject) {
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}

function add_client(add_client) {
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null) {
		alert ("Your browser does not support XMLHTTP!");
		return;
	}
	var url="ajaxquery.php";
	url=url+"?"+add_client+"=all";
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function show_leadgroups(leadgroups) {
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null) {
		alert ("Your browser does not support XMLHTTP!");
		return;
	}
	var url="ajaxquery.php";
	url=url+"?"+leadgroups+"=all";
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
function add_tariff(addtariff) {
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null) {
		alert ("Your browser does not support XMLHTTP!");
		return;
	}
	var url="ajaxquery.php";
	url=url+"?"+addtariff+"=all";
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
function add_rate(id_rate) {
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null) {
		alert ("Your browser does not support XMLHTTP!");
		return;
	}
	var url="ajaxquery.php";
       	url=url+"?id_rate="+id_rate+"&?test=all";
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
function stateChanged() {
	if (xmlhttp.readyState==4) {
		document.getElementById("ajaxfill").innerHTML=xmlhttp.responseText;
	}
}

// Check all if a master button in clicked
function mastercheck() {
	if (document.forms["frm1"]["master"].checked == true) {
		document.forms["frm1"]["choices[]"].checked = true;
		for (var i = 0; i < document.forms["frm1"]["choices[]"].length; i++) {
			document.forms["frm1"]["choices[]"][i].checked = true;
		}
	} else {
		document.forms["frm1"]["choices[]"].checked = false;
		for (var i = 0; i < document.forms["frm1"]["choices[]"].length; i++) {
			document.forms["frm1"]["choices[]"][i].checked = false;
		}
	}
}

// Sign Up form validation

function ValidateForm1(theForm) {
	if (theForm.Combobox2.selectedIndex < 0) {
	   alert("Please Select A Service");
	   theForm.Combobox2.focus();
	   return false;
	}
	if (theForm.Combobox2.selectedIndex == 0) {
	   alert("Please Select A Service");
	   theForm.Combobox2.focus();
	   return false;
	}
	return true;
}

function signupvalidate() {
	var name = document.form1.name.value;
	var address = document.form1.address.value;
	var country = document.form1.country.value;
	var phone = document.form1.phone.value;
	var email = document.form1.email.value;
	var password = document.form1.password.value;
	var confirmpassword = document.form1.confirmpassword.value;
	var currency = document.form1.currency.value;
	
	if(name == "" || address == "" || country == "" || phone == "" || email == "" || password == "" || confirmpassword == "" || currency == "") {
		alert("All Fields with * are necessary");
		document.form1.name.focus();
		return false;
	} else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))) {
		alert("Invalid E-mail Address");
		document.form1.email.select();
		return false;
	} else if(password != confirmpassword) {
		alert("Sorry both password must be same");
		document.form1.password.select();
		return false;
	}
}


// Change Password

function changepassword() {
	var cardno = document.Form1.cardno.value;
	var newcardno = document.Form1.newcardno.value;
	var confirmnewcardno = document.Form1.confirmnewcardno.value;
	
	if(cardno == "" || newcardno == "" || confirmnewcardno == "") {
		alert("All Fields with * are necessary");
		document.Form1.cardno.focus();
		return false;
	} else if(newcardno != confirmnewcardno) {
		alert("Sorry both password must be same");
		document.Form1.newcardno.select();
		return false;
	}
}


// Reseller page

function resellervalidate() {
	var name = document.form1.name.value;
	var address = document.form1.address.value;
	var country = document.form1.country.value;
	var phone = document.form1.phone.value;
	var email = document.form1.email.value;
	var currency = document.form1.currency.value;
	
	if(name == "" || address == "" || country == "" || phone == "" || email == "" || currency == "") {
		alert("All Fields with * are necessary");
		document.form1.name.focus();
		return false;
	} else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))) {
		alert("Invalid E-mail Address");
		document.form1.email.select();
		return false;
	}
}

function change_currency() {
	document.getElementById('currency').submit();
}

function popupwnd(url, toolbar, menubar, locationbar, resize, scrollbars, statusbar){
	var width = 245;
	var height = 125;
	var left = parseInt((screen.availWidth/2) - (width/2));
	var top = parseInt((screen.availHeight/2) - (height/2));
	var popupwindow = this.open(url, '', 'toolbar=' + toolbar + ',menubar=' + menubar + ',location=' + locationbar + ',scrollbars=' + scrollbars + ',resizable=' + resize + ',status=' + statusbar + ',left=' + left + ',top=' + top + ',width=' + width + ',height=' + height);
}

