/*
* This script is meant to be called upon loading a page.
* The onLoad section of the Body tag calls the populateTestData() function
* This function will only work when certain query string variables are
* turned on and thus does not pose a danger to the end customer.
*/


/* 1 means the switch is on, 0 means off. 
* These switches are turned on from the Query String by setting the variables:
* populatetestdata=1
* and debugswitch=1
*/

var debugSwitch = 0; 
var testSwitch = 0; 

function populateTestData()
{


	testSwitch = getQueryVariable("populatetestdata");
	debugSwitch = getQueryVariable("debugswitch");


	debug('populatetestdata = ' + testSwitch);
	debug('debugSwitch = ' + debugSwitch);

	debug("Entering populateTestData() ...");


	if (testSwitch==1) 

	{
		debug("Populating fields ...");

		// Standard Address Fields

		fillTextField("FNAME","TestFirstName");
		fillTextField("LNAME","TestLastName");
		fillTextField("TITLE","TestTitle");
		fillTextField("COMPANY","TestCompany");
		fillTextField("ADDRESS1","Test Address 1");
		fillTextField("ADDRESS2","Test Address 2");
		fillTextField("CITY","TestCity");
		fillDropDownField("STATE",10);
		fillTextField("ZIPCODE","12345");
		fillRadioButtonField("COUNTRY", 0);
		fillTextField("EMAIL_ADDRESS","test@omeda.com");

		debug("Done populating the Standard Address Fields");


		// Additional Address Fields

		fillTextField("HOME_ADDRESS2","Test Home Address 2");
		fillTextField("HOME_CITY","TestHomeCity");
		fillDropDownField("HOME_STATE",10);
		fillTextField("HOME_ZIPCODE","12345");
		fillRadioButtonField("HOME_COUNTRY", 0);
	

		// BSL

		fillRadioButtonField("RECEIVE_YES_NO", 0);
		fillRadioButtonField("BANDWIDTH", 0);
		fillRadioButtonField("REQUESTED_VERSION", 0);
		fillRadioButtonField("INVOLVED", 0);
		fillCheckBoxField("PRIMARY_ROLE-01");
		fillRadioButtonField("PURCHASE", 1);
		fillRadioButtonField("JOB_TITLE", 0);
		fillDropDownField("BUSINESS", 1);
		fillCheckBoxField("LISTINGS_NEW-01");
		fillDropDownField("EMPLOYEES",1);
		fillDropDownField("REVENUE",1);

		fillRadioButtonField("ORG_INET", 1);
		fillRadioButtonField("ORG_ENTERPRISE", 1);
		fillRadioButtonField("ORG_COMP_SYS", 1);
		fillRadioButtonField("ORG_NETWORK", 1);
		fillRadioButtonField("ORG_STORAGE", 1);
		fillRadioButtonField("ORG_SECURITY", 1);
		fillRadioButtonField("ORG_CONSULTING", 1);
		fillRadioButtonField("ORG_STAFFING", 1);

		fillRadioButtonField("PERS_INET", 1);
		fillRadioButtonField("PERS_ENTERPRISE", 1);
		fillRadioButtonField("PERS_COMP_SYS", 1);
		fillRadioButtonField("PERS_NETWORK", 1);
		fillRadioButtonField("PERS_STORAGE", 1);
		fillRadioButtonField("PERS_SECURITY", 1);
		fillRadioButtonField("PERS_CONSULTING", 1);
		fillRadioButtonField("PERS_STAFFING", 1);


		fillDropDownField("IT_PROJECT", 1);
		fillRadioButtonField("EXEC_PARTNER", 1);
		fillDropDownField("PERSONAL_ID",1);
		

		// IST

		fillRadioButtonField("ORG_INT_EXT", 1);
		fillRadioButtonField("ORG_COMP_SOFT", 1);
		fillRadioButtonField("ORG_COMP_SYS", 1);
		fillRadioButtonField("ORG_NET_TEL", 1);
		fillRadioButtonField("ORG_STORAGE", 1);
		fillRadioButtonField("ORG_SECURITY", 1);
		fillRadioButtonField("ORG_CONSULT_STAFF", 1);
		fillDropDownField("BUDGET",1);
		fillCheckBoxField("IT_ENTERPRISE-01");
		fillRadioButtonField("RESPONSIBLE", 0);
		fillCheckBoxField("PURCHASE_AUTHORITY-1");
		debug("Done Populating the Custom Fields.");

		// EWK

		fillDropDownField("INDUSTRY", 5);
		fillCheckBoxField("JOB_FUNCTION-01");
		fillCheckBoxField("IT_DECISION-01");
		fillDropDownField("SOFTWARE_THIS_LOC",2);
		fillDropDownField("SOFTWARE_OTHR_LOC",2);
		fillDropDownField("SECURITY_THIS_LOC",2);
		fillDropDownField("SECURITY_OTHR_LOC",2);
		fillDropDownField("STORAGE_THIS_LOC",2);
		fillDropDownField("STORAGE_OTHR_LOC",2);
		fillDropDownField("NETWORKING_THIS_LOC",2);
		fillDropDownField("NETWORKING_OTHR_LOC",2);
		fillDropDownField("LARGE_SYS_THIS_LOC",2);
		fillDropDownField("LARGE_SYS_OTHR_LOC",2);
		fillDropDownField("INTERNET_THIS_LOC",2);
		fillDropDownField("INTERNET_OTHR_LOC",2);
		fillDropDownField("OUTSOURCE_THIS_LOC",2);
		fillDropDownField("OUTSOURCE_OTHR_LOC",2);
		fillDropDownField("WIRELESS_THIS_LOC",2);
		fillDropDownField("WIRELESS_OTHR_LOC",2);
		fillDropDownField("DESKTOPS_THIS_LOC",2);
		fillDropDownField("DESKTOPS_OTHR_LOC",2);
		fillDropDownField("PERIPHERAL_THIS_LOC",2);
		fillDropDownField("PERIPHERAL_OTHR_LOC",2);

		fillCheckBoxField("SOFTWARE_SPECIFY-01");
		fillCheckBoxField("SOFTWARE_SPEC_OUTSRC-35");
		fillCheckBoxField("SOFTWARE_SPECIFY-05");
		fillCheckBoxField("SOFTWARE_SPEC_OUTSRC-42");
		fillCheckBoxField("SOFTWARE_SPECIFY-09");
		fillCheckBoxField("SOFTWARE_SPEC_OUTSRC-45");
		fillCheckBoxField("SOFTWARE_SPECIFY-12");
		fillCheckBoxField("SOFTWARE_SPEC_OUTSRC-55");
		fillCheckBoxField("SOFTWARE_SPECIFY-20");
		fillCheckBoxField("SOFTWARE_SPEC_OUTSRC-65");

		fillCheckBoxField("PRODUCTS_SPECIFY-01");
		fillCheckBoxField("PRODUCTS_SPECIFY-03");
		fillCheckBoxField("PRODUCTS_SPECIFY-05");
		fillCheckBoxField("PRODUCTS_SPECIFY-06");
		fillCheckBoxField("PRODUCTS_SPECIFY-08");
		fillCheckBoxField("PRODUCTS_SPECIFY-11");
		fillCheckBoxField("PRODUCTS_SPECIFY-23");
		fillCheckBoxField("PRODUCTS_SPECIFY-25");
		fillCheckBoxField("PRODUCTS_SPECIFY-26");
		fillCheckBoxField("PRODUCTS_SPECIFY-28");

		fillCheckBoxField("ENTERPRISE_SOFTWARE-01");
		fillCheckBoxField("ENTERPRISE_SOFTWARE-03");
		fillCheckBoxField("ENTERPRISE_SOFTWARE-04");
		fillCheckBoxField("ENTERPRISE_SOFTWARE-07");
		fillCheckBoxField("ENTERPRISE_SOFTWARE-09");
		fillCheckBoxField("ENTERPRISE_SOFTWARE-20");
		fillCheckBoxField("ENTERPRISE_SOFTWARE-24");

		fillCheckBoxField("PRODUCTS_IN_USE-01");

		fillCheckBoxField("ENEWSLETTERS-01");
		fillCheckBoxField("ENEWSLETTERS-02");
		fillCheckBoxField("ENEWSLETTERS-03");
		fillCheckBoxField("ENEWSLETTERS-05");
		fillCheckBoxField("ENEWSLETTERS-06");
		fillCheckBoxField("ENEWSLETTERS-09");
		fillCheckBoxField("ENEWS_TEXT_FORMAT");
		fillCheckBoxField("EMAIL_PROMOTE");
		fillCheckBoxField("ESEMINARS");
		fillTextField("LASTEMAIL","lastemail@omeda.com");
		fillTextField("PERSONAL_ID_DESC","Test Desc of Personal ID");
		fillTextField("PNM01_FNAME","TestPNMFNAME");
		fillTextField("PNM01_LNAME","TestPNMLNAME");
		fillTextField("PNM01_TITLE","TestPNMTITLE");





	}

	debug("Exiting populateTestData() ...");

}


