// JavaScript Document

function isNum(passedVal) {
	if (passedVal == "") {
		return false }
	for (i=0; i<passedVal.length; i++) {
		if (passedVal.charAt(i) < "0") {
			return false }
		if (passedVal.charAt(i) > "9") {
			return false }
	}
	return true
}


function validZip(inzip) {
	if (isNum(inzip)) {
		return true }
return false
}
	
function validEmail(inEmail) {
	invalidChars = "/:,;"
	if (inEmail == "") {
		return false; }
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (inEmail.indexOf(badChar,0) > -1) {
			return false; }
		}
		atPos = inEmail.indexOf("@",1)
		if (atPos == -1) {
			return false; }
		if (inEmail.indexOf("@",atPos+1) > -1) {
			return false; }
		periodPos = inEmail.indexOf(".",atPos)
		if (periodPos == -1) {
			return false; }
		if (periodPos+3 > inEmail.length) {
			return false; }
		else {
			return true; }
}
	
//Form validation Check Main Registration  START


function validFormStep1(step1) {
	var d = step1;
	var tt = $F("transaction_type");
	var t = $F("transaction");
	myt = -1;
	mytt = -1;
	
for (i=d.transaction.length-1; i > -1; i--) {
	if (d.transaction[i].checked) {
		mytt = i;
	}
}
for (i=d.transaction_type.length-1; i > -1; i--) {
	if (d.transaction_type[i].checked) {
		myt = i;
	}
}

	if (d.name.value == "") {
		alert("You must enter a project name")
		d.name.focus()
		return false; }
	if (myt == -1) {
		alert("You must select a transaction type");
		return false;}
	if (mytt == -1) {
		alert("You must pick a transaction");
		return false; }

	else {
		return true; }
}

function validFormPasswd(passwd) {
	var d = passwd;
	if (d.email.value == "") {
		alert("You must enter an email address")
		d.email.focus()
		return false; }
		
	if (!validEmail(d.email.value)) {
		alert("You must enter a valid email address")
		d.email.focus()
		return false; }

	else {
		return true; }
}


function validFormChangePasswd(change_passwd) {
	var d = change_passwd;
	var valid="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var num_valid="123456789";
	var alph_valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var minLength = 6; 
	var sizechar = d.passwd.value.length;
	var passwdString = d.passwd.value;
	var numCount = 0;
	var alphaCount = 0;
	if (d.old_password.value == "") {
		alert("You must your original password")
		d.old_password.focus()
		return false; }
	
	if (d.passwd.value == "") {
		alert("You must enter a password")
		d.passwd.focus()
		return false; }
		
	if (d.passwd.value.length < minLength) {
		alert('Your password must be at least ' + minLength + ' characters long. Try again.');
		return false; }
		
    for (var i=0; i<sizechar; i++) {
        if (num_valid.indexOf(passwdString.charAt(i)) < 0) {
			numCount++;
		}
	}
	 if (numCount==sizechar) {
            alert('Your password contains only characters. Please enter an alphanumeric value like ' + num_valid);
			d.passwd.focus();
            return false;
        }

    for (var i=0; i<sizechar; i++) {
        if (alph_valid.indexOf(passwdString.charAt(i)) < 0) {
			alphaCount++;
		}
	}
	
		if (alphaCount==sizechar) {
            alert('Your password contains only numbers. Please enter an alphanumeric value like a,b,c etc');
			d.passwd.focus();
            return false;
        }
	
	if (d.passwd.value != d.psswd_confirm.value) {
		alert("Your passwords do not match")
		d.passwd.value = "";
		d.psswd_confirm.value = "";
		d.passwd.focus()
		return false; }

	else {
		return true; }
}


