/*
-------------------------------------------------------
Project.....: Pickuphelp.com
Datetime....: 2011-01-04 09:54 GMT+8
Author......: Anderssonweb 2011 (micke@anderssonweb.se)
-------------------------------------------------------
*/

/* throw error
--------------------------------------------------*/
function throwError(data){
	if(data.fldError){
		$.each(data.fldError, function(){
			var $input = $('input:text[name=' + this + '],input:password[name=' + this + ']').addClass('error');
			var $img = $input.parent().parent().find('img:first');
			$img.attr("src","/images/warning.png");
		});
	}

	msg = "";
	$.each(data.msgError, function(){
		msg += "- " + this + "\n";
	});
	alert(msg);
}

/* block ui definitions
--------------------------------------------------*/
$.blockUI.defaults.growlCSS = {
	width:  	'350px',
	top:		'50px',
	left:   	'',
	right:  	'10px',
	border: 	'none',
	padding:	'5px',
	opacity:	0.8,
	cursor: 	'default',
	color:		'#fff',
	backgroundColor: '#000',
	'-webkit-border-radius': '10px',
	'-moz-border-radius':	 '10px'
};
	
$.blockUI.defaults.css = {
	padding:	'15px',
	margin:		0,
	width:		'30%',
	top:		'40%',
	left:		'35%',
	textAlign:	'center',
	color:		'#007f12',
	border:		'none',
	backgroundColor:'#fff',
	'-webkit-border-radius': '10px', 
	'-moz-border-radius': '10px',
	cursor:		'wait'
};

/* output rest of the form
--------------------------------------------------*/
function GenerateForm(Referer, Random){
	$.ajax({
		url: ABSPATH + "inc/ajax.Form.php",
		type: "POST",
		data: {

		},
		dataType: "json",
		success: function(data){
			if(data.hasError){
				throwError(data);
				
			}else{
				$('#pulMainFrm').html(data.Content);
				$('input[name^="custom type"]').attr('checked', false);
				$('input[name^="custom type"]').click(function(){
					FormContent(Referer, Random);
				});
			}
		}
	});
}

function FormContent(Referer, Random){
	$.ajax({
		url: ABSPATH + "inc/ajax.FormContent.php",
		type: "POST",
		data: {
			Referer: Referer,
			Random: Random
		},
		dataType: "json",
		success: function(data){
			if(data.hasError){
				throwError(data);
				
			}else{
				$('#rest-of-the-form').html(data.Content);
				$('input[name^="custom prefer"]').attr('checked', false);
				$('input[name^="custom prefer"]').click(function(){
					FormEmail();
				});
			}
		}
	});
}

function FormEmail(){
	$('#xtraText').html(
		

		"<h3>Just type in your email here to get your pick up lines =)</h3>\n"
	);
	$('.opt-in-email').html("");
	$('.opt-in-email').css("background-color", "#e8e8e8");
	$('.opt-in-email').html(
		 "<p>Your e-mail:</p>\n"
		+"<p class=\"email-addr\"><input type=\"text\" name=\"email\" class=\"opt-in-area\" /></p>\n"
	);
}
/* 		"<div class=\"content\">\n"
		+"	<p>Great! You filled out the form. Before you get the lines... let me introduce myself.</p><br />\n"
		+"	<p>I'm John Chase, and I created this site to help guys talk to girls. A few years back, I didn't know what to say and how to approach girls. Now after years of research and training I know exactly how to approach and get laid. because a few years ago I was an average dude and didn't know how easy it can be to get I will tell you funny pick up stories from my own life.. and give you lots of free tricks, information and techniques to pick up girls!</p><br />\n"
		+"	<p>Welcome to pickuphelp.com - the #1 ranked pick up lines website!</p><br />\n"
		+"	<p>I'm John, and I created this site to help guys get more and hotter women! Women love funny guys! Here is another pick up line...</p><br />\n"
		+"</div>\n"
		+"<h3>Type In Your Email And We Will Send Your Pick Up Lines Right Away!</h3><br />\n"
		+"<p>If you sign up right now... I will send you:</p><br />\n"
		
		+"<div class=\"this-is-what-you-get clearfix\">\n"
		+"	<ul>\n"
		+"	<li>Customized Pick Up lines.</li>\n"
		+"	<li>Videos of how to use pick up lines.</li>\n"
		+"	<li>My real life pick up stories.</li>\n"
		+"	</ul>\n"

		+"	<img src=\"./images/john-chase.jpg\" alt=\"image: john chase\" />\n"
		+"</div><br />\n"

		+"<h3>Just type in your email here to get your pick up lines =)</h3><br /><br />\n"
		*/

/* on DOM ready funcs
--------------------------------------------------*/
$(document).ready(function() {
	$('#pulMainFrm').submit( function(e){
		var msg = "";
		var chk = false;
		$('input[name^="custom type"]').each(function(){
			if(this.checked){
				chk = true; 
			}
		});
		if(chk == false) msg += "- Please select at least one kind of girl.\n";
		
		chk = false;
		$('input[name^="custom location"]').each(function(){
			if(this.checked){
				chk = true; 
			}
		});
		if(chk == false) msg += "- Please select at least one location.\n";

		chk = false;
		$('input[name^="custom age"]').each(function(){
			if(this.checked){
				chk = true; 
			}
		});
		if(chk == false) msg += "- Please select at least one age.\n";
		
		if($('select[name="custom your_age"]').val() == "0"){
			msg += "- Please select your age.\n";
		}
		
		chk = false;
		$('input[name^="custom pickup"]').each(function(){
			if(this.checked){
				chk = true; 
			}
		});
		if(chk == false) msg += "- Please select how you want to pick up girls.\n";

		chk = false;
		$('input[name^="custom skills"]').each(function(){
			if(this.checked){
				chk = true; 
			}
		});
		if(chk == false) msg += "- Please select whether you want to improve your skills.\n";

		chk = false;
		$('input[name^="custom line"]').each(function(){
			if(this.checked){
				chk = true; 
			}
		});
		if(chk == false) msg += "- Please select at least one line.\n";

		if($('input[name="email"]').val().length == 0){
			msg += "- The e-mail address is missing or not valid.\n";
		}

		if(msg.length != 0){
			alert(msg); 
			return false;
		}
	});
});
