var ON_FLAG = "On";
var OFF_FLAG = "Off";
var preferencesWindow;

function submitPreferences(var1,prodId,userGroupName,msg){
	 var finalURL="&prodId="+prodId+"&userGroupName="+userGroupName+"&type="+var1;

	 if(var1=="ApplyPreferences") {

	    if(selectedFlagRadio() == ON_FLAG ){
			finalURL = construtURLWithHighLightOptions(finalURL);
		}
		var SearchTermHighLightFlagValue = selectedFlagRadio();
		finalURL += "&" + SearchTermHighLightFlagString +"=" +SearchTermHighLightFlagValue;

		if(document.prefsForm.UIPresentation[0].checked){
    		finalURL+="&UIPresentation="+document.prefsForm.UIPresentation[0].value;
		}
		else if(document.prefsForm.UIPresentation[1].checked){
			finalURL+="&UIPresentation="+document.prefsForm.UIPresentation[1].value;
		}
	
		finalURL += "&SearchResultsPerPage="+document.forms[0].SearchResultsPerPage.value;	
		if (null != document.forms[0].FULLTEXT_LIMIT) {
			if(document.forms[0].FULLTEXT_LIMIT.checked) {
				finalURL += "&FULLTEXT_LIMIT=y";
			} else {
				finalURL += "&FULLTEXT_LIMIT=n";
			}
		}

		if (null != document.forms[0].REFREED_LIMIT) {
			if(document.forms[0].REFREED_LIMIT.checked) {
				finalURL += "&REFREED_LIMIT=y";
			} else {
				finalURL += "&REFREED_LIMIT=n";
			}	
		}
		
		finalURL += "&Language="+document.forms[0].Language.value;					
	 }
	 this.location.href = basicPreferenceURL+finalURL;
	 alert(msg);
}

function construtURLWithHighLightOptions(finalURL){
	var formObj = document.forms[0];
	
	var SearchTermHighLightColorValue = formObj.SearchTermHighLightColor.value;
	var SearchTermHighLightStyleValue = formObj.SearchTermHighLightStyle.value;
	
	finalURL += "&" + SearchTermHighLightColorString +"=" +SearchTermHighLightColorValue;
	finalURL += "&" + SearchTermHighLightStyleString +"=" +SearchTermHighLightStyleValue;
	
	return finalURL;
}

function selectedFlagRadio(){
	var formObj = document.forms[0];
	var flagRadioObj = formObj.sthilite;
	for(i=0;i<flagRadioObj.length;i++){
		if(flagRadioObj[i].checked==true)
 			return flagRadioObj[i].value;
	}
}

function enableOrDisableSearchHilite() {
    if(selectedFlagRadio() == ON_FLAG ) {
	    enableSearchHilite();
	}
	else  {
	    disableSearchHilite(true);
	}
	    

	  // reload the parent window to apply preferences.
	  // commented out for now because of HTTP Request and other issues
	  /*
	if (-1 == window.location.href.indexOf("type=ShowPreferences")  ) {
		var sURL = unescape(window.opener.location.href);
	  window.opener.location.href = sURL;
	  window.close();
  }	    
	  */
}

function disableSearchHilite(hilite){
	if(hilite){
		document.forms[0].SearchTermHighLightStyle.disabled=true;
		document.forms[0].SearchTermHighLightColor.disabled = true;
	}
}

function enableSearchHilite(){
	document.forms[0].SearchTermHighLightStyle.disabled=false;
	document.forms[0].SearchTermHighLightColor.disabled = false;
}

function openPreferences(url){
    window.open(url,'galeChildWindow',"toolbar=no, directories=no, status=no, location=no, resizable=yes, menubar=no, scrollbars=yes,screenX=50,screenY=50,top=50,left=50,width=750,height=550");
}
 