/*
	Created By: 	Matt Bergstein
	Date:			9/23/11
	Description:	used by global search in top banner to clear field on focus, search on enter press (during focus), and submit on button click.
	
	Example:		<td valign="middle" align="left"><input class="search_txt_box" style="margin-left:5px; width:143px; height:17px; border: 1px solid #4dc8e9;" type="text" 
					id="search" name="search" onfocus="return clearInstructions();" onKeyDown="return checkForEnterPress();" value=" Enter Keyword or Model #" /><span 
					style="position:relative; top:3px; left:2px;"><img src="../images/search_btn.gif" alt="search_btn" border="0" onclick="javascript:doSearch();" /></span></td>
*/

function doSearch()
{
	var searchTerm = document.getElementById("headerSearch").value;

	if (searchTerm != null)
	{
	    callManualCMClick(cmPageName,'Global%20Header','Global%20Search');
	    var searchUrl = meridianDomain + "pna-global/search/?q=" + searchTerm;
		window.location = searchUrl;
		return false;
	}
	else
	{
		return true;
	}
}

function doConsumerSupportSearch()
{
	var searchTerm = document.getElementById("consumerSupportSearch").value;

	if (searchTerm != null)
	{
	    callManualCMClick(cmPageName,'Global%20Header','Consumer%20Support%20Search');
	    var searchUrl = meridianDomain + "search/?support=consumer&q=" + searchTerm;
		window.location = searchUrl;
		return false;
	}
	else
	{
		return true;
	}
}

function doSearchOnTerm(searchTerm)
{
	//var searchUrl = "http://www2.panasonic.com/webapp/wcs/stores/servlet/PNAEndecaEnterpriseSearchCmd?N=779832187&Ne=&Ns=&Nr=12001&No=0&Ntt=" + searchTerm + "&Ntk=EnterpriseSearch&URL=vEnterpriseSearch&catalogId=13401&storeId=15001";
	callManualCMClick(cmPageName,'Global%20Header','Global%20Search');
	var searchUrl = meridianDomain + "pna-global/search/?q=" + searchTerm;
	window.location = searchUrl;
}

//doSearchOnConsumerSupportTerm
function doSearchOnConsumerSupportTerm(searchTerm)
{
	callManualCMClick(cmPageName,'Global%20Header','Consumer%20Support%20Search');
	var searchUrl = meridianDomain + "search/?support=consumer&q=" + searchTerm;
	window.location = searchUrl;
}

//Used for the top banner search box. When the enter key is pressed while you are focused on the search box this function call the dosearchterm fucntion above.
//Here is an example of how to call this function: onkeydown="return checkForEnterPress(event);"
function checkForEnterPress(e)
{
    if(window.event)
    {
        //ie
	    if (event.which || event.keyCode)
	    {
		    if ((event.which == 13) || (event.keyCode == 13))
		    {
			    var searchTerm = document.getElementById("headerSearch").value;
    	        
    	        if (searchTerm == null)
			    {
				    searchTerm = document.aspnetForm.search.value;
			    }
			    if (searchTerm != null)
			    {
				    if(searchTerm != null)
				    {
					    doSearchOnTerm(searchTerm);
				    }
				    return false;
			    }
			    else
			    {
				    return true;	
			    }
		    }
	    }
	    else 
	    {
		    return true;	
	    }
    }
    else 
    {
        //firefox
        if (e.which || e.keyCode)
	    {	    
		    if ((e.which == 13) || (e.keyCode == 13))
		    {
		        //alert('enter');
		    
			    var searchTerm = document.getElementById("headerSearch").value;
    	        
    	        if (searchTerm == null)
			    {
				    searchTerm = document.aspnetForm.search.value;
			    }
			    if (searchTerm != null)
			    {
				    if(searchTerm != null)
				    {
				        //alert(searchTerm);
					    doSearchOnTerm(searchTerm);
				    }
				    return false;
			    }
			    else
			    {
				    return true;	
			    }
		    }
	    }
	    else 
	    {
		    return true;	
	    }
    }
}

function checkForEnterPressConsumerSupport(e)
{
    if(window.event)
    {
        //ie
	    if (event.which || event.keyCode)
	    {
		    if ((event.which == 13) || (event.keyCode == 13))
		    {
			    var searchTerm = document.getElementById("consumerSupportSearch").value;
    	        
    	        if (searchTerm == null)
			    {
				    searchTerm = document.aspnetForm.search.value;
			    }
			    if (searchTerm != null)
			    {
				    if(searchTerm != null)
				    {
					    doSearchOnConsumerSupportTerm(searchTerm);
				    }
				    return false;
			    }
			    else
			    {
				    return true;	
			    }
		    }
	    }
	    else 
	    {
		    return true;	
	    }
    }
    else 
    {
        //firefox
        if (e.which || e.keyCode)
	    {	    
		    if ((e.which == 13) || (e.keyCode == 13))
		    {    
			    var searchTerm = document.getElementById("consumerSupportSearch").value;
    	        
    	        if (searchTerm == null)
			    {
				    searchTerm = document.aspnetForm.search.value;
			    }
			    if (searchTerm != null)
			    {
				    if(searchTerm != null)
				    {
					    doSearchOnConsumerSupportTerm(searchTerm);
				    }
				    return false;
			    }
			    else
			    {
				    return true;	
			    }
		    }
	    }
	    else 
	    {
		    return true;	
	    }
    }
}

//On focus, clear the search box
function clearInstructions()
{
    //alert('hi');

	if ((document.getElementById("headerSearch").value == ' Enter Keyword or Model #') || (document.getElementById("search").value == 'Enter Keyword or Model #'))
	{
		document.getElementById("headerSearch").value = '';
	}
}

function addInstructions()
{
    if (document.getElementById("headerSearch").value == '')
    {
        document.getElementById("headerSearch").value = 'Enter Keyword or Model #';
    }
}

// Search Boxes
// http://kneedeepincode.com/topics/making-a-dynamic-jquery-search-box/


$(function(){ //Document ready shorthand
    var $searchSupport = $('#consumerSupportSearch');//Cache the element for faster DOM searching since we are using it more than once
    original_supportVal = $searchSupport.val(); //Get the original value to test against. We use .val() to grab value="Search"
    $searchSupport.focus(function(){ //When the user tabs/clicks the search box.
        if($(this).val()===original_supportVal){ //If the value is still the default, in this case, "Search"
	        $(this).val('');//If it is, set it to blank
        }
    })
    .blur(function(){//When the user tabs/clicks out of the input
        if($(this).val()===''){//If the value is blank (such as the user clicking in it and clicking out)...
	        $(this).val(original_supportVal); //... set back to the original value
        }
    });
});


    
$(function(){ //Document ready shorthand
    var wrapper = document.getElementById('searchGlobalWrapper'); //used for border
    var $search = $('#headerSearch');//Cache the element for faster DOM searching since we are using it more than once
    original_val = $search.val(); //Get the original value to test against. We use .val() to grab value="Search"
    $search.focus(function(){ //When the user tabs/clicks the search box.
        wrapper.style.border = "1px solid #fff";
        if($(this).val()===original_val){ //If the value is still the default, in this case, "Search"
	        $(this).val('');//If it is, set it to blank
        }
    })
    .blur(function(){//When the user tabs/clicks out of the input
        wrapper.style.border = "0";
        if($(this).val()===''){//If the value is blank (such as the user clicking in it and clicking out)...
	        $(this).val(original_val); //... set back to the original value
        }
    });
});


