var displayImg;



function init(){

// HIDE ALL DROPDOWNS

	$('#industry_flash').hide();
	$('#education').hide();
	$('#food').hide();
	$('#government').hide();
	$('#health').hide();
	$('#franchising').hide();
	$('#mining').hide();
	$('#manufacturing').hide();
	$('#construction').hide();
	$('#wholesale').hide();
	$('#retail').hide();
	$('#hospitality').hide();
	$('#transport').hide();
//	$('#communication').hide();
	$('#property').hide();
	$('#business_services').hide();
	$('#personal_services').hide();

}

function initSelection(form) {
	form.education_select.value = "";
	form.food_select.value = "";
	form.gov_select.value = "";
	form.health_select.value = "";
	form.franchise_select.value = "";

	form.mining_select.value = "";
	form.manufacturing_select.value = "";
	form.construction_select.value = "";
	form.wholesale_select.value = "";
	form.retail_select.value = "";
	form.hospitality_select.value = "";

	form.transport_select.value = "";
//	form.communication_select.value = "";
	form.property_select.value = "";
	form.busserv_select.value = "";
	form.perrsserv_select.value = "";
}

function makeChangeOld(form) {
	init();
	var industrySelection = getSelectedOptionValue(form.industry);
	initSelection(form);
	var altText = "";
	displayImg = passImage(industrySelection);
	var optCounter = form.industry.length;

	if (displayImg[1].length > 0) {
			var imgPath = '<img src="/vgnmedia/images/Business_Solutions/' + displayImg[0] + ' " alt="' + displayImg[1] + '"/>';
	} else {
		imgPath = "";
		form.industryLink.value = displayImg[2];
	}

	switch (industrySelection) {
	case "Agribusiness": 
//		location.href = displayImg[0];
		$('#industry_flash').show();
		break;
	case "Education": 
	$('#education').show();
		break;
	case "Religious": 
//		location.href = displayImg[0];
		$('#industry_flash').show();
		break;
	case "Food":
		$('#industry_flash').show();
	//	$('#food').show();
		break;
	case "Government":
	$('#government').show();
		break;
	case "Health":
		//$('#health').show();
		$('#industry_flash').show();
		break;
	case "Franchising":
	$('#franchising').show();
		break;
	case "Planning":
	$('#industry_flash').show();
		break;
	case "Mining":
		$('#industry_flash').show();
	$('#mining').show();
		break;
	case "Manufacturing":
		$('#industry_flash').show();
	$('#manufacturing').show();
		break;
	case "Construction":
		$('#industry_flash').show();
//	$('#construction').show();
		break;
	case "Wholesale":
		$('#industry_flash').show();
	$('#wholesale').show();
		break;
	case "Retail":
		$('#industry_flash').show();
	$('#retail').show();
		break;
	case "Hospitality":
		$('#industry_flash').show();
	$('#hospitality').show();
		break;
	case "Transport":
		$('#industry_flash').show();
	$('#transport').show();
		break;
	case "Communication":
	$('#communication').show();
		break;
	case "Property":
//		$('#industry_flash').show();
	$('#property').show();
		break;
	case "Business":
		$('#industry_flash').show();
	$('#business_services').show();
		break;
	case "Personal":
		$('#industry_flash').show();
//	$('#personal_services').show();
		break;
	case "Insolvency":
		$('#industry_flash').show();
//	$('#personal_services').show();
		break;
	case "Management Rights":
		$('#industry_flash').show();
//	$('#personal_services').show();
		break;
	case "":
	$('#industry_flash').show();
		break;
	}

//	if (imgPath.length > 79) 
	if (displayImg[2].length <= 0) {
		$("#master_placeholder").empty().append(imgPath);
	} else {
		imgPath = "";
		$("#master_placeholder").empty().append(imgPath);
	}
}

function makeChange(form, indust) {
	init();
	initSelection(form);
	
	if ( indust == undefined || !indust || indust.length == 0 ) {
		indust = getSelectedOptionValue(form.industry);
	}
	
	displayImg = passImage(indust);
	
	var imgPath;
	
	if (displayImg[0].length > 0 && displayImg[1].length > 0) {
		imgPath = '<img src="/vgnmedia/images/Business_Solutions/' + displayImg[0] + ' " alt="' + displayImg[1] + '"/>';
	} else {
		imgPath = "";
	}
	
	form.industryLink.value = displayImg[2];

	switch (indust) {
	case "Agribusiness": 
//		location.href = displayImg[0];
		$('#industry_flash').show();
		break;
	case "Education": 
	$('#education').show();
		break;
	case "Religious": 
//		location.href = displayImg[0];
		$('#industry_flash').show();
		break;
	case "Food":
		$('#industry_flash').show();
	//	$('#food').show();
		break;
	case "Government":
	$('#government').show();
		break;
	case "Health":
		//$('#health').show();
		$('#industry_flash').show();
		break;
	case "Franchising":
	$('#franchising').show();
		break;
	case "Planning":
	$('#industry_flash').show();
		break;
	case "Mining":
		$('#industry_flash').show();
	$('#mining').show();
		break;
	case "Manufacturing":
		$('#industry_flash').show();
	$('#manufacturing').show();
		break;
	case "Construction":
		$('#industry_flash').show();
//	$('#construction').show();
		break;
	case "Wholesale":
		$('#industry_flash').show();
	$('#wholesale').show();
		break;
	case "Retail":
		$('#industry_flash').show();
	$('#retail').show();
		break;
	case "Hospitality":
		$('#industry_flash').show();
	$('#hospitality').show();
		break;
	case "Transport":
		$('#industry_flash').show();
	$('#transport').show();
		break;
	case "Communication":
	$('#communication').show();
		break;
	case "Property":
		$('#industry_flash').show();
	$('#property').show();
		break;
	case "Business":
		$('#industry_flash').show();
	$('#business_services').show();
		break;
	case "Personal":
		$('#industry_flash').show();
//	$('#personal_services').show();
		break;
	case "Insolvency": 
//		location.href = displayImg[0];
		$('#industry_flash').show();
		break;
	case "Management Rights":
		$('#industry_flash').show();
//	$('#personal_services').show();
		break;
	case "":
		$('#industry_flash').show();
		break;
	}

	//if (displayImg[2].length <= 0) {
	if (imgPath.length > 0) {
		$("#master_placeholder").empty().append(imgPath);
		$('#industry_flash').hide();
		$("#master_placeholder").show();
	} else {
		$('#industry_flash').show();
		$("#master_placeholder").hide();
	}
}

function checkForm(form) {
	var errorMsg = "";
	var linkto = "";
	var education_select_min = 0;
	var gov_select_min = 0;
	var health_select_min = 0;
	var franchise_select_min = 0;
	var mining_select_min = 0;
	var manufacturing_select_min = 0;
	var wholesale_select_min = 0;
	var retail_select_min = 0;
	var hospitality_select_min = 0;
	var property_select_min = 0;
	var business_select_min = 0;
	var transport_select_min = 0;

	var industryIndex = form.industry.selectedIndex;
	setLastLoginCookieValue2(industryIndex);

	errorMsg += isFieldValid(getSelectedOptionValue(form.industry),"Industry",0,38,"alphaNum");
	switch (getSelectedOptionValue(form.industry))
	{
	case "Education":
		education_select_min = 1;
		break;
	case "Mining":
		mining_select_min = 1;
		break;
	case "Manufacturing":
		manufacturing_select_min = 1;
		break;
	case "Government":
		gov_select_min = 1;
		break;
	case "Wholesale":
		wholesale_select_min = 1;
		break;
	case "Health":
		health_select_min = 1;
		break;
	case "Franchise":
		franchise_select_min = 1;
		break;
	case "Retail":
		retail_select_min = 1;
		break;
	case "Hospitality":
		hospitality_select_min = 1;
		break;
	case "Transport":
		transport_select_min = 1;
		break;
	case "Property":
		property_select_min = 1;
		break;
	case "Business":
		business_select_min = 1;
		break;

	}
	
	errorMsg += isFieldValid(getSelectedOptionValue(form.education_select),"Your category",education_select_min,100,"alphaNum");
//	errorMsg += isFieldValid(getSelectedOptionValue(form.food_select),"Turnover, size or type",0,100,"alphaNum");
	errorMsg += isFieldValid(getSelectedOptionValue(form.gov_select),"Your category",gov_select_min,100,"alphaNum");
	//errorMsg += isFieldValid(getSelectedOptionValue(form.health_select),"Your category",health_select_min,100,"alphaNum");
	errorMsg += isFieldValid(getSelectedOptionValue(form.franchise_select),"Your category",franchise_select_min,100,"alphaNum");
	errorMsg += isFieldValid(getSelectedOptionValue(form.mining_select),"Turnover, size or type",mining_select_min,100,"alphaNum");
	errorMsg += isFieldValid(getSelectedOptionValue(form.manufacturing_select),"Turnover, size or type",manufacturing_select_min,100,"alphaNum");
//	errorMsg += isFieldValid(getSelectedOptionValue(form.construction_select),"Turnover, size or type",0,100,"alphaNum");
	errorMsg += isFieldValid(getSelectedOptionValue(form.wholesale_select),"Turnover, size or type",wholesale_select_min,100,"alphaNum");
	errorMsg += isFieldValid(getSelectedOptionValue(form.retail_select),"Turnover, size or type",retail_select_min,100,"alphaNum");
	errorMsg += isFieldValid(getSelectedOptionValue(form.hospitality_select),"Turnover, size or type",hospitality_select_min,100,"alphaNum");
	errorMsg += isFieldValid(getSelectedOptionValue(form.transport_select),"Turnover, size or type",transport_select_min,100,"alphaNum");
//	errorMsg += isFieldValid(getSelectedOptionValue(form.communication_select),"Turnover, size or type",0,100,"alphaNum");
	errorMsg += isFieldValid(getSelectedOptionValue(form.property_select),"Turnover, size or type",property_select_min,100,"alphaNum");
	errorMsg += isFieldValid(getSelectedOptionValue(form.busserv_select),"Turnover, size or type",business_select_min,100,"alphaNum");
//	errorMsg += isFieldValid(getSelectedOptionValue(form.perrsserv_select),"Turnover, size or type",0,100,"alphaNum");

	linkto = getSelectedOptionValue(form.education_select) + getSelectedOptionValue(form.food_select) + getSelectedOptionValue(form.gov_select) + getSelectedOptionValue(form.health_select) + getSelectedOptionValue(form.franchise_select) + getSelectedOptionValue(form.mining_select)  + getSelectedOptionValue(form.manufacturing_select) + getSelectedOptionValue(form.construction_select) + getSelectedOptionValue(form.wholesale_select) + getSelectedOptionValue(form.retail_select) + getSelectedOptionValue(form.hospitality_select) + getSelectedOptionValue(form.transport_select) + getSelectedOptionValue(form.property_select) + getSelectedOptionValue(form.busserv_select) + getSelectedOptionValue(form.perrsserv_select);
	// + getSelectedOptionValue(form.communication_select)

	if (linkto.length <= 0) {
		linkto = form.industryLink.value;
	}

	return [errorMsg, linkto];
}

function submitForm(form) {
	var errorMsg = checkForm(form);
	var displayErrorMsg = errorMsg[0];
	var industryLink = errorMsg[1];
	var reEnterMsg = " <p>Please click the 'Close' button and complete the missing fields.</p>";

	if (isEmpty(errorMsg[0])) {
		form.submit();   
		window.location = industryLink;
	} else {
		popup = window.open("","industry_win","width=400,height=400,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1");
		popup.document.write("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'><html><head>");
		popup.document.write("<link rel='stylesheet' href='/css/National/GlobalStyle.css' type='text/css'></head>");
		popup.document.write("<title>Industry Selector</title>");
		popup.document.write("<body>");
		popup.document.write("<strong>Industry Selector</strong><br><br>");
		popup.document.write(displayErrorMsg);
		popup.document.write("<br>");
		popup.document.write(reEnterMsg);
		popup.document.write("<center><form><input type=button value=Close onClick=javascript:window.close();></center></form>");
		popup.document.write("</body>");
		popup.document.write("</html>");
		popup.document.close();
	}
}


