// JavaScript Document

function required()
{
	var hiba = false;
	if( isempty(document.getElementById("name").value) ) hiba = true;
	
	if(document.getElementById("howcontact"))
	{
			if(document.getElementById("howcontact").selectedIndex>1)
			{
				if(isempty(document.getElementById("phone").value))
				{
					hiba=true;
					alert("Please check your phone field values!");
					return !hiba;
				}
			}
	}
	
	if( !isemail(document.getElementById("email").value) )
	{
		hiba = true;
		alert("Please check your e-mail syntax! (STEP 1)");
		return !hiba;
	}
	
	if( document.getElementById("email").value != document.getElementById("re_email").value)
	{
		hiba = true;
		alert("Please check your e-mail address as they seem to differ! (STEP 1)");
		return !hiba;
	}
	
	var chks = document.getElementById("othertreatments").getElementsByTagName("INPUT");
	var ck = 0, i;
	for(i=0; i< chks.length; i++)
	{
		if(chks[i].type=="checkbox" && chks[i].checked) ck++;
	}
	if(!ck)
	{
		hiba = true;
		alert("Please check the Dental Treatment(s) you require! (STEP 3)");
		return !hiba;
	}
	
	if(document.getElementById('startdt'))
	{
		if(document.getElementById('startdt').value=="")
		{
			hiba=true;
			alert("Please select when do you plan to start your dental treatment! (STEP 3)");
			return !hiba;
		}
	}

	if(document.getElementById('howcontact'))
	{
		if(document.getElementById('howcontact').value=="")
		{
			hiba=true;
			alert("Please select how do you wish to be contacted! (STEP 3)");
			return !hiba;
		}
	}
 	
	var rb = document.getElementById("freeeva").getElementsByTagName("INPUT");
	ck=0;
	for(i=0;i<rb.length;i++)
	{
		if(rb[i].checked) ck++;
	}
	if(!ck)
	{
		hiba = true;
		alert("Please check the currency in which you wish to receive your Free Evaluation! (Step 3)");
		return !hiba;
	}
	
	if(hiba) alert("Please complete all required fields!"); 
	return !hiba;
}

function contactrequired()
{
	var hiba = false;
	if( isempty(document.getElementById("name").value) ) hiba = true;
	if( !isemail(document.getElementById("email").value) )
	{
		hiba = true;
		alert("Please check your e-mail syntax!");
		return !hiba;
	}
	if( document.getElementById("email").value != document.getElementById("re_email").value)
	{
		hiba = true;
		alert("Please check your e-mail address as they seem to differ!");
		return !hiba;
	}
	if( isempty(document.getElementById("othercomm").value) ) hiba = true;
	if(hiba) alert("Please complete all required fields!"); 
	return !hiba;
}

/* global function */
function isempty(str)
{
	var r = new RegExp("^ *$");
	return r.test(str);
}

function isemail(str)
{
	var r = new RegExp("^[0-9a-zA-Z._-]{2,}@([0-9a-zA-Z_-]{2,}\\.){1,7}[a-zA-Z]{2,3}$");
	return r.test(str);
}


function iecheck()
{
	var pos = navigator.userAgent.indexOf("MSIE ");
	if (pos == -1) return false;
	var version = navigator.userAgent.substring(pos + 5);
	return (((version.indexOf("5.5") == 0) || (version.indexOf("6") == 0)  || ( version.indexOf("7") == 0) || ( version.indexOf("8") == 0) ) && (navigator.platform == ("Win32")));
}

function operacheck()
{
	var pos = navigator.userAgent.indexOf("Opera");
	return (pos == 0);
}

function firefoxcheck()
{
	var pos = navigator.userAgent.indexOf("Gecko");
	return (pos > 0)
}

function setXMLNS()
{
	var d = document.getElementById("mainhtml");
	if(iecheck())	
	{
		try
		{
			document.namespaces.add('v', 'urn:schemas-microsoft-com:vml','#default#VML');
		}
		catch(e){}
	}
}

function winopen(url,size)
{	
	window.open(url,"movie",size);
}

