/*****************************************************************
*                                                                *
*   Feedback Functions                                           *
*                                                                *
*****************************************************************/

var strSubjects = new Array()
strSubjects[0] = '';
strSubjects[1] = new Array('Parts Pricing','Machine Pricing','Service Pricing')
strSubjects[2] = new Array('New Equipment Information','Used Equipment Information','Rental Equipment Information')
strSubjects[3] = new Array('Human Resources','Investors Inquiries')
strSubjects[4] = new Array('General Inquiry','Web Site Feedback','Web Site Problem')
strSubjects[5] = new Array('Other')

function PopulateForm(form) {
    var i = form.category.selectedIndex;

    //remove current subjects
    for(j=form.subject.options.length;j>=0;j--){
        form.subject.options[j]=null;
    }

    //init new subjects
    for(j=0;j<strSubjects[i].length+1;j++){
        form.subject.options[j] = new Option();
    }
    
    //fill drop down with array values
    form.subject.options[0].text = '-- Select a Subject --';
    for(t=0;t<strSubjects[i].length;t++){
        form.subject.options[t+1].text = strSubjects[i][t];
        
    }
    form.subject.options[0].selected=true;
}

function ContactFormOK(form){
    var ok = true;

    //check for subject
    var strSelSubject = form.subject.options[form.subject.selectedIndex].text;
    if(ok && (strSelSubject.substring(0,2) == '--' || strSelSubject == '')){
        alert('Please select a subject.');
        ok = false;
    }
    
    //check for name
    if(ok && form.fullname.value == ''){
        alert('Please tell us your name.')
        ok = false;
    }
    
    //check for email
    var newString = form.email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
    if(ok && !newString){
        alert('Invalid e-mail address!')
        ok = false;
    }
    
    //check for phone
    if(ok && form.chkPhone.checked && form.phone.value == ''){
        alert('You didn\'t enter a phone number.');
        ok = false;
    }
    
    //check for comments
    if(ok && form.comments.value == ''){
        alert('Please enter your question or comment.');
        ok = false;
    }
    
    if(!ok)return false;
}


/*****************************************************************
*                                                                *
*   Survey functions                                             *
*                                                                *
*****************************************************************/



/*****************************************************************
*                                                                *
*   Branch list functions                                        *
*                                                                *
*****************************************************************/

//create arrays for ab, bc, nt and yt	
city = new Array()
city[0] = new Array()
city[1] = new Array()
city[2] = new Array()
city[3] = new Array()

function buildArrays(){
  //build arrays from anchors
  var strProvince
  var intProvinceIdx = -1
  var intCityIdx

  for(i=0;i<document.anchors.length;i++){
    if(document.anchors[i].name!=''){
      strNextProvince = document.anchors[i].name.split('|')[0]
      if(strProvince != strNextProvince){
        intProvinceIdx++;
        strProvince = strNextProvince;
        intCityIdx = 0;
      }
      city[intProvinceIdx][intCityIdx] = document.anchors[i].name;
      intCityIdx++;
    }
  }
}

//update city list
function showCities(form){
  buildArrays();

	//deterine which province radio was clicked
	var i = 0
	while (!form.province[i].checked){i++}

	//populate list from array
	//remove current cities
	for(j=form.citylist.options.length;j>=0;j--){
	    form.citylist.options[j] = null;
	}

	//init new cities
	for(j=0;j<city[i].length+1;j++){
	    form.citylist.options[j] = new Option();
	}
    
	//fill list with array values
	for(t=0;t<city[i].length;t++){
	    form.citylist.options[t].value = city[i][t];
	    form.citylist.options[t].text = city[i][t].split('|')[1].replace('_',' ');
		    
	}
	form.citylist.options[t].text = '                                ';
}
	
//jump to specified city
function jumpTo(form) {
	location='#' + form.citylist.options[form.citylist.selectedIndex].value;
}



/*****************************************************************
*                                                                *
*   Used Equipment Functions                                     *
*                                                                *
*****************************************************************/

//printer friendly window
function openPrint(location){
	window.open(location, 'PrintFriendly', 'width=620,height=500,toolbar=yes,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes, resizable=yes');
}
