/******************************************************************************
 Copyright (c) 2007 Samsung Electronics. All Rights Reserved.
 Project: Samsung.com Site Renewal(2007.01~07)

 File Name : paramsearch.js
 Description : parametric search JavaScript
 Author : À¯Àç¸í
 Since : 2007.04.05
 
 Modification Information
 Mod Date Modifier Description
 ---------- -------- ---------------------------
 2007.04.05 À¯Àç¸í   ÃÖÃÊ »ý¼º
 2009.06.11 Á¤±ÔÈ¯   search error ¼öÁ¤
******************************************************************************/
var vCtrl_subFamily;
var flag;
var initFlag;

var category_selectBox = new Ui.SelectBox();
for(i=1; i<=vCol_length; i++){
	var vColNum = "col_" + i;	
	category_selectBox.add(vColNum);
}

/************************************************************
dwr¿¡ ³Ñ¾î°¡´Â °ªÀº ¹è¿­·Î ³Ñ±â´Â °æ¿ì¸¦ À§ÇÑ ÂüÁ¶¿ë ÇÔ¼ö
************************************************************/
function test(fmly_id){
		var zzz = new Array("1","2","3","4","5","6","7","8","9","10");
		ParamSelectBoxDWR.getParamSelectBoxValueList( zzz, aaa );
}

/** ********************************************************** **/

//DWR selected result
function paramselectNext(site_cd, fmly_id, valueselectobj, selectedPrd_id, selectedId, selectedValue){
  
	if(valueselectobj.value != "All"){
		var valueselect = valueselectobj.value;
		var isvariousvalue = "n";
		var valueselectname = valueselectobj.name.split("_");
		
    vparamlist[valueselectname[1]-1] = valueselect;		
		
		if(valueselect.substring(0,1) == ","){
		  isvariousvalue ="y";
		  valuselect = valueselect.substr(1);
		}

    var originValues = valueselectobj.value;
    var originId = valueselectobj.id;
    var originParent = document.getElementById(originId);
    var originIdNum = valueselectobj.id.split("_")[1];
    var originInput = document.createElement("input");
    originInput.type = 'hidden';
    originInput.id = 'originValue_'+originIdNum;    
    originInput.className = originValues;
    
    originParent.appendChild(originInput);
    
    initFlag = 'N'
    
		ParamSelectBoxDWR.getSelecteoptionList(site_cd, fmly_id, valueselect, isvariousvalue, selectedPrd_id, callbackOptionList);
		ParamSelectBoxDWR.getSelectedPrdId(site_cd, fmly_id, valueselect, isvariousvalue, selectedPrd_id, callbackPrdIdList);    

	} else {
	  
	  if ((fmly_id == '223') && (selectedId == 'col_3') && (selectedValue == 'All')){
	    /*
      initFlag = 'Y'
      flag = 'Y';
	    valueselect = "";
	    selectedPrd_id.length = 0;

      for (var xFI = 0; xFI < vparamlist.length; xFI++) {
   				vparamlist.splice(xFI, 1);
      }
      
      disableSel(flag);
      
  		ParamSelectBoxDWR.getSelecteoptionList(site_cd, fmly_id, valueselect, isvariousvalue, selectedPrd_id, callbackOptionList);
  		*/
  		location.href = "/global/business/semiconductor/paramSearch.do?fmly_id=223";
  		
  		
	  } else {	  
      var originId = valueselectobj.id.split("_")[1];
      var vCtrlOriginValue = document.getElementById("originValue_"+originId).className;
      
      for (var xFI = 0; xFI < vparamlist.length; xFI++) {
        optobj = document.getElementById("col_" + (xFI+1) ).options;
        for(var j = 0; j < optobj.length; j++){
    			if (vparamlist[xFI] == vCtrlOriginValue) {
    					vparamlist.splice(xFI, 1);  				
    			}
  			}
  		}
		}
	}
}
/*
function disableSel(flag) {
  var arraySelect = document.body.getElementsByTagName("select");
  for(var xFI=0; xFI < arraySelect.length; xFI++) {
    if (flag == 'Y') {
      arraySelect[xFI].disabled = 'disabled';
      arraySelect[xFI].style.backgroundColor = "#e5e5e5";
    } else {
      arraySelect[xFI].disabled = '';
      arraySelect[xFI].style.backgroundColor = "fff";
    }
  }
}
*/