function change_money(obj)
{
	var i = obj.selectedIndex;
	var v = obj.options[i].value
	window.location = "/prices_"+v+".html";
}

var UPR_STR = "";
var UPL_STR = "";
var LOR_STR = "";
var LOL_STR = "";
var QUAD = 0;
function getprices(bt)
{
	if(required())
	{
		bt.disabled = "disabled";
		document.getElementById("indicator").style.display = "inline";
		UPR_STR = "";
		UPL_STR = "";
		LOR_STR = "";
		LOL_STR = "";
		var obj = document.getElementById("pricefrm");
		var en = document.getElementById("othertreatments").getElementsByTagName("INPUT");
		var tmb = new Array();
		var treat = "";
		for(var i = 0; i< en.length; i++)
		{
			if(en[i].type == "checkbox" && en[i].checked)
			{
				treat += ", "+en[i].value;
			}
		}
		treat = treat.substr(2);
		tmb.push(new Array("custom treatments", treat));
		
		//mikor tervezi a jovetelet, hogyan erjuk el.
		if(document.getElementById('startdt'))	tmb.push(new Array("custom whenstart", document.getElementById('startdt').value));
		if(document.getElementById('howcontact')) tmb.push(new Array("custom howcontact", document.getElementById('howcontact').value));
		
		// free evaluation
		var eva = document.getElementById("freeeva").getElementsByTagName("INPUT");
		for(i=0;i<eva.length;i++)
		{
			if(eva[i].checked)
			{
				tmb.push(new Array("custom freecurrency", eva[i].value));
				break;
			}
		}
		
		/* ha NEM az uj fogsor cucc van */
		if(!document.getElementById('jawbugsinputup'))
		{
			var upper = document.getElementById("upperjaw");
			var lower = document.getElementById("lowerjaw");
			var du = upper.getElementsByTagName("DIV");
			var dl = lower.getElementsByTagName("DIV");
			var r = new RegExp("[0-9]+");
			var z = 0;
	
			QUAD = 0;
			// felso
			for(i = 0; i < du.length; i++)
			{
				if(iecheck())
				{
					var a = r.exec(du[i].style.filter);
					if(Number(a) > 0) fogfuzes(i-8,"upper");
					r.lastIndex = 0;
				}
				else
				{
					if(du[i].style.opacity > 0) fogfuzes(i-8,"upper");
				}
			}
	
			QUAD = 0;
			for(i = 0; i < dl.length; i++)
			{
				if(iecheck())
				{
					var a = r.exec(dl[i].style.filter);
					if(Number(a) > 0) fogfuzes(i-8,"lower");
					r.lastIndex = 0;
				}
				else
				{
					if(dl[i].style.opacity > 0) fogfuzes(i-8,"lower");
				}
			}
			tmb.push(new Array("jawtype","oldjaw"));
		}
		else
		{
			/* uj fogkigyujtes*/
			var upperke = document.getElementById('jawbugsinputup').value.split(',');
			var downeke = document.getElementById('jawbugsinputdn').value.split(',');
			for(i=0;i<upperke.length;i++)
			{
				// jobb felso
				if(new RegExp('^1','g').test(upperke[i])) UPR_STR += ' '+upperke[i];
				// bal felso
				if(new RegExp('^2','g').test(upperke[i])) UPL_STR += ' '+upperke[i];
			}
			for(i=0;i<downeke.length;i++)
			{
				// bal also
				if(new RegExp('^3','g').test(downeke[i])) LOL_STR += ' '+downeke[i];
				// jobb also
				if(new RegExp('^4','g').test(downeke[i])) LOR_STR += ' '+downeke[i];	
			}
			UPR_STR = UPR_STR.replace(/^,/,"");
			UPL_STR = UPL_STR.replace(/^,/,"");
			LOL_STR = LOL_STR.replace(/^,/,"");
			LOR_STR = LOR_STR.replace(/^,/,"");
			tmb.push(new Array("jawtype","newjaw"));
		}
		/* ***** */


		tmb.push(new Array("custom upperright", UPR_STR));
		tmb.push(new Array("custom upperleft", UPL_STR));
		tmb.push(new Array("custom lowerright", LOR_STR));
		tmb.push(new Array("custom lowerleft", LOL_STR));
		tmb.push(new Array("custom preliminary", document.getElementById("preliminary").value));
		if(document.getElementById("custom_description")) tmb.push(new Array("custom description", document.getElementById("custom_description").value));
		makeinput(tmb, obj);
		obj.submit();
		//sendmyself(obj);
	}
}

