var bigstring = " "

function doesexist(inputValue, inputExpected, defaultValue) {
  var aCharExists=0
  if (inputValue != defaultValue){
	  if (inputValue) {
	    for (var i=0; i<inputValue.length; i++) {
	      if (inputValue.charAt(i) != " ") {
	        aCharExists = 1
	      }
	    }
	  }
  }
  if (!aCharExists) {
    bigstring = bigstring += inputExpected += "\n ";
  }
}
function doesexistradio(inputValue, inputExpected, size) {
	sum=0;
	for(i=0; i<size; i++)
		if (inputValue[i].checked == true)
			sum++;
	if (!sum) {
		bigstring = bigstring += inputExpected += "\n ";
		return false
  	}
  	return true
  	
}

function checkem() {
	var where_to= confirm("Are you sure you want to submit your application?");
	if (where_to== false)
	{
		return false
	}
	
  
  
  
  
   
  if (bigstring != " "){
    alert("Please complete the following fields: \n" + bigstring)
    bigstring = " "
    return false
  }
  return true
}

function reset_first_to_null(a){
	if(a.value == "First Name"){
		a.value = "";
	}
}
function reset_middle_to_null(a){
	if(a.value == "Middle"){
		a.value = "";
	}
}
function reset_last_to_null(a){
	if(a.value == "Last Name"){
		a.value = "";
	}
}

function media_track_company_change_type(the_field) {
	var l        = location.href;
	var lpos     = l.indexOf('?');
	var box_name = the_field.name;
	
	if (lpos > 0) {
	    l = l.substring(0, lpos);
	} // end if
	
	location.href = l + "?" + box_name + '=' + escape(the_field.value);
}

function media_track_company_change_region(the_field) {
	var l        = location.href;
	var lpos     = l.indexOf('&region');
	var box_name = the_field.name;
	
	if (lpos > 0) {
	    l = l.substring(0, lpos);
	} // end if
	
	location.href = l + "&" + box_name + '=' + escape(the_field.value);
}

function media_track_company_change_city(the_field) {
	var l        = location.href;
	var lpos     = l.indexOf('&city');
	var box_name = the_field.name;
	
	if (lpos > 0) {
	    l = l.substring(0, lpos);
	} // end if
	
	location.href = l + "&" + box_name + '=' + escape(the_field.value);
}

function validateReference(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');     

   if (fld.value == "") {
        error = "You didn't enter how you heard about us.\n";
        fld.style.background = 'Yellow';
    }
    return error;
}


function validateFormOnSubmit(theForm) {
var reason = "";

  reason += validateReference(theForm.reference);
  
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  if (sign) {
	signature.value=sign.signature();
	PR.value=sign.PR();
	PG.value=sign.PG();
	PB.value=sign.PB();
	BR.value=sign.BR();
	BG.value=sign.BG();
	BB.value=sign.BB();

	width.value=sign.imagewidth();
	height.value=sign.imageheight(); 
  }
  alert("Thank you. We now have your application!");
  
  return true;
}