function callbackOptionList(data){

	var j = 1;
	var out_name = data[0].spec_out_name;

	document.getElementById("col_" + (1)).length = 0;

  try {
  			var newOption = document.createElement('option');
        newOption.value = 'All'; 
        newOption.text = 'All'; 
        document.getElementById("col_" + (1)).add(newOption,null);
			} catch (e) {
   			var newOption = document.createElement('option'); 
        newOption.value = 'All'; 
        newOption.text = 'All'; 
        document.getElementById("col_" + (1)).add(newOption);
			}
			
	for(var i = 0; i < data.length ; i++){
		if(out_name != data[i].spec_out_name){		  
			out_name = data[i].spec_out_name;
 			j++;

			if (out_name != document.getElementById("col2_"+ (j)).innerHTML){
        // var delRow = document.getElementById("col3_" + (j));
        // delRow.style.display = "none";			  
        var allRow = document.getElementById("col_" + (j));
        allRow.length = 1;
        allRow.disabled = 'disabled';
        allRow.style.backgroundColor = "#e5e5e5";            
           
			  while(1){
         	if (data[i].spec_out_name != document.getElementById("col2_"+ (j)).innerHTML){
            // var delRow = document.getElementById("col3_" + (j));   			    
            // delRow.style.display = "none";
            var allRow = document.getElementById("col_" + (j));
            allRow.length = 1;
            allRow.disabled = 'disabled';
            allRow.style.backgroundColor = "#e5e5e5";            
            j++;
     		  } else {
   		      break;  
       		}
			  }
      }
      
			document.getElementById("col_" + (j)).length = 0;
			
		try {
  			var newOption = document.createElement('option'); 
        newOption.value = 'All'; 
        newOption.text = 'All';         
        document.getElementById("col_" + (j)).add(newOption,null); 
			} catch (e) {
   			var newOption = document.createElement('option'); 
        newOption.value = 'All'; 
        newOption.text = 'All';
        document.getElementById("col_" + (j)).add(newOption);
			}
		}

		try {
				if(data[i].prd_spec_val.substring(0,1) == ","){
					document.getElementById("col_" + (j)).add(new Option(data[i].prd_spec_val.substr(1),data[i].prd_spec_val),null);
				}else{
					document.getElementById("col_" + (j)).add(new Option(data[i].prd_spec_val,data[i].prd_spec_val),null);
				}
			
		} catch (e) {
			if(data[i].prd_spec_val.substring(0,1) == ","){
				document.getElementById("col_" + (j)).add(new Option(data[i].prd_spec_val.substr(1),data[i].prd_spec_val));
			}else{
				document.getElementById("col_" + (j)).add(new Option(data[i].prd_spec_val,data[i].prd_spec_val));
			}
		}
	}

	selecedvaluedisplay(vparamlist);
	
	/*
  flag = 'N';
  if (initFlag == 'Y') { 
    disableSel(flag);
  }
  */
}

function callbackPrdIdList(data){
	selectedPrd_id = data;	
}

function selecedvaluedisplay(vparamlist){
	for(var i = 0; i < vparamlist.length ; i++){
		optobj = document.getElementById("col_" + (i+1) ).options;
		for(var j = 0; j < optobj.length; j++){
			if(optobj[j].value == vparamlist[i]){
				optobj[j].selected = true;
			} else if(','+optobj[j].value == vparamlist[i]) {
 				optobj[j].selected = true;
			}
		}
	}
}

// 1st select
function selectclass(site_cd, fmly_id){
		if(fmly_id ==""){
		clearselectbox("classifiactionselect");
		optGroup = document.createElement("optgroup");
		optGroup.label = "--------------------------------------------------";

		objOption=document.createElement("option");
		objOption.innerHTML = "classification";
		objOption.value = "";

		document.getElementById("classifiactionselect").appendChild(objOption);
		document.getElementById("classifiactionselect").appendChild(optGroup);

		}else{
			ParamSelectBoxDWR.getParamClassificationValueList(site_cd, fmly_id, callbackParamfirstSelectbox);
		}
}

function callbackParamfirstSelectbox(data){
	clearselectbox("classifiactionselect");

		optGroup = document.createElement("optgroup");
		optGroup.label = "--------------------------------------------------";

		objOption=document.createElement("option");
		objOption.innerHTML = "classification";
		objOption.value = "";

		document.getElementById("classifiactionselect").appendChild(objOption);
		document.getElementById("classifiactionselect").appendChild(optGroup);

	if(data.length == 1){
		if(data[0].fmly_name == ""){
      objOption = document.createElement("option");
			objOption.innerHTML = data[0].upper_fmly_name;
			objOption.value = data[0].fmly_id; 
			document.getElementById("classifiactionselect").appendChild(objOption);
			
			// 2009.06.08[jkh] FIRE FOX µ¿ÀÛÀÎ½Ä ºÒ°¡·Î Query ¼öÁ¤À¸·Î ÀÎÇØ ÁÖ¼®Ã³¸®
			// objOption.innerHTML = document.getElementById("productselect").options[document.getElementById("productselect").selectedIndex].name;
			// objOption.value = document.getElementById("productselect").value;

		}else{
			objOption=document.createElement("option");
			objOption.innerHTML = data[0].fmly_name;
			objOption.value = data[0].fmly_id;

			document.getElementById("classifiactionselect").appendChild(objOption);
		}
	}else{
		for(var i = 0; i< data.length ; i++){

			objOption=document.createElement("option");
			objOption.innerHTML = data[i].fmly_name;
			objOption.value = data[i].fmly_id;

			document.getElementById("classifiactionselect").appendChild(objOption);
		}
	}

	document.getElementById("classifiactionselect").focus();

	clearselectbox("parameterselect");

	objOption=document.createElement("option");
	objOption.innerHTML = "parameter";
	objOption.value = "";
	document.getElementById("parameterselect").appendChild(objOption);

	clearselectbox("valueselect");
	objOption=document.createElement("option");
	objOption.innerHTML = "value";
	objOption.value = "";

	document.getElementById("valueselect").appendChild(objOption);
}