function makeinput(tmb, frm)
{
	for	(var i = 0; i< tmb.length; i++)
	{
		var n = document.createElement("INPUT");
		n.type = "hidden";
		n.name = tmb[i][0];
		n.value = tmb[i][1];
		frm.appendChild(n);
	}
}

function sendcallback()
{
	var hiba = false;
	if( isempty(document.getElementById("callbackname").value) )
	{
		alert("Please complete all required fields!");	
		hiba = true;
		return false;	
	}
	if( isempty(document.getElementById("callbackphone").value) )
	{		
		alert("Please complete all required fields!");	
		hiba = true;
		return false;
	}
	if( !isemail(document.getElementById("callbackmail").value) )
	{
		alert("Please check your e-mail syntax!");
		return false;
		hiba = true;
	}
	if(!hiba)
	{
		var frm = document.createElement("FORM");
		frm.style.display = "none";
		frm.action = "/process/sendform.php";
		frm.method = "post";
		
		var n = new Array();
		n.push(new Array("callbackname", document.getElementById("callbackname").value));
		n.push(new Array("callbackphone", document.getElementById("callbackphone").value));
		n.push(new Array("callbackmail", document.getElementById("callbackmail").value));
		var i = document.getElementById("besttime").selectedIndex;
		n.push(new Array("besttime", document.getElementById("besttime").options[i].value));
		n.push(new Array("callcomm", document.getElementById("callcomm").value));
		n.push(new Array("action","callback"));
		n.push(new Array("backsitename","thankyou_callback"));
		makeinput(n, frm);
		document.body.appendChild(frm);
		frm.submit();
	}	
}

function fogfuzes(n,type)
{
	var i = n+8;
	if(type == "upper")
	{
		if(n>=0)
		{
			QUAD = 1;
			UPL_STR += " 2"+(Math.abs((i+QUAD)-8));
		}
		else
		{
			UPR_STR += " 1"+(Math.abs((i+QUAD)-8));
		}	
	}
	
	if(type == "lower")
	{
		if(n>=0)
		{
			QUAD = 1;
			LOL_STR += " 3"+(Math.abs((i+QUAD)-8));
		}
		else
		{
			LOR_STR += " 4"+(Math.abs((i+QUAD)-8));
		}	
	}
}

function trim(str)
{
	return str.replace(/^s+/, '').replace(/s+$/, '');
}

function embedFlash(id,url,w,h)
{
	var str  = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,24,0" width="'+w+'" height="'+h+'">';
	str += '<param name="movie" value="'+url+'" />';
	str += '<param name="quality" value="high" />';
	str += '<param name="menu" value="false" />';
	str += '<embed src="'+url+'" menu="false" swfLiveconnect="true" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'"></embed>';
	str += '</object>';
	document.getElementById(id).innerHTML = str;
}

function mlreplacer(id)
{
	var m = document.getElementById(id).innerHTML;
	m = m.replace(/ at /,"@");
	m = m.replace(/ dot /,".");
	document.getElementById(id).innerHTML = '<a href="mailto:'+m+'">'+m+'</a>';
}

function getAjax()
{
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				//A böngészo nem támogatja az ajaxot
				return false;
			}
		}
	}
	return xmlHttp;
}

