/*
#############################################################
#															#
#		functions.js - Javascript Functions Container		#
#															#
#############################################################*/
/* <![CDATA[ */
function IncreaseQuantity(item_id)
{
	var current_quantity = document.getElementById('item_quantity'+item_id).value;
	current_quantity = parseInt(current_quantity);
	current_quantity++;
	if(current_quantity < 1000)
	{
		document.getElementById('item_quantity'+item_id).value = current_quantity;
	}
	else
	{
		alert("Sorry, You Cannot Place This Large Of An Order.");	
	}
	return false;
}
function DecreaseQuantity(item_id)
{
	var current_quantity = document.getElementById('item_quantity'+item_id).value;
	current_quantity = parseInt(current_quantity);
	current_quantity--;
	if((current_quantity >= 1 && item_id == '') || (current_quantity >= 0 && item_id != ''))
	{
		document.getElementById('item_quantity'+item_id).value = current_quantity;
	}	return false;
}
function CheckCard()
{
	if(document.getElementById('card[card_type]').selectedIndex > 0)
	{
		var cc_num	= document.getElementById('card[ccnum]').value;
		var cc_type	= document.getElementById('card[card_type]').options[document.getElementById('card[card_type]').selectedIndex].value;
		if(!checkCreditCard(cc_num,cc_type))
		{
			alert(ccErrors[ccErrorNo]);
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		alert('Please Select A Credit Card Type.');
		return false;
	}
}
function ShowLeadRepBox()
{
	document.getElementById('lr_display1').style.display = 'block';
	document.getElementById('lr_display2').style.display = 'block';
	document.getElementById('lr_display3').style.display = 'none';
	document.getElementById('lr_display4').style.display = 'none';
}
function HideLeadRepBox()
{
	document.getElementById('lr_display1').style.display = 'none';
	document.getElementById('lr_display2').style.display = 'none';
}
function ShowSupervisorBox()
{
	document.getElementById('lr_display1').style.display = 'none';
	document.getElementById('lr_display2').style.display = 'none';
	document.getElementById('lr_display3').style.display = 'block';
	document.getElementById('lr_display4').style.display = 'block';
}
function HideLeadsBox()
{
	document.getElementById('lr_display1').style.display = 'none';
	document.getElementById('lr_display2').style.display = 'none';
	document.getElementById('lr_display3').style.display = 'none';
	document.getElementById('lr_display4').style.display = 'none';
}
function ToggleDetails(ChangeDisp,section)
{
	var details = document.getElementById('details'+ChangeDisp+section);
	var detail_o = document.getElementById('detail_override'+ChangeDisp+section);
	if(details.style.display == 'none')
	{
		details.style.display = 'block';
		detail_o.innerHTML = '<a href="javascript:void(0);" onclick="ToggleDetails('+ChangeDisp+','+section+');">-</a>';
	}
	else if(details.style.display == 'block')
	{
		details.style.display = 'none';	
		detail_o.innerHTML = '<a href="javascript:void(0);" onclick="ToggleDetails('+ChangeDisp+','+section+');">+</a>';
	}
	else
	{
		details.style.display = 'block';	
		detail_o.innerHTML = '<a href="javascript:void(0);" onclick="ToggleDetails('+ChangeDisp+','+section+');">-</a>';
	}
}
function ProccessCheckboxes(object,order,section)
{
	var i = 0;
	while(i < 100)
	{
		if(document.getElementById('detail_select'+order+'_'+i+'_'+section))
		{
			if(object.checked)
			{
				document.getElementById('detail_select'+order+'_'+i+'_'+section).checked = true;
			}
			else
			{
				document.getElementById('detail_select'+order+'_'+i+'_'+section).checked = false;
			}
		}
		i++;
	}
}
function ExecuteSearch()
{
	var abs_cont = 0;
	if(abs_cont == 1)
	{
		var theUrl			= './m_index.php?p=search';
		var update_content	= $('content');
		var AjaxReq = new Request({url: theUrl,
									update:	update_content,
									method: 'post',
									autoCancel: true,
									onRequest: function(){
										$('content').innerHTML = "Searching";
									}
									}).send($('SearchForm'));
		//return false;
	}
	else
	{
		return true;	
	}
}
function open_win(url,width,height)
{
	if(width  == undefined){ width  = 300; }
	if(height == undefined){ height = 300; }
	day = new Date();
	id = day.getTime();
	return eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height+",left = 250,top = 250');");
	return "page"+id;
}
var win;
function OpenWrite(url,barcode_url,name){
	if(win){ win.close(); }
	day = new Date();
	id = day.getTime();
	win = window.open("","win"+id,"location=0,status=0,scrollbars=0,width=400,height=155");
	var winW = 200, winH = 300;

	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = (((window.innerWidth-16)/2)-200);
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = (((document.body.offsetWidth-20)/2)-200);
		}
	}
	win.moveTo(winW,winH);
	win.document.write("<table id=\"data\" style=\"border:1px solid #CCCCCC;\">"+(name != 'undefined' ? "<tr><td align=\"center\">"+name+"</td></tr>" : "")+"<tr><td align=\"center\"><img src=\""+barcode_url+"\"></td></tr></table>");
	tbls = win.document.getElementById("data");
	win.focus();
}
function positionInfo(object) {

	var p_elm = object;
	
	this.getElementLeft = getElementLeft;
	function getElementLeft() 
	{
		var x = 0;
		var elm;
		if(typeof(p_elm) == "object")
		{
			elm = p_elm;
		} 
		else 
		{
			elm = document.getElementById(p_elm);
		}
		while (elm != null) {
			x+= elm.offsetLeft;
			elm = elm.offsetParent;
		}
		return parseInt(x);
	}
	
	this.getElementWidth = getElementWidth;
	function getElementWidth()
	{
		var elm;
		if(typeof(p_elm) == "object")
		{
			elm = p_elm;
		} else {
			elm = document.getElementById(p_elm);
		}
		return parseInt(elm.offsetWidth);
	}
	
	this.getElementRight = getElementRight;
	function getElementRight()
	{
		return getElementLeft(p_elm) + getElementWidth(p_elm);
	}
	
	this.getElementTop = getElementTop;
	function getElementTop()
	{
		var y = 0;
		var elm;
		if(typeof(p_elm) == "object")
		{
			elm = p_elm;
		}
		else 
		{
			elm = document.getElementById(p_elm);
		}
		while (elm != null) {
			y+= elm.offsetTop;
			elm = elm.offsetParent;
		}
		return parseInt(y);
	}
	
	this.getElementHeight = getElementHeight;
	function getElementHeight()
	{
		var elm;
		if(typeof(p_elm) == "object")
		{
			elm = p_elm;
		} 
		else 
		{
			elm = document.getElementById(p_elm);
		}
		return parseInt(elm.offsetHeight);
	}
	
	this.getElementBottom = getElementBottom;
	function getElementBottom()
	{
		return getElementTop(p_elm) + getElementHeight(p_elm);
	}
}
function SizePage()
{
	/********************************************/
	/*				Page Sizeing				*/
	/********************************************/
	var theHeight;
	var theWidth;
	if (window.innerHeight) 
	{ 
		theHeight=window.innerHeight;
		theWidth=window.innerWidth;
	} 
	else if((document.documentElement) && (document.documentElement.clientHeight))
	{ 
		theHeight=document.documentElement.clientHeight; 
		theWidth=document.documentElement.clientWidth; 
	} 
	else if(document.body) 
	{ 
		theHeight=document.body.clientHeight; 
		theWidth=document.body.clientWidth; 
	} 
	var newHeight	= (theHeight-42);
	var newWidth	= (theWidth-170);
	var myFx		= new Fx.Tween('content');
	myFx.set('width', newWidth);
	myFx.set('height', newHeight);
}
function ChangeRecurring(obj)
{
	if(obj.selectedIndex == 0) 
	{
		document.getElementById('RecurringText').style.display = 'inline'; 
		document.getElementById('RecurringDuration').style.display = 'inline'; 
		document.getElementById('RecurringDays').style.display = 'inline'; 
	} 
	else
	{ 
		document.getElementById('RecurringText').style.display = 'none';
		document.getElementById('RecurringDuration').style.display = 'none'; 
		document.getElementById('RecurringDays').style.display = 'none'; 
	}
}
function CheckRemoveAll(obj)
{
	var i = 0;
	while(i < 100)
	{
		if(obj.checked || document.getElementById('RemoveAll').checked)
		{
			if(document.getElementById('rem'+i))
			{
				document.getElementById('rem'+i).checked = true;
			}
		}
		else
		{
			if(document.getElementById('rem'+i))
			{
				document.getElementById('rem'+i).checked = false;
			}
		}
		i++;
	}
}
function SurveyQuestionTypeSwitch(obj)
{
	if(obj.selectedIndex == 1 || obj.selectedIndex == 3)
	{
		//1 & 3 Options
		$('SurveyQuestionOptionText').style.display = 'block';
		$('SurveyOptionQuestionList').style.display = 'block';
	}
	else
	{
		//0 & 2 No Options
		$('SurveyQuestionOptionText').style.display = 'none';
		$('SurveyOptionQuestionList').style.display = 'none';		
	}
}
function AddSurveyOption()
{
	var index = 0;
	var parent = document.getElementById('SurveyOptionQuestionList');
	while(true)
	{
		if(!document.getElementById('question'+index))
		{
			if(index == 0)
			{
				var br = document.createElement("br");
				parent.appendChild(br);
			}
			var input = document.createElement("input");
			input.setAttribute("name","question["+index+"]");
			input.setAttribute("id","question"+index);
			input.setAttribute("value","");
			input.setAttribute("type","text");
			parent.appendChild(input);
			if(index%2)
			{
				var br = document.createElement("br");
				parent.appendChild(br);
			}
			break;
		}
		index++;
	}
}
function OrderDateSwap(obj)
{
	if(obj.selectedIndex < 4)
	{
		document.getElementById('else_date1').style.display = 'none';
		document.getElementById('else_date2').style.display = 'none';
	}
	else
	{
		document.getElementById('else_date1').style.display = 'block';
		document.getElementById('else_date2').style.display = 'block';
	}
}
function VerifyDate(obj)
{
	var obj = document.getElementById(obj);
	if(obj.value.length > 0)
	{
		var now = new Date();
		now.setDate(now.getDate()+1);
		var s_day	= parseFloat(now.getDate());
		var s_month	= parseFloat(now.getMonth())+1;
		var s_year	= parseFloat(now.getFullYear());
		
		var min_date = Date.parse(s_month+'/'+s_day+'/'+s_year);
		var sel_date = Date.parse(obj.value);
		if(sel_date >= min_date)
		{
			return true;
		}
		else
		{
			obj.value = s_month+'/'+s_day+'/'+s_year;
			alert("You Must Specify A Date In The Future");
		}
	}
}
function CycleSwap(obj)
{
	if(obj.selectedIndex == 1)
	{
		document.getElementById('CycleSwapInfo1').style.display = 'none';
		document.getElementById('CycleSwapInfo2').style.display = 'none';
	}
	else
	{
		document.getElementById('CycleSwapInfo1').style.display = 'block';
		document.getElementById('CycleSwapInfo2').style.display = 'block';
	}
}
function AdminReportError()
{
	document.getElementById('error_data').value = document.getElementById('admin').innerHTML;
	var Ajax = new Request({url:'m_index.php?p=send_error',onComplete:function(){ alert('Error Reported'); }}).send($('ErrorReport'));
}

function AddToCart(idProduct)
{
	var Ajax = new Request.HTML({url: './?p=add_to_cart&item_id='+idProduct+'&item_quantity=1',
							onRequest: function() {
								$('encarte'+idProduct).innerHTML = 'Adding item to cart.';
							},
							onComplete: function () {
								$('encarte'+idProduct).innerHTML = 'Successfully added item to cart. - <a href="?p=view_cart">View Cart</a>';
							}
	}).send();
}
function FindSetSelect(obj,val)
{
	var i = obj.options.length;
	while(i > 0)
	{
		if(obj.options[(i-1)].text == val || obj.options[(i-1)].value == val)
		{
			obj.selectedIndex = (i-1);
			break;
		}
		i--;
	}
}
function SetBillingToPhysical()
{
	$('baddress').value = $('aaddress').value;
	$('bcity').value = $('acity').value;
	$('bstate').selectedIndex = $('astate').selectedIndex;
	$('bzip').value = $('azip').value;
	$('bnoc').value = $('first').value+' '+$('last').value;
}
/* ]]> */