// 2nd select

function selectparameter(site_cd, fmly_id){
	ParamSelectBoxDWR.getParamParameterList(site_cd, fmly_id, callbackParamsecondSelectbox);
}

function callbackParamsecondSelectbox(data){
	clearselectbox("parameterselect");

	optGroup = document.createElement("optgroup");
	optGroup.label = "--------------------------------------------------";

	objOption=document.createElement("option");
	objOption.innerHTML = "parameter";
	objOption.value = "";

	document.getElementById("parameterselect").appendChild(objOption);
	document.getElementById("parameterselect").appendChild(optGroup);

	for(var i = 0; i< data.length ; i++){
		objOption=document.createElement("option");
		objOption.innerHTML = data[i].spec_out_name;
		objOption.value = data[i].spec_id;

		document.getElementById("parameterselect").appendChild(objOption);
	}

	document.getElementById("parameterselect").focus();
	clearselectbox("valueselect");

	objOption=document.createElement("option");
	objOption.innerHTML = "value";
	objOption.value = "";

	document.getElementById("valueselect").appendChild(objOption);
}


// 3rd select
function selectvalue(site_cd, prd_spec_id){
	ParamSelectBoxDWR.getParamValueList(site_cd, document.getElementById("classifiactionselect").value, prd_spec_id, callbackParamthirdSelectbox);
}

function callbackParamthirdSelectbox(data){
	clearselectbox("valueselect");

	optGroup = document.createElement("optgroup");
	optGroup.label = "--------------------------------------------------";

	objOption=document.createElement("option");
	objOption.innerHTML = "value";
	objOption.value = "";

	document.getElementById("valueselect").appendChild(objOption);
	document.getElementById("valueselect").appendChild(optGroup);
	
	for(var i = 0; i< data.length ; i++){


		if(data[i].prd_spec_val.substring(0,1) == ","){

			objOption=document.createElement("option");
			objOption.innerHTML = data[i].prd_spec_val.substr(1);
			objOption.value = data[i].prd_spec_val;

			document.getElementById("valueselect").appendChild(objOption);
		}else{

			objOption=document.createElement("option");
			objOption.innerHTML = data[i].prd_spec_val;
			objOption.value = data[i].prd_spec_val;

			document.getElementById("valueselect").appendChild(objOption);

		}
	}
	document.getElementById("valueselect").focus();
}


function clearselectbox(objid){
	for(i = document.getElementById(objid).childNodes.length-1; i >=0; i--){
		document.getElementById(objid).removeChild(document.getElementById(objid).childNodes[i]);
	}
}

function selectedcomplite(){
	document.mainparamsearch.submit();
}



function replaceAll(str, searchStr, replaceStr){
	while(str.indexOf(searchStr) != -1){
		str = str.replace(searchStr, replaceStr);
	}

	return str;
}

function refresh(fmly_id,productselect,parameterselect,valueselect){
	var form = document.Form1;
	form.action = "/global/business/semiconductor/paramSearch.do?productselect="+ productselect + "&fmly_id=" + fmly_id + "&parameterselect=" + parameterselect + "&valueselect=" + valueselect;
	form.submit();
}

//*****************************************************************************
// DWR Test
//
//
//*****************************************************************************

function dwrtest(fmly_id){
	
	ParamSelectBoxDWR.getParamSelectBoxValueList(fmly_id);
}