/*
function sendmyself(frm)
{
	var allfields = frm.getElementsByTagName("input");
	var	qstr = "";
	for(var i = 0; i<allfields.length; i++)
	{
		qstr += allfields[i].name+"="+allfields[i].value+"&";
	}
	qstr = qstr.substr(0,qstr.length-1);
	qstr += "&custom_sex="+document.getElementById("sex").value; //sexfields.options[sexfields.selectedIndex].value
	
	
	var xmlHttp = new getAjax();
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState==4)
		{
			frm.submit();
			//alert(xmlHttp.responseText);
		}
	}

	xmlHttp.open("POST","/process/sendform.php",true);
	xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=utf-8");
	xmlHttp.setRequestHeader("Request-type","XMLHttpRequest");		
	if (xmlHttp.overrideMimeType)	xmlHttp.setRequestHeader("Connection","close");
	querystr = qstr+"&browser="+navigator.userAgent;
	xmlHttp.send(querystr);
}*/

function sendconsultation()
{
	var hiba = false;
	if( isempty(document.getElementById("firstname").value) ) hiba = true;
	if( isempty(document.getElementById("familyname").value) ) hiba = true;
	if( isempty(document.getElementById("phone").value) ) hiba = true;
	if(document.getElementById("airport").selectedIndex < 1) hiba= true;

	if(hiba)
	{
		alert("Please complete all required fields!");
		return false;
	}
	else
	{
		if( !isemail(document.getElementById("email1").value) )
		{
			alert("Please check your e-mail syntax!");
			return false;
		}
		if( document.getElementById("email1").value != document.getElementById("email2").value)
		{
			alert("Please check your e-mail address as they seem to differ!");
			return false;
		}
	}
}

function currencyChanger(slt)
{
	var tbl = document.getElementById("pricesTable");
	var i,j,sty;
	for(i=0;i<tbl.rows.length;i++)
	{
		var row = tbl.rows[i];
		if(row.cells.length>1)
		{
			for(j=1;j<row.cells.length;j++)
			{
				row.cells[j].style.display = "none";
				sty = (slt.value == "UK prices") ? 1 : 2;
				if(Math.ceil(j/3)==sty)	row.cells[j].style.display = "";
			}
		}
	}
}

function howchange(j)
{
	var h = document.getElementById('phonelabel').innerHTML;
	if(j.selectedIndex>1)
	{		
		if(new RegExp("^[^*]","gi").test(h))
		{
			document.getElementById('phonelabel').innerHTML = "* "+h;
		}
	}
	else
	{
		h = h.replace(/\* /,"");
		document.getElementById('phonelabel').innerHTML = h;
	}
}

function sendDiscounts()
{
	var hiba = false;
	if(!trim($("#name").val()))
	{
		hiba = true;
	}
	
	if(!isemail(trim($("#email").val())))
	{
		hiba = true;
	}
	
	if(!trim($("#tel").val()))
	{
		hiba = true;
	}
	
	if(!trim($("#airport").val()))
	{
		hiba = true;
	}
	
	if($("#wishes input:checked").length==0)
	{
		hiba = true;
	}
	
	if(hiba)
	{
		 alert("Please complete all required fields!");
		 return;
	}
	
	var indicator = '<img src="/images/indicator2.gif" class="ml20 vmid dindi" /> <span class="blue dindi">please wait...</span>';
	$('#discountbutton').after(indicator);
	$('#discountbutton').unbind('click');
	$('#discountbutton').removeAttr('onclick');
	var data = "&name="+$("#name").val()+"&email="+$("#email").val()+"&tel="+$("#tel").val()+"&date="+$("#wishes input:checked").val();
	data += "&airport="+$("#airport").val()+"&did="+$("#did").val()+"&comment="+$("#comment").val();
	
	$.ajax({
		url:"/process/sendform.php",
		type:"POST",
		data:"action=discounts"+data,
		success:function(msg)
		{
			window.location = "/thankyou.html";
		}
	});
}

function sendtoafriend()
{
	$.ajax({
		type: "POST",
		url: "/process/sendtoafriend.php",
		data: "action=tofriend",
		success: function(msg){
			var mod='<div>\
			<img src="/images/x.gif" alt="bezár" class="hand floatright" onclick="jQuery.facebox.close();" />\
			<div class="floatleft"><h3>Email this to a friend</h3></div>\
			<div class="clear"></div><br />\
			'+msg+'\
			</div>';
			$.facebox(mod);
		}
	});
}

