var qna_submitOK       = true;
var inquiraMaxPartSearchLength = 40;
var inquiraMaxTextSearchLength = 135;
var inquiraPossibleText = ["Enter search words or describe product features","Enter a complete or partial part number..."];

function TE_SetSearchType(searchTypeId){
	var CurrentText = dojo.byId("question_box").value;

	if (searchTypeId == "inquiraTypePart"){
		if (CurrentText == inquiraPossibleText[0] || CurrentText.length < 1){
			dojo.byId("question_box").value = inquiraPossibleText[1];
		}
		dojo.byId("search_type").value = "Part";
		dojo.byId("inquiraTypePart").checked = true;
		dojo.byId("inquiraTypeText").checked = false;
	} else if (searchTypeId == "inquiraTypeText"){
		if (CurrentText == inquiraPossibleText[1] || CurrentText.length < 1){
			dojo.byId("question_box").value = inquiraPossibleText[0];
		}
		dojo.byId("search_type").value = "Text";
		dojo.byId("inquiraTypeText").checked = true;
		dojo.byId("inquiraTypePart").checked = false;			
	}
	dojo.byId("question_box").focus();
}

function handleFocus_QuestionBox()
{
	var CurrentText = dojo.byId("question_box").value;
	
    for (i = 0; i < inquiraPossibleText.length; i++) {
        if ( CurrentText.indexOf(inquiraPossibleText[i]) > -1 )	{
			dojo.byId("question_box").select();
			break;
        }
    }

    return true;
}

function TE_ShowTips() {
	if (dojo.byId("TE_searchTipsDiv").style.display =="none"){
		dojo.byId("TE_searchTipsDivIframe").src ="/_TEincludes/TEsearch/tips.html"
		dojo.html.setStyle("TE_searchTipsDiv","left",dojo.html.getAbsolutePosition("TE_outerDiv").x+406)
		dojo.html.setStyle("TE_searchTipsDiv","height",dojo.html.getMarginBox("TE_outerDiv").height-115)
		dojo.html.setStyle("TE_searchTipsDivIframe","height",dojo.html.getMarginBox("TE_outerDiv").height-165)
		dojo.html.show("TE_searchTipsDiv");
		
	}else{
		dojo.html.hide("TE_searchTipsDiv");	
		dojo.byId("question_box").focus();
	}
	return false;
}

function search_inquira_submitQuestion()
{   
    if (!isSubmitOK()) {
        return false;
    }
    
    // Prevent another quick submit and submit this question
    disableSubmit();    
    dojo.byId("inquiraSearchForm").submit();

    
    // Wait 10 seconds before submit available
    setTimeout("enableSubmit();", 10000);

    return false;
}

function isSubmitOK()
{
    if (!qna_submitOK)
        return false;
      
	var qboxValue = dojo.byId("question_box").value.replace(/^\s+/g,'').replace(/\s+$/g,'');
    dojo.byId("question_box").value = qboxValue;
    
	if ( qboxValue == inquiraPossibleText[0] || qboxValue == inquiraPossibleText[1]){
		dojo.byId("question_box").value = "";
	    dojo.byId("question_box").focus();
		return false;
	}
	if ( qboxValue.length < 1 ){
		dojo.html.setStyle("TE_blankSearchErrorDiv","left",dojo.style.getAbsoluteX("TE_outerDiv")+545);
		dojo.html.show("TE_blankSearchErrorDiv");
		dojo.byId("TE_blankSearchErrorDivButton").focus();
		return false;
	}
	if (dojo.byId("inquiraTypePart").checked && qboxValue.length > inquiraMaxPartSearchLength){
			dojo.html.setStyle("TE_searchErrorDiv","left",dojo.style.getAbsoluteX("TE_outerDiv")+545);
			dojo.byId("TE_searchErrorDiv").style.display = "inline";
    		return false;
    }else if (qboxValue.length > inquiraMaxTextSearchLength){// this not run as the input is set to max 135
            dojo.byId("question_box").value = qboxValue.substring(0,inquiraMaxTextSearchLength);
            alert('Questions are limited to 135 characters or less.');
            return false;
    } 

    return true;
}

/**
  * Disable the submit feature.
  */
function disableSubmit()
{
    qna_submitOK = false;
    dojo.byId("TE_searchButton").disabled = true;
}

/**
  * Enable the submit feature.
  */
function enableSubmit()
{
    qna_submitOK = true;
    dojo.byId("TE_searchButton").disabled = false;
}

function inquiraTruncatePartNumber(length) 
  {
  var qbox = dojo.byId("question_box")	
    qbox.value = qbox.value.substring(0,length);
	dojo.byId("question_box").focus();
	dojo.html.hide("TE_searchErrorDiv");
  }
	
/*tip box*/	
document.write('<div id="TE_searchTipsDiv" style="display:none;">')
document.write('	<h3 style="padding:2px;"><input type="button" onClick="TE_ShowTips()" class="TE_darkSmallButton"value="X" style="float:right;margin:0;padding:0;font-size:0.6em;" />Search Tips</h3>')
document.write('	<iframe id="TE_searchTipsDivIframe" src="/_TEincludes/TEsearch/tipsBlank.html""></iframe>')
document.write('	<input type="button" onClick="TE_ShowTips()" class="TE_darkButton"value="Close" />')
document.write('	</div>')

/*part length error*/
document.write('	<div id="TE_searchErrorDiv" style="display:none;">')
document.write('		<p>Tyco Electronics Part Numbers are limited to '+inquiraMaxPartSearchLength+' characters. If you wish to <b>search by Part Number</b>, please click the ')
document.write('		Part Search button below.  Be sure to enter just the part number (or a portion of the part number if the full part number is unknown.)</p>')
document.write('		<p>If you intended to <b>search by text or product attributes</b>, please')
document.write('		click the Text Search button below to switch to Text search.')
document.write('		<p>')
document.write('		<div>')
document.write('			<input type=BUTTON value="Part Search" name="partSearchButton" class="TE_darkSmallButton"onClick="inquiraTruncatePartNumber(inquiraMaxPartSearchLength);">')
document.write('   <input type=BUTTON value="Text Search" name="textSearchButton" class="TE_darkSmallButton" onClick=\'TE_SetSearchType("inquiraTypeText");dojo.html.hide("TE_searchErrorDiv");\'>')
document.write('			<input type="button" onClick="dojo.html.hide(\'TE_searchErrorDiv\')" class="TE_darkSmallButton"value="Close" />')
document.write('		</div>')
document.write('	</div>')

/*Blank search error box*/
document.write('	<div id="TE_blankSearchErrorDiv" style="display:none;">')
document.write('		<p>Please enter your search text first.</p>')
document.write('<div>			<input type="button" id="TE_blankSearchErrorDivButton"onClick=\'dojo.html.hide("TE_blankSearchErrorDiv");dojo.byId("question_box").focus();\' class="TE_darkSmallButton"value="Close" />')
document.write('</div>	</div>')



