// lets load up our javascripts
// GOOGLE CONVERSATION SCRIPT
function registerConversion(account,label,value)
{
     var image = new Image(1,1);
     image.src = 'http://www.googleadservices.com/pagead/conversion/' + account  + '/?value=' + value + '&amp;label=' + label + '&amp;guid=ON&amp;script=0';
     return true;
}
// END GOOGLE CONVERSATION SCRIPT

function cngsrc(src, obj)
{
	var lbref = document.getElementById('lbref');
	var lbimg = document.getElementById('lbimg');
	var oldsrc = lbimg.src;
	
	obj.src = oldsrc;
	lbref.href = src;
	lbimg.src = src;
}

function opnWin(url)
{
	window.open (url, "","menubar=1,resizable=0,width=430,height=450"); 
	return false;
}

function chkMail(mail)
{
	return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(mail);
}

function ajaxObject()
{
	var obj = null;
	
	if (window.XMLHttpRequest)
	{
		obj = new XMLHttpRequest;
		return obj;
	} 
	
	if (window.ActiveXObject)
	{
		obj = new ActiveXObject("Microsoft.XMLHTTP");
		return obj;
	}else
	if (window.ActiveXObject)
	{
		obj = new ActiveXObject("Microsoft.XMLHTTP") || new ActiveXObject("Msxml2.XMLHTTP");
		return obj;
	}
}

function fastCont()
{
	var name = encodeURIComponent(document.getElementById('form_name').value);
	var mail = document.getElementById('form_mail').value;
	var phone = document.getElementById('form_phone').value;
	var type = document.getElementById('form_type').value;
	var mailing = document.getElementById('form_news').checked;

	if (!phone) phone = 'NULL';
	
	if (name == '' || (mail == '' || chkMail(mail) == false))
	{
		if (name == '') document.getElementById('form_name').style.backgroundColor='#ffe8e8'; else document.getElementById('form_name').style.backgroundColor='#fff';
		if (mail == '' || !chkMail(mail)) document.getElementById('form_mail').style.backgroundColor='#ffe8e8'; else document.getElementById('form_name').style.backgroundColor='#fff';
	}
	else
	{
		var xhr = new ajaxObject();
		var url = "http://"+document.domain+"/contact.php?do=homeSend&name="+name+"&mail="+mail+"&phone="+phone+"&type="+type+"&mailing="+(mailing == 1 ? 1 : 0);
		xhr.open("GET", url, true);
		
		xhr.onreadystatechange = function() {//Call a function when the state changes.
			if(xhr.readyState == 4 && xhr.status == 200) {
				document.getElementById('homeCont').innerHTML = xhr.responseText;
			}
		}
		registerConversion('1049687762','Q4G0CNCakwIQ0u3D9AM','0');
		xhr.send(null);
	}
}

function prodCont()
{
	var name = encodeURIComponent(document.getElementById('prod_form_name').value);
	var mail = document.getElementById('prod_form_mail').value;
	// var addr = encodeURIComponent(document.getElementById('prod_form_addr').value);
	var phone = document.getElementById('prod_form_phone').value;
	// var cell = document.getElementById('prod_form_cell').value;
	// var cont = encodeURIComponent(document.getElementById('prod_form_cont').value);
	var section = document.getElementById('prod_section').value;
	var mailing = document.getElementById('prod_form_news').checked;
	
	if (!phone) phone = 'NULL';
	
	if (name == '' || (mail == '' || chkMail(mail) == false))
	{
		if (name == '') document.getElementById('prod_form_name').style.backgroundColor='#ffe8e8'; else document.getElementById('prod_form_name').style.backgroundColor='#fff';
		if (mail == '' || !chkMail(mail)) document.getElementById('prod_form_mail').style.backgroundColor='#ffe8e8'; else document.getElementById('prod_form_name').style.backgroundColor='#fff';
	}
	else
	{
		var xhr = new ajaxObject();
		// var url = "http://"+document.domain+"/jsProd/"+name+"/"+mail+"/"+phone+"/"+section+"/"+(mailing == 1 ? 1 : 0);
		var url = "http://"+document.domain+"/contact.php?do=prodSend&name="+name+"&mail="+mail+"&phone="+phone+"&cell="+section+"&mailing="+(mailing ? 1 : 0);
		xhr.open("GET", url, true);
		
		xhr.onreadystatechange = function() {//Call a function when the state changes.
			if(xhr.readyState == 4 && xhr.status == 200) {
				document.getElementById('order').innerHTML = xhr.responseText;
				setInterval("jQuery('#shortFormCont').slideUp('slow')", 2500);
			}
		}
		registerConversion('1049687762','Q4G0CNCakwIQ0u3D9AM','0');
		xhr.send(null);
	}
}

function landCont()
{
	var name = encodeURIComponent(document.getElementById('prod_form_name').value);
	var mail = document.getElementById('prod_form_mail').value;
	var addr = encodeURIComponent(document.getElementById('prod_form_addr').value);
	var phone = document.getElementById('prod_form_phone').value;
	var cell = document.getElementById('prod_form_cell').value;
	var cont = encodeURIComponent(document.getElementById('prod_form_cont').value);
	var section = document.getElementById('prod_section').value;
	var mailing = document.getElementById('prod_form_news').checked;
	
	if (!phone) phone = 'NULL';
	
	if (name == '' || (mail == '' || chkMail(mail) == false))
	{
		if (name == '') document.getElementById('prod_form_name').style.backgroundColor='#ffe8e8'; else document.getElementById('prod_form_name').style.backgroundColor='#fff';
		if (mail == '' || !chkMail(mail)) document.getElementById('prod_form_mail').style.backgroundColor='#ffe8e8'; else document.getElementById('prod_form_name').style.backgroundColor='#fff';
	}
	else
	{
		var xhr = new ajaxObject();
		// var url = "http://"+document.domain+"/jsProd/"+name+"/"+mail+"/"+phone+"/"+section+"/"+(mailing == 1 ? 1 : 0);
		var url = "http://"+document.domain+"/contact.php?do=prodSend&name="+name+"&mail="+mail+"&phone="+phone+"&cell="+section+"&content="+cont+"&mailing="+(mailing ? 1 : 0);
		xhr.open("GET", url, true);
		
		xhr.onreadystatechange = function() {//Call a function when the state changes.
			if(xhr.readyState == 4 && xhr.status == 200) {
				document.getElementById('order').innerHTML = xhr.responseText;
				if ($('#shortFormCont').legnth > 0) setInterval("jQuery('#shortFormCont').slideUp('slow')", 2500);
			}
		}
		registerConversion('1049687762','Q4G0CNCakwIQ0u3D9AM','0');
		xhr.send(null);
	}
}

var lastid = '';
function showHide(id)
{
	// jQuery.noConflict();
	if (lastid && lastid != id) $('#'+lastid).toggle('fast');
	lastid = id;
	jQuery('#'+id).toggle('fast');
}

function chngImg(img)
{
	document.getElementById('mainPic').src = img;
}
