/**
 * @author Carlos Peņa
 */
 

/* Payment Form */
function paypalForm() {
	
	var val = document.getElementById('item_name').value; // Value from the Select
	
	switch (val) {
		case 'Square Ad - 1 Month': // Value of the Option field selected
			var amn = '25.00'; // Price for each of the packages
			break;
		case 'Square Ad - 2 Months':
			var amn = '45.00';
			break;
		case 'Square Ad - 3 Months':
			var amn = '60.00';
			break;
		case 'Partners Link - 1 Month':
			var amn = '10.00';
			break;
		case 'Partners Link - 2 Months':
			var amn = '15.00';
			break;
		case 'Partners Link - 3 Months':
			var amn = '20.00';
			break;
		default:
			var amn = '25.00';	
	}
	
	document.getElementById('frm_amount').value = amn;
	
}
  
function checkForm() {
	var doc = document.submitform;
	var error = '';
	if(doc.title.value == '' || doc.title.value == 'title') {
		error += '<li>Please enter a Title for your tutorial</li>';
	}
	if(doc.url.value == '' || doc.url.value == 'url') {
		error += '<li>Please enter an Url for your tutorial</li>';
	}
	if(doc.desc.value == '' || doc.desc.value == 'description') {
		error += '<li>Please enter a Description for your tutorial</li>';
	}
	if(doc.cat.value == '0') {
		error += '<li>Please choose a Category/SubCategory for your tutorial</li>';
	}
	
	// Show error message(s), if any
	if(error != '') {
		document.getElementById('light').innerHTML = '<div id="error_cont"><div id="error_title">Please <span class="error_blue">correct</span> the following errors:</div><div id="error_close"><a href="javascript:closeError();"><img src="http://think2torials.com/wp-content/themes/think2torials/images/error_close.jpg" alt="Close" /></a></div><div class="clear"></div><ul id="error_list">'+error+'</ul></div>';
		document.getElementById('light').style.display='block';
		document.getElementById('fade').style.display='block';
	} else { // If no error, call sendTut() function
		sendTut();
	}
	return false;
}

function closeError() {
	document.getElementById('light').style.display='none';
	document.getElementById('fade').style.display='none';
}
 
function changeSubCat(p) {
	var selects = '<select id="select_subcat" name="sub_cat">';
	
	if(p == 'ps') {
		var subcats = new Array("Animation", "Basics", "Buttons", "Drawings", "Effects", "Icons", "Photo Retouch", "Text Effects", "Web Design", "Web Templates");
	} else if(p == 'il') {
		var subcats = new Array("Animacion", "dos", "tres", "cuatro");
	} else if(p == 'css') {
		var subcats = new Array("tablas", "layouts", "tres", "cuatro");
	}
	var i = 0;
	while (i < subcats.length) {
		selects += '<option value="'+subcats[i]+'">'+subcats[i]+'</option>';
		i++;
	}
	
	selects += '</select>';
	
	document.getElementById('select_subcat_p').innerHTML = selects;
}

function clearInput(i, v) {
	if(i.value == v) {
		i.value = '';
	} else if(i.value == '') {
		i.value = v;
	}
}

function clearTextarea(i, v) {
	if(i.innerHTML == v) {
		i.innerHTML = '';
	} else if(i.value == '') {
		i.innerHTML = v;
	}
}

function clearForm() {
	// Start Input Fx
	var titlefx = new Fx.Styles('s_title', {duration:500}); // Set Title Color
	titlefx.start({
			'color': '#f1eeda',
			'background-color': '#f1eeda'
			});
	var urlfx = new Fx.Styles('s_url', {duration:500}); // Set Url Color
	urlfx.start({
			'color': '#f1eeda',
			'background-color': '#f1eeda'
			});
	var descfx = new Fx.Styles('s_desc', {duration:500}); // Set Desc Color
	descfx.start({
			'color': '#f1eeda',
			'background-color': '#f1eeda'
			});
	
	(function() { document.submitform.reset() }).delay(500); // Reset Form Delayed
	
	var titlefx = new Fx.Styles('s_title', {duration:800});
	(function() { titlefx.start({
			'color': '#918e7e',
			'background-color': '#ffffff'
			}) }).delay(700);
	var urlfx = new Fx.Styles('s_url', {duration:800});
	(function() { urlfx.start({
			'color': '#918e7e',
			'background-color': '#ffffff'
			}) }).delay(700);
	var descfx = new Fx.Styles('s_desc', {duration:800});
	(function() { descfx.start({
			'color': '#918e7e',
			'background-color': '#ffffff'
			}) }).delay(700);
	// End Input Fx
}

/* Mootools AJAX */
function sendTut() {
	
	var myOpac = new Fx.Style('form_sent', 'opacity', {duration:3000});
	$('form_sent').setOpacity(0);
	$('form_loading').innerHTML = '<img src="http://think2torials.com/wp-content/themes/think2torials/images/spinner.gif" alt="Loading">';
	myOpac.start(1);

	function effects() {
		myOpac.start(1);
		$('form_sent').addClass('form_sent');
		setTimeout("document.getElementById('form_loading').innerHTML=''", 1500);
		(function() { clearForm(); }).delay(500);
	}

	$('submitform').send({
			update: $('form_sent'),
			onComplete: effects()
		}).request();
	return false;
}




