// This array is used to hold the various actions of the form
// Each value much correspond to the proper selected index
var formActionArray = new Array();
formActionArray[0] = '';
formActionArray[1] = 'https://secure.marketwire.com/mw/customer_login2';
formActionArray[2] = 'https://eservices.ccnmatthews.com/news/nre.UniqueLogon?action=Login&application=nre&fromLL=no&fx_type=login&url=index.html';
formActionArray[3] = 'https://secure.ccnmatthews.co.uk/ccnmatthewsuk.Login?action=login&fromLL=no&fromCir=no&application=nre&fx_type=login&url=index.xml';
formActionArray[4] = 'https://secure.marketwire.com/mw/customer_login2';

// This array is used to hold the various user name field variables

var userNameFieldArray = new Array();
userNameFieldArray[0] = '';
userNameFieldArray[1] = 'loginName';
userNameFieldArray[2] = 'Logon';
userNameFieldArray[3] = 'Logon';
userNameFieldArray[4] = 'loginName';

// This array is used to hold the various password field variables

var passwordFieldArray = new Array();
passwordFieldArray[0] = '';
passwordFieldArray[1] = 'password';
passwordFieldArray[2] = 'Password';
passwordFieldArray[3] = 'Password';
passwordFieldArray[4] = 'password';

var forgotPwArray = new Array();
forgotPwArray[0] = '';
forgotPwArray[1] = 'https://secure.marketwire.com/mw/password_forgot';
forgotPwArray[2] = 'http://www.ccnmatthews.com/news/forgot_password.jsp?message=nothing';
forgotPwArray[3] = 'http://www.ccnmatthews.com/news/forgot_password.jsp?message=nothing';
forgotPwArray[4] = 'https://secure.marketwire.com/mw/password_forgot';

var createActArray = new Array();
//createActArray[0] = '';
//createActArray[1] = 'https://secure.marketwire.com/mw/create_account_init';
//createActArray[2] = 'http://www.marketwire.com/docs/Commercial_Account_Application_June_2007.pdf';
//createActArray[3] = 'http://www.marketwire.com/docs/Commercial_Account_Application_June_2007.pdf';
//createActArray[4] = 'https://secure.marketwire.com/mw/create_account_init';
createActArray[0] = '';
createActArray[1] = 'https://secure.marketwire.com/mw/create_account_init_sf';
createActArray[2] = 'https://secure.marketwire.com/mw/create_account_init_sf';
createActArray[3] = 'https://secure.marketwire.com/mw/create_account_init_sf';
createActArray[4] = 'https://secure.marketwire.com/mw/create_account_init_sf';




function actSelectFxn() {
  
  
  
  var form = document.getElementById('loginForm');
  var select = document.getElementById('actTypeSelect');
  var forgotPw = document.getElementById('forgotPw');
  var createAct = document.getElementById('createAct');
  

  
  var index = 0;
  
  
  if(select) {
  	
  	index = select.selectedIndex;
  	
	  // since each login script takes different variable names for user and pass
	  // we need to access the objects by id, and then set their names appropriately.
	  
	  var userName = document.getElementById('userName');
	  if(userName) {
	  	userName.name = userNameFieldArray[index];
	  }
  
	  var password = document.getElementById('password');
	  if(password) {
	  	password.name = passwordFieldArray[index];
	  }    	
  	
  	
  	form.action = formActionArray[index];
  	forgotPw.href = forgotPwArray[index];
  	createAct.href = createActArray[index];
  	
  }  
  
}

function validateLoginForm(type)
{
 
	var form = document.getElementById('loginForm');
	var select = document.getElementById('actTypeSelect');
	
	if(form) {
	     
	     
	
		if(form.action==null || form.action=='') {
		
			
			if(select.selectedIndex > 0)
			{
			    

				form.action = formActionArray[select.selectedIndex];
				forgotPw.href = forgotPwArray[select.selectedIndex];
  				createAct.href = createActArray[select.selectedIndex];
  				
				  var userName = document.getElementById('userName');
				  if(userName) {
				  	userName.name = userNameFieldArray[select.selectedIndex];
				  }
			  
				  var password = document.getElementById('password');
				  if(password) {
				  	password.name = passwordFieldArray[select.selectedIndex];
				  }  				
  				
			}
			else
			{
		
				alert('Please Select an Account Type.');		
				return false;
			}
		}	
	}
	
	if(type == 'form') {
	

		var userName = document.getElementById('userName');
		if(userName) {
		   if(userName.name != '') {
		   		if(userName.value ==null|| userName.value=="") {
		   			alert('Please Supply a Login Id.');
		   			return false;
		   		}	   		
		   }
			else {
				alert('Please Select an Account Type.');		
				return false;
			}		   
		}
	  
		var password = document.getElementById('password');
		if(password) {
		   if(password != '') {
		   		if(password.value==null|| password.value=='') {
		   			alert('Please Supply a Password.');
		   			return false;
		   		}
		   		
		   }
			else {
				alert('Please Select an Account Type.');		
				return false;
			}		   
		}   
	
	}
	
	return true; 	
	
}