// ************************************************************************
// Function: search_app_user
// Input: stype - search type which equates to application or user
// Result: forwards user to the specified page found in the selection
// Found: side menu of navigation (search function)
// ************************************************************************

function search_app_user(stype)
{
	if (document.getElementById(stype).options[document.getElementById(stype).selectedIndex].value != -1)
        location.href = document.getElementById(stype).options[document.getElementById(stype).selectedIndex].value;
}

// ************************************************************************
// Function: remove_quote
// Input: model - model number to remove from quote
// Result: removes model from quote
// Found: quote cart
// ************************************************************************

function remove_quote(model)
{
	location.href = "index.php?req=home&sub=quote&delete="+model;
}

// ************************************************************************
// Function: update_quote
// Input: model - model number to remove from quote
// 		  box - box to get updated quantity from
// Result: increases model count for quote
// Found: quote cart
// ************************************************************************

function update_quote(model, boxvar)
{
	var box = 'totalq'+boxvar;
	var quant = document.getElementById(box).value;
	location.href = "index.php?req=home&sub=quote&update="+model+"&quantity="+quant;
}

// ************************************************************************
// Function: submit_quote
// Input: qid - quote id
// Result: takes user to collect user information
// Found: quote cart
// ************************************************************************

function submit_quote(qid)
{
	if(document.getElementById('vac1').checked == true || document.getElementById('vac2').checked == true || document.getElementById('vac3').checked == true)
	{
		if((document.getElementById('vac2').checked == true || document.getElementById('vac3').checked == true) && document.qbox.plugpattern.value != '')
		{
			var radioObj = document.qbox.plugpattern;
			var radioLength = radioObj.length;
			var plug = '';
			for(var i = 0; i < radioLength; i++) 
			{
				if(radioObj[i].checked == true)
					plug = radioObj[i].value;
			}
			if(plug == '')
			{
				alert("You indicated that you need an International Cordset but you did not select one.  Please select a cordset.");
				return false;
			}
			else
			{
				if(document.getElementById('vac2').checked == true)
					location.href = "index.php?req=home&sub=quote&processq="+qid+"&vac=2&plug="+plug;
				else if(document.getElementById('vac3').checked == true)
					location.href = "index.php?req=home&sub=quote&processq="+qid+"&vac=3&plug="+plug;
			}
		}
		else if(document.getElementById('vac1').checked == true)
			location.href = "index.php?req=home&sub=quote&processq="+qid+"&vac=1&plug=K";
		else
			location.href = "index.php?req=home&sub=quote&processq="+qid+"&vac=0";
	}
	else
		location.href = "index.php?req=home&sub=quote&processq="+qid;

}

// ************************************************************************
// Function: clear_example
// Input: boxid - object holding example text
// Result: clears example text from form object
// Found: various forms
// ************************************************************************

function clear_example(boxid)
{
	var strval = document.getElementById(boxid).value;
	if(strval.substr(0,5) == '(e.g.')
	{
		document.getElementById(boxid).value = '';
		document.getElementById(boxid).style.color = "black";
	}
}

// ************************************************************************
// Function: link_jump
// Input: none
// Result: jumps to internal link
// Found: product pages
// ************************************************************************

function link_jump()
{
	var url = location.href;
	if(strpos(url,'#') > 0)
	{
		var spliturl = url.split("#");
		location.href = "#"+spliturl[1];	
	}	
}

function strpos( haystack, needle, offset){
 
    var i = haystack.indexOf( needle, offset ); // returns -1
    return i >= 0 ? i : false;
}


// ************************************************************************
// Function: show_opts
// Input: none
// Result: shows custom options for quoting
// Found: ordering/quote page
// ************************************************************************

function show_opts()
{
	if(document.getElementById('customs').style.display == 'none')
	{
		document.getElementById('customs').style.display = '';
		document.getElementById('show_custom').value = 'Remove Customizations';
	}
	else
	{
		document.getElementById('plugs1').style.display = 'none';
		document.getElementById('plugs2').style.display = 'none';
		document.getElementById('customs').style.display = 'none';
		document.getElementById('vac1').checked = false;
		document.getElementById('vac2').checked = false;
		document.getElementById('vac3').checked = false;
		document.getElementById('show_custom').value = 'Require product to operate on 220-240 VAC or have an International Cordset? Click Here!';
	}
}





// ************************************************************************
// Function: show_plugs
// Input: none
// Result: shows plug selection
// Found: ordering/quote page
// ************************************************************************

function show_plugs(_id, _show)
{
	var plugselect = 'vac'+_id;
	var plugshow = 'plugs'+_show; 
	if(document.getElementById('vac1').checked == false && document.getElementById('vac2').checked == false && document.getElementById('vac3').checked == false)
	{
		document.getElementById('plugs1').style.display = 'none';
		document.getElementById('plugs2').style.display = 'none';
		document.getElementById('vac1').checked = false;
		document.getElementById('vac2').checked = false;
		document.getElementById('vac3').checked = false;
	}
	else
	{
		document.getElementById('plugs1').style.display = 'none';
		document.getElementById('plugs2').style.display = 'none';
		document.getElementById('vac1').checked = false;
		document.getElementById('vac2').checked = false;
		document.getElementById('vac3').checked = false;
		document.getElementById(plugselect).checked = true;	
		document.getElementById(plugshow).style.display = '';
	}
}


function pick_plug(_plug) 
{
	var plug = 'plug'+_plug;
	var radioObj = document.qbox.plugpattern;
	var radioLength = radioObj.length;
	for(var i = 0; i < radioLength; i++) 
	{
		radioObj[i].checked = false;
		if(radioObj[i].value == _plug) 
			radioObj[i].checked = true;
	}
}