
function showLoaderAt(e)
{
	$e = $(e).parent();
	setTimeout(function(){
		$e.html('<table><tr><td><img src="/site/img/ajax_loader.gif" /></td><td style="color:#09f">Please wait.</td></tr></table>');
	}, 100);
}
function empty( mixed_var ) 
{ 
	return ( mixed_var === "" || mixed_var === 0   || mixed_var === "0" || mixed_var === null  || mixed_var === false  ||  mixed_var.length === 0 );
}


function kwtValidate(obj)
{	
	var regul = /[^a-zA-Z0-9\s\-\'\`\,;]/;
	var regulcom = /[^a-zA-Z0-9\s\-\'\`]/;
	var com = 0;
	var spec = 0;
	var fintext = '';
	var rept='';
	for(i=0; i<$("textarea").length; i++ )
	{	
		var text = $("textarea")[i].value; 
		//if (text === "Please enter one keyword phrase per line. Avoid using , . ; in this field") text = '';
        if (text === "Enter Your Targeted Keywords (one per line)") text = '';
		if (regulcom.test(text))
		{
			for(var q = 0; q < text.length; q++)
			{	
				if(!regul.test(text.charAt(q))) 
				{
					if(text.charAt(q) === ',' || text.charAt(q) === ';' || text.charAt(q) === '\n') 
					{ 
						rept += "\n";
						com =1;
					}
					else {
						rept += text.charAt(q);
					}
				}else {
				spec = 1;
				}
			}
			
			rept = jQuery.trim(rept);
			if(com==1)
			{
				reptarr = rept.split('\n');
				for(var qr = 0; qr < reptarr.length; qr++)
				{	
					reptarr[qr] = jQuery.trim(reptarr[qr]);	
					if(empty(reptarr[qr])) 
					{
						//alert('pystota');
						
					} else {
						fintext += reptarr[qr]+'\n';
					}
					
					
				}
			} else {fintext = rept;}
			
			$("textarea")[i].value = fintext;
			
		} else {
			$("textarea")[i].value = jQuery.trim(text);
		}	
		//alert('value - '+$("textarea")[i].value+'; number - '+i);
		fintext = "";
		rept = "";
	}
	if(com == 1 && spec != 1)
	{
		alert("Note: it's not allowed to use commas (,) in the keyword list, that's why all commas were automatically replaced with line folding. (Our system treats commas as line folding.) You'll be able to edit your keywords & make any necessary changes when you login to the system on further steps.");
	}
	if(com == 1 && spec == 1)
	{
		alert("Note: you can only use English letters (a-z) and numbers (0-9) in your keywords. That's why all non-English letters and all special characters such as~!@#$%^&*()_+=;:\/[]. were automatically removed from your keyword list. It's also not allowed to use commas (,) in the keyword list, so all commas were automatically replaced with line folding. You'll be able to edit your keywords & make any necessary changes when you login to the system on further steps.");
	}
	if(com != 1 && spec == 1)
	{
		alert("Note: you can only use English letters (a-z) and numbers (0-9) in your keywords. That's why all non-English letters and all special characters such as ~!@#$%^&*()_+=;:\/[],. were automatically removed from your keyword list. You'll be able to edit your keywords & make any necessary changes when you login to the system on further steps.");
	}
	if ($("#b_name").val() === "Enter Your First Name")
	{
		$("#b_name").val("");
	}
    if ($("#b_email").val() === "Enter Your Email")
	{
		$("#b_email").val("");
	}
	if ($("#b_url").val() === "Enter Your Site URL")
	{
		$("#b_url").val("");
	}
	showLoaderAt(obj);
	$("form[class=iform1]").submit();
}


/*function kwtValidate(obj)
{
	var regul = /[^a-zA-Z0-9\-\s]/;
	var validate = true;
	$(':input[name*="project_keyword"]').each(function() {
		if (regul.test(this.value))
    	{
    		if (!confirm("Note: you're using some special characters. Are you sure, you want to submit these keywords anyway?"))
    		{
    			validate = false;
    		}
    	}
	});
	if (!validate) return false;
	
	
	showLoaderAt(obj);
	$("form[class=iform1]").submit();
}*/