/**
* The getQueryVariable Function simply gets variables from the query string.
* In this script the two query string variables of interest are "populatetestdata"
* and "debugswitch"
*/

function getQueryVariable(variable) {
 	var query = window.location.search.substring(1);
	var vars = query.split("%26");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	} 
	debug('Query Variable ' + variable + ' not found');
}


/**
* This function checks to see whether the field element exists or not
*/

function element_exists(element_name) {
	if(document.getElementsByName(element_name).length > 0) {
		return true;
	} else {
		return false;
	}
}


/**
* This is a convenience function for filling in a text field value
* 1) element_name: Name of the Text Field to be filled
* 2) field_value: The value to fill the text field
*/

function fillTextField(element_name, field_value) {
	if (element_exists(element_name)) {
		document.getElementsByName(element_name)[0].value=field_value;
	}
}

/**
* This is a convenience function for selecting a drop down list field value
* 1) element_name: Name of the List Field to be filled
* 2) index_value: The index value to be selected, note that this is zero indexed
*/

function fillDropDownField(element_name, index_value) {
	if (element_exists(element_name)) {
		document.getElementsByName(element_name)[0].selectedIndex=index_value;
	}	
}

/**
* This is a convenience function for selecting a Radio Button field value
* 1) element_name: Name of the Radio Button to be filled
* 2) index_value: The index value to be selected
*/

function fillRadioButtonField(element_name, index_value) {
	if (element_exists(element_name)) {
		document.getElementsByName(element_name)[index_value].checked=true;
	}
}

/**
* This is a convenience function for selecting a Radio Button field value
* 1) element_name: Name of the check box to be filled
*/

function fillCheckBoxField(element_name) {
	if (element_exists(element_name)) {
		document.getElementsByName(element_name)[0].checked=true;
	}
}

/**
* This is a convenience function for debugging
* When the debugswitch is equal to 1, alert messages show up
*/

function debug(msg_string) {
	if (debugSwitch==1) {
		alert(msg_string);
	}
}