String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}


function validate_taburit_form(name, family, prefix, suffix, month, year, day)
{	
	if (prefix == "0")
	{
		alert("לא נבחרה קידומת לטלפון. אנא בחרי קידומת ולחצי שוב על 'שלח'.");
		return false;
	}
	
	suffix = suffix.replace(/[^0-9]/g, "").trim();
	if (suffix.length > 7)
	{
		alert("ישנן יותר מדי ספרות בטלפון שהוזן. אנא בדקי את המספר ולחצי שוב על 'שלח'.");
		return false;
	}
	
	if (suffix.length < 7)
	{
		alert("חסרות ספרות בטלפון שהוזן. אנא בדקי את המספר ולחצי שוב על 'שלח'.");
		return false;
	}
	
	if (name.length < 2 || family.length < 2)
	{
		alert("השם שהוכנס קצר מדי. אנא בדקי את השם ושם המשפחה ולחצי שוב על 'שלח'.");
		return false;
	}
		
	if (month == "0" || day == "0" || year == "0" || month == "undefined" || day == "undefined" || year == "undefined" || month == "" || day == "" || year == "")
	{
		alert("תאריך הלידה שהוזן אינו מלא. אנא בדקי את תאריך הלידה ולחצי שוב על 'שלח'.");
		return false;
	}
	return true;
}

function on_submit_successfull()
{
	if (data_from_server == "")
	{
		//location.href = 'taburit_thankyou.php';
		thankyou_message();
	}
	else
	{
		error_message();		
	}
	
}

function on_taburit_form_submit()
{	
	var name = document.getElementById('pren').value.trim();
	var family = document.getElementById('fam').value.trim();
	var prefix = document.getElementById('cd').value.trim();
	var suffix = document.getElementById('tel').value.trim();
	var day = document.getElementById('taburit_date').value.trim();
	var month = document.getElementById('taburit_month').value.trim();
	var year = document.getElementById('taburit_year').value.trim();
	var param_arr = Array("name", "family", "phone_prefix", "phone_suffix", "birth_date", "referrer");
	var value_arr = Array(name, family, prefix, suffix, year + "-" + month + "-" + day, document.title);
	
	if (validate_taburit_form(name, family, prefix, suffix, month, year, day))
	{	
		try
		{
			thinking_message();
		}
		catch (e)
		{
		
		}
	
		call_server_post_params_array("leads/submit_taburit_crio_lead.php", param_arr, value_arr, on_submit_successfull, null);
	}
}

function thinking_message()
{
	var message = document.createElement("div");
	var span = document.createElement("span");
	span.id = 'loading_image';
	span.style.visibility = "visible";
	span.style.width = '105px';
	span.style.fontSize = '14px';
	span.style.background = 'none repeat scroll 0 0 white';
	span.style.padding = '10px';
	
	span.innerHTML = "<b>מעבד בקשה...</b><img src='images/animation/spinning.gif' alt='מעבד בקשה...'/>";
	message.appendChild(span);
	msgBox(message);
}

function init_taburit_form()
{	
	document.getElementById('taburit_send').onclick = on_taburit_form_submit;
}
init_taburit_form();


function error_message()
{
	var message = document.createElement("div");
	//message.style.minWidth = "600px";
	message.style.width = "600px";
	
	var title = document.createElement("div");
	title.innerHTML = "שגיאה בקבלת הפרטים";
	title.style.fontSize = "30px";
	title.style.color = "#C24C78";
	title.style.marginBottom = "10px";
	
	message.appendChild(title);
	
	var logo = document.createElement("img");
	logo.src = "taburit_page_template/taburit_logo.png";
	//logo.style.cssFloat = 'left';
	logo.className = 'floating_logo';
	title.appendChild(logo);
	var text = document.createElement("div");
	text.innerHTML = "חלה שגיאה בזמן קליטת הפרטים שלך במערכת, ופרטיך לא נקלטו. אנא נסי שנית.";
	text.style.fontSize = "20px";
	text.style.color = "#828282";
	message.appendChild(text);
	
	var button = document.createElement("div");	
	button.innerHTML = '<u>חזרה למחשבון</u>';
	button.onclick = msgBox_vanish;
	button.style.fontSize = "12px";
	button.style.marginTop = "10px";
	button.style.minHeight = "25px";
	button.className = "linked";
	//button.style.margin = '0 auto';
	
	
	message.appendChild(button);
	
	msgBox(message);
}

function thankyou_message()
{
	var message = document.createElement("div");
	//message.style.minWidth = "600px";
	message.style.width = "600px";
	
	var title = document.createElement("div");
	title.innerHTML = "תודה על פנייתך";
	title.style.fontSize = "30px";
	title.style.color = "#C24C78";
	title.style.marginBottom = "10px";
	
	message.appendChild(title);
	
	var logo = document.createElement("img");
	logo.src = "taburit_page_template/taburit_logo.png";
	//logo.style.cssFloat = 'left';
	logo.className = 'floating_logo';
	title.appendChild(logo);
	var text = document.createElement("div");
	text.innerHTML = "נציגי טבורית יחזרו אלייך בהקדם";
	text.style.fontSize = "20px";
	text.style.color = "#828282";
	message.appendChild(text);
	
	var button = document.createElement("div");	
	button.innerHTML = '<u>חזרה למחשבון</u>';
	button.onclick = msgBox_vanish;
	button.style.fontSize = "12px";
	button.style.marginTop = "10px";
	button.style.minHeight = "25px";
	button.className = "linked";
	//button.style.margin = '0 auto';
	
	
	message.appendChild(button);
	
	msgBox(message);
}

function load_taburit_objects()
{
	
	var text_arr = Array("בחרי");
	var value_arr = Array(0);
	
	for (var i = 1; i <= 31; i++)
	{
		text_arr[i] = i;
		value_arr[i] = i;
	}

	load_list_from_array(taburit_day_list, text_arr, value_arr, 0);
	
	text_arr = Array("בחרי");
	value_arr = Array(0);
	
	for (var i = 1; i <= 12; i++)
	{
		text_arr[i] = i;
		value_arr[i] = i;
	}
	
	load_list_from_array(taburit_month_list, text_arr, value_arr, 0);
	
	list = document.getElementById('taburit_year');
	
	text_arr = Array("בחרי");
	value_arr = Array(0);
	
	text_arr[1] = 2011;
	value_arr[1] = 2011;
	
	text_arr[2] = 2012;
	value_arr[2] = 2012;
	
	load_list_from_array(taburit_year_list, text_arr, value_arr, 0);
}

var taburit_day_list, taburit_month_list, taburit_year_list;

taburit_day_list = document.getElementById('taburit_date');
taburit_month_list = document.getElementById('taburit_month');
taburit_year_list = document.getElementById('taburit_year');
load_taburit_objects();