function validFormProjectInfo(project_info,button) {
	var d = project_info;

	if ($F('contact_name') == "") {
		alert("You must enter a contact name")
		d.contact_name.focus()
		return false; }
	
	if ($F('office_location') == "") {
		alert("You must enter an office location")
		d.office_location.focus();
		return false; }
		
	if ($F('lead_broker') == "") {
		alert("You must enter an lead broker")
		d.lead_broker.focus();
		return false; }
		
	if ($F('client_name') == "") {
		alert("You must enter an client name")
		d.client_name.focus();
		return false; }
		
	if ($F('deliver_to') == "") {
		alert("You must enter an deliver to name")
		d.deliver_to.focus();
		return false; }

	if ($F('property_type') == '') {
		alert("You must select a property type")
		d.property_type.focus();
		return false; }
		
	if ($F('approx_deal_value') == '') {
		alert("You must select a approximate deal value")
		d.approx_deal_value.focus();
		return false; }
		
	if ($F('property_name') == '') {
		alert("You must enter a property name")
		d.property_name.focus();
		return false; }
		
	if ($F('property_addr1') == '') {
		alert("You must enter a property address")
		d.property_addr1.focus();
		return false; }
		
	if ($F('property_city') == '') {
		alert("You must enter a city")
		d.property_city.focus();
		return false; }
		
	if ($F('property_state') == 'Select a State') {
		alert("You must enter a state")
		d.property_state.focus();
		return false; }
	
	if ($F('property_zip') == '') {
		alert("You must enter a zip")
		d.property_zip.focus();
		return false; }
		
	if ($F('date_due') == '') {
		alert("You must enter a due date")
		d.date_due.focus();
		return false; }
		
	if ($F('project_budget') == '') {
		alert("You must enter a project budget amount")
		d.project_budget.focus();
		return false; }

	else {
		return true; }
}


function TransTotal(step1) 
{ 
  var d = document.step1;
  var total = 0; 
  for (var i=0;i<d.transaction_type.length;i++) {
  if (d.transaction_type[i].checked) {
    total++;
	}
 }
  return total; 
}

function OrderTotal(step1) 
{ 
  var d = document.step1;
  var total2 = 0; 
  for (var i=0;i<d.transaction.length;i++) {
  if (d.transaction[i].checked) {
    total2++;
	}
 }
  return total2; 
}


function validFormStep1(step1) {
	var d = step1;
	var total = TransTotal(d);
	var total2 = OrderTotal(d);

	if ($F('name') == "") {
		alert("You must enter a name")
		d.name.focus()
		return false; }
		
	if (total == 0){
		alert ("You must pick a transaction type")
		return false; }
		
	if (total2 == 0){
		alert ("You must pick an order type")
		return false; }
	
	else {
		return true; }
}

function validFormStock() {
	var total = $F('graphic_support')
	if (total == "--------"){
		alert ("You must pick let us know if you want graphic options")
		return false; }
	
	else {
		return true; }
}

function setValue(y) {
     document.step1.saveOrder.value = y;
}

function setValue2(y) {
     document.step2.saveOrder.value = y;
}

function setValue3(y) {
     document.step3.saveOrder.value = y;
}

function setValue4(y) {
     document.step4.saveOrder.value = y;
}

function setValueStock(y) {
     document.stock.saveOrder.value = y;
}

function setValueStock2(y) {
     document.order.saveOrder.value = y;
}

function setValueStock3(y) {
     document.project_info.saveOrder.value = y;
}

function formReset(){
    var x=document.forms.order
    x.reset()
}

function confirmSubmit(user){

    var agree=confirm("Are you sure you want to delete this user?");
    if (agree)
	    eval('window.location="deleteuser.php?id=' + user + '"');
    else
	    return false ;
}

function confirmSubmit2(broker){

    var agree=confirm("Are you sure you want to delete this broker?");
    if (agree)
	    eval('window.location="deletebrokers.php?id=' + broker + '"');
    else
	    return false ;
}

function confirmSubmit3(client){

    var agree=confirm("Are you sure you want to delete this client?");
    if (agree)
	    eval('window.location="deleteclients.php?id=' + client + '"');
    else
	    return false ;
}
	