//*****************************************************************************
// Description : ¼±ÅÃÇÑ Source Parametric Search ÀÇ µ¿Àû SelectBox List Á¶È¸   
// Parameter: ¾øÀ½ 
// Return: ¾øÀ½ 
// Usage: onclick="javascript:paramNextSelectbox();"
//*****************************************************************************
function paramNextSelectbox(vFmlyId, vColNum, vNum) {
	var vNextColNum 	= "col_"+vNum;
	var vSpecId 		= "to_"+vNum;
	var vCtrl_srcFamily = document.getElementById(vColNum);
	var vSpecIdValue 	= document.getElementById(vSpecId);
	var vSelectedValue 	= vCtrl_srcFamily.value;
	var vNextSpecId		= vSpecIdValue.value;
		
	vCtrl_subFamily 	= document.getElementById(vNextColNum);
	
    // ÇöÀçselectBox¼³Á¤ & ÇÏÀ§ selectBox ÃÊ±âÈ­
    category_selectBox.setCurrnet(vCtrl_srcFamily.id);
    category_selectBox.clearBoxLowThis(vCtrl_srcFamily.id, "");	
		

	ParamSelectBoxDWR.getParamSelectBoxList(vFmlyId, vSelectedValue, vNextSpecId, vSite_cd, callbackParamNextSelectbox);

}

 
//*****************************************************************************
// Description : callbackParamNextSelectbox Ã³¸®    
// Parameter: ¾øÀ½ 
// Return: ¾øÀ½ 
// Usage: ¾øÀ½ 
//*****************************************************************************
function callbackParamNextSelectbox(data) {
	vCtrl_subFamily; 
	var vTempOption;
	vCtrl_subFamily.length = 0;

	if(data.length == 0) {
		vTempOption = new Option("All", "All");
		try {
			vCtrl_subFamily.add(vTempOption, null);	
		} catch (e) {
			vCtrl_subFamily.add(vTempOption);
		}
	} else {
		vTempOption = new Option("All", "All");
		try {
			vCtrl_subFamily.add(vTempOption, null);	
		} catch (e) {
			vCtrl_subFamily.add(vTempOption);
		}
		for(var xFI = 0; xFI < data.length; xFI++) {
			vTempOption = new Option(data[xFI].prd_spec_val, data[xFI].prd_spec_val);
			try {
				vCtrl_subFamily.add(vTempOption, null);	
			} catch (e) {
				vCtrl_subFamily.add(vTempOption);
			}
		}		
	}
	vCtrl_subFamily;
}


//*****************************************************************************
// Description : parameteric List
// Parameter: 
// Return: ¾øÀ½
// Usage: onClick="javascript:param_searchList();"
//*****************************************************************************
function param_searchList(vFmly_id) {
	var frmObj = document.Form1;	
	var sheetYn = frmObj.sheet_yn.value;
	frmObj.action = "/global/business/semiconductor/paramSearchList.do?fmly_id="+ vFmly_id + "&sheet_yn="+ sheetYn;

	for(xFI=1; xFI <= frmObj.dummys.length; xFI++){ 
	  var encodeValues = encodeURI(eval("frmObj.col_"+xFI+".value"));
      document.getElementById('selected_'+xFI).value = encodeValues;
  }	
	frmObj.submit();
}



//*****************************************************************************
// Description : flex»ç¿ëÆÁ ÆäÀÌÁö open
// Parameter: ¾øÀ½
// Return: ¾øÀ½
// È£ÃâÆäÀÌÁö : productlist.jsp
//*****************************************************************************
function flextip_open() {
	var vUrl = "http://www.samsung.com/global/business/semiconductor/productsearch/ProductListTable_Tip.html";
	openWindow(765,	635, vUrl, 1); 
}


function close_layer() {
	var cvr = document.getElementById("semi_layer_transparency");
	var dlg = document.getElementById("semi_pro_flex_layer");

	cvr.style.display = "none";
	dlg.style.display = "none";
}

function pop_layer() {
	var cvr = document.getElementById("semi_layer_transparency");
	var dlg = document.getElementById("semi_pro_flex_layer");
	var business = document.getElementById("business");
	var contents = document.getElementById("semi_pro_layer_content");
	var bgimg1 = document.getElementById("bgimg1");
	var bgimg2 = document.getElementById("bgimg2");
	var addHeight = getFooterHeight(document.getElementById("footer"));

//	cvr.style.top = 0+'px';
//	cvr.style.left = 0+'px';
//	cvr.style.width = document.body.offsetWidth+'px';
	var height = document.body.offsetHeight+addHeight;
	if(height < screen.availHeight){
		height = screen.availHeight;
	}
	if (cvr != null && dlg != null){
		cvr.style.height = height+'px';
		business.appendChild(cvr);
		cvr.style.display = "block";

		business.appendChild(dlg);
		dlg.style.display = "block";

		bgimg1.style.display = "block";
		contents.style.display = "block";
		bgimg2.style.display = "block";
	}

}

function getFooterHeight(footer){
	var footerChilds = footer.childNodes;
	var foot_height = 0;
	for(i=0;i<footerChilds.length;i++){
		if(footerChilds[i].className == 'foot_logo'){
			foot_height = footerChilds[i].offsetHeight;
			break;
		}
	}
	return foot_height;
}