function sendpageinmail()
{
	var adat = "action=sendtoafriend&kuldo="+$("#kuldo").val()+"&kuldo_mail="+$("#kuldo_mail").val()+"&cimzett="+$("#cimzett").val();
	adat += "&cimzett_mail="+$("#cimzett_mail").val()+"&page="+window.location+"&uzenet="+$("#uzenet").val()+"&copyme="+String($("#magamnakis").attr("checked"));

	if($.trim($("#kuldo").val())=="") { alert("Please complete all required fields!"); return false; }
	if(!isemail( $.trim($("#kuldo_mail").val()))) { alert("Please check sender e-mail syntax!"); return false; }
	if($.trim($("#cimzett").val())=="") { alert("Please complete all required fields!"); return false; }
	if(!isemail( $.trim( $("#cimzett_mail").val()))) { alert("Please check receiver e-mail syntax!"); return false; }
	$("#ajaxindicator").show();
	$.ajax({
		url:"/process/sendform.php",
		type:"POST",
		data: adat,
		success: function(msg){
			$("#sendtoafriendbox").html('<div class="f14 green" align="center"><b>Thank you for sharing great Dental Savings<br />with your Friends!</b></div>')
		}
	});
}

function samplebanda()
{
	$.ajax({
		url: "/process/samplebanda.php",
		type: "post",
		success:function(msg)
		{
			var str = '<div><h3 class="floatleft">Before &amp; After</h3>\
			<img src="/images/x.gif" alt="bezár" style="cursor:pointer; float:right;" onclick="jQuery.facebox.close();" /><div class="clear"></div><br />\
			<div style="width:450px;">'+msg+'</div><br />\
			<a href="/before_and_after.html" class="floatright">More picture</a><div class="clear"></div>\
			</div>';
			$.facebox(str);	
		}
	});
}

function samplevideo()
{
	var str = '<div>minta video testimonal\
	<img src="/images/x.gif" alt="bezár" style="cursor:pointer; float:right;" onclick="jQuery.facebox.close();" />\
	</div>';
	$.facebox(str)
}

function sample3d()
{
	var str = '<div>3d bemutato\
	<img src="/images/x.gif" alt="bezár" style="cursor:pointer; float:right;" onclick="jQuery.facebox.close();" />\
	</div>';
	$.facebox(str)
}

function sendsurvey(obj)
{
	var set = $(".ten img[set='1']").length;
	var ker = $(".ten").length;
	var ket = $(".two input[type='radio']").filter("input[checked='true']").length;
	var inp = $(".two input[type='radio']").length/2;
	// extra figyeles
	var ext = $("#q10 input[type='radio']").eq(0).filter("input[checked='true']").length;
	
	if(set<ker || ket<inp || (ext==1 && $.trim($("#q17 textarea").val())=="")) { alert('Please provide an answer to every question!'); return false; }
	
	$(obj).unbind('click');
	$(obj).removeAttr('onclick');
	$(obj).after('<img src="/images/ajaxindicator.gif" class="vmid ml16 surveyindicator" />')
	// csillag ertekeles begyujtese
	var datastr = "action=sendsurvey&sess="+SESS;
	$(".ten img[set='1']").each(function(i,e){
		datastr += "&answers["+$(e).parent().attr('id')+"]="+($(e).index()+1);
	})
	// yes no ertekeles begyujtese
	$(".two input[type='radio']").filter("input[checked='true']").each(function(i,e){
		datastr += "&answers["+$(e).parent().attr('id')+"]="+$(e).val();
	});
	
	// szoveges ertekeles
	$(".free textarea").each(function(i,e){
		datastr += "&answers["+$(e).parent().attr("id")+"]="+$(e).val();
	});
	
	$.ajax({
		url:'/process/sendsurvey.php',
		type:'post',
		data:datastr,
		success:function(str){
			window.location="/survey_thankyou.html";
		}
	})
}