
// ************************************************************
// Author : Narendra Yalavarthi
// Date : 05/06/2010
//*************************************************************
// populate dropdowns from XMl files.
var dropdownValues;
//initialize the xml objects.
function init(){
	$.ajax({
		type: "GET",
		url: "/ftpc/EOCSAJaxServlet?callType=1&salesOrg=1100",
		dataType: "xml",
		error: displayError,
		success: parseXML
	});

}

function parseXML(xml){
	//prompt('xml',xml.XML);
	dropdownValues = $(xml).find('prescription brand[brand_code=AVC] power-list power');
	populatePowerList('drop-list1', 'AVC', 'd', 'sph');
	
}

function displayError(xml){
	alert("error"+xml);
}

//Sph power
//idname = id of the dropdown to be populated
//errorId = div id of error
// product id 
function populatePowerList(idname, productId, divId, inputName){
	$(dropdownValues).each(function() {
	        var item = $(this).text();
	        var oNewNode = document.createElement("LI");
		document.getElementById(idname).appendChild(oNewNode);
		$(oNewNode).html("<a href=javascript:toggle('"+divId+"');clearMsg();changeValue("+item+",'"+inputName+"')>"+item+"</a>");
	       
	});
	
}


/***********************************************************************************
// validate prescription parameters.
// p_value 	= selected prescription value from dropdown.
************************************************************************************/
function validate(p_value){
	var result = false;
	$.ajax({
		type: "GET",
		url: "/ftpc/EOCSAJaxServlet?callType=2&salesOrg=1100&brandCode=AVC&power="+p_value,
		dataType: "xml",
		error: displayError,
		success: function(xml) {
		    result = $(xml).find('VALID').text();
		    if(result == 'true'){
		    	displayYesMessage();
		    }else{
		    	displayNoMessage();
		}
		}

	});
}


/**
* Clear the prescription error / success message when user makes a new selection.
*/
function clearMsg(){
	document.getElementById("prescription-validation").className = "prescription-validation";
}
