﻿var tabs = $A(['features', 'attachments','exAttachments', 'specs', 'exSpecs', 'cSpecs']);
var type = 0;

function isDev()
{
	if (window.location.hostname == 'dev.13prime.com')
		return true;
	else
		return false;
}
function isAdmin()
{
	if (window.location.href.indexOf('/admin/') >= 0)
		return true;
	else
		return false;
}


function initTabs()
{
	type = $F('productType');

	if (type == 1)
		$('featuresTab').hide();
	else if (type == 3 || type == 4)
	{
		$('featuresTab').hide();
		$('attachmentsTab').hide();
	}

	changeTab('specs');
}

function changeTab(name)
{
	$$('.tab').each(function (ele) { ele.removeClassName('selected'); });

	$(name + 'Tab').addClassName('selected');

	var prefix = (isAdmin()) ? 'admin' : '';

	tabs.each(function (tab) { try { $(prefix + tab).hide(); } catch (e) { } });

	if (name == 'specs')
	{
		if (type == 0 || type == 5)
			$(prefix + 'exSpecs').show();
		else if (type == 1)
			$(prefix + 'cSpecs').show();
		else
			$(prefix + 'specs').show();
	}
	else if (isAdmin() && type == 0 && name == 'attachments')
	{
		$(prefix + 'exAttachments').show();
	}
	else
		$(prefix + name).show();
}


function removeDoc(type, model)
{
	var url = (isDev()) ? '/ihices.com/a.aspx' : '/a.aspx';
	
	new Ajax.Request(
		url,
		{
			method: 'post',
			parameters: 'action=removeDoc&type=' + type + '&model=' + model,
			onComplete: function(transport) { window.location.reload(); }
		}
	);
}


function validateContact()
{
	var x = "";

	if ($F('name') == '')
		x += '- Name cannot be blank\n';
	if ($F('phone') == '')
		x += '- Phone cannot be blank\n';
	if ($F('email') == '')
		x += '- Email cannot be blank\n';

	if (x.length > 0)
		alert('Please correct the following: \n\n' + x);
	else
		$('valid').value = true;
}


function initAdmin()
{
	$$('.small').each(function (ele) { CKEDITOR.replace(ele); });
	$$('.editor').each(function (ele) { CKEDITOR.replace(ele, { toolbar: 'CMS' }); });
}

function deleteConfirmation()
{
	var cf = confirm("Delete this machine?");
	if (cf)
	{
		$('deleteConfirm').value = 'true';
		return true;
	}
	return false;
}
