//AJAX Functions
var SITEURL='http://www.icm-projects.com/';


function createXMLHttp() 
{

    if (typeof XMLHttpRequest != "undefined") 
	{
        return new XMLHttpRequest();
    } 
	else if (window.ActiveXObject) 
	{
      	var aVersions = [ "MSXML2.XMLHttp.5.0",
        "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
       	"MSXML2.XMLHttp","Microsoft.XMLHttp"
      	];

      	for (var i = 0; i < aVersions.length; i++) 
		{
        	try 
			{
            	var oXmlHttp = new ActiveXObject(aVersions[i]);
           		return oXmlHttp;
        	} 
			catch (oError) 
			{
            	//Do nothing
        	}
      	}
   	}
    throw new Error("XMLHttp object could be created.");
}



function sendGetRequest(url, func) 
{
    var oXmlHttp = createXMLHttp();
    oXmlHttp.open("get", url, true);

    oXmlHttp.onreadystatechange = function () 
	{
        if (oXmlHttp.readyState == 4) {

            if (oXmlHttp.status == 200) {
			       	var result = JSON.parse(oXmlHttp.responseText);
                eval(func + "(result);");
            } else {
                alert("An error occurred: "+ oXmlHttp.statusText);
            }
        }
    };
    oXmlHttp.send(null);
}

function sendGetRequest_sync(url, func) 
{
    var oXmlHttp = createXMLHttp();
    oXmlHttp.open("get", url, false);

    oXmlHttp.onreadystatechange = function () 
	{
        if (oXmlHttp.readyState == 4) {

            if (oXmlHttp.status == 200) {
			       	var result = JSON.parse(oXmlHttp.responseText);
                eval(func + "(result);");
            } else {
                alert("An error occurred: "+ oXmlHttp.statusText);
            }
        }
    };
    oXmlHttp.send(null);
}


function getSmallThumbs(id,dev,ord,param)
{ 
	sendGetRequest(SITEURL+'server/get_small_thumbs.php?id='+id+'&dev='+dev+'&ord='+ord+'&param='+param, 'showSmallThumbs');	
}

function checkPartner(logout)
{
	if ($('user')) var user=$('user').value;
	else var user='';
	
	if ($('pass')) var pass=$('pass').value;
	else var pass='';
	
	sendGetRequest(SITEURL+'server/check_partner.php?user=' + user +'&pass='+ pass +'&logout='+logout, 'LogedInPartner');	
}

function checkCode(writeCode)
{ 
	sendGetRequest(SITEURL+'server/codeCheck.php?code=' + writeCode, 'Myval');		
}

function setSearchFileds(par,type_apartmentid,cityid,complexid)
{ 
	sendGetRequest(SITEURL+'server/setSearchFields.php?par=' + par+'&type_apartmentid='+type_apartmentid+'&cityid='+cityid+'&complexid='+complexid, 'showSearchFileds');		
}


function PropertySearch(lang,url)
{
	var type_property=$('search_type_apartment').value;
	var city=$('search_city').value;
	var complex=$('search_complex').value;
	var type=$('search_deal').value;
	var min_price=$('search_price').value;
	if (!parseFloat(min_price))  min_price=0;
	window.location.href=SITEURL+lang+'/'+parseInt(type_property)+'_'+parseInt(city)+'_'+parseInt(complex)+'_'+parseInt(type)+'_'+parseFloat(min_price)+'/'+url+'.html';
}

function SetMapItem(cityid,position1,position2)
{ 
	sendGetRequest(SITEURL+'server/get_map_item.php?cityid='+cityid+'&position1='+position1+'&position2='+position2 , 'showGoogleMap');
}

function showGoogleMap(aMapItems)
{
	var data ='';
	//<![CDATA[';

	if (aMapItems.length>0)
	{
		
		some=aMapItems[0];
		var map = new GMap2(document.getElementById("map"));
		//var start = new GLatLng(65,25);
		map.setCenter(new GLatLng(parseFloat(some.position1),parseFloat(some.position2)), 15);
		map.addControl(new GMapTypeControl(1));
		map.addControl(new GLargeMapControl());
		
		map.enableContinuousZoom();
		map.enableDoubleClickZoom();
		map.setMapType(G_HYBRID_TYPE) ;
		
		
		// "tiny" marker icon
		var icon = new GIcon();
		icon.image = SITEURL+"images/map_icons/office.gif";
		icon.shadow = SITEURL+"images/map_icons/shadow.png";
		icon.iconSize = new GSize(26,26);
		icon.shadowSize = new GSize(28,26);
		icon.iconAnchor = new GPoint(16,26);
		icon.infoWindowAnchor = new GPoint(16,0);
		
		
		var airport = new GIcon(); //1
		airport.image = SITEURL+"images/map_icons/airport.gif";
		airport.shadow = SITEURL+"images/map_icons/shadow.png";
		airport.iconSize = new GSize(24,24);
		airport.shadowSize =  new GSize(28,26);
		airport.iconAnchor = new GPoint(16,26);
		airport.infoWindowAnchor = new GPoint(16,0);
		
		
		var apteka = new GIcon(); //2
		apteka.image = SITEURL+"images/map_icons/apteka.gif";
		apteka.shadow = SITEURL+"images/map_icons/shadow.png";
		apteka.iconSize = new GSize(24,24);
		apteka.shadowSize =  new GSize(28,26);
		apteka.iconAnchor = new GPoint(16,26);
		apteka.infoWindowAnchor = new GPoint(16,0);
		
		var bus = new GIcon(); //3
		bus.image = SITEURL+"images/map_icons/bus.gif";
		bus.shadow = SITEURL+"images/map_icons/shadow.png";
		bus.iconSize = new GSize(24,24);
		bus.shadowSize =  new GSize(28,26);
		bus.iconAnchor = new GPoint(16,26);
		bus.infoWindowAnchor = new GPoint(16,0);
		
		var gas = new GIcon(); //4
		gas.image = SITEURL+"images/map_icons/gas.gif";
		gas.shadow = SITEURL+"images/map_icons/shadow.png";
		gas.iconSize = new GSize(24,24);
		gas.shadowSize =  new GSize(28,26);
		gas.iconAnchor = new GPoint(16,26);
		gas.infoWindowAnchor = new GPoint(16,0);
		
		var hospital = new GIcon(); //5
		hospital.image = SITEURL+"images/map_icons/hospital.gif";
		hospital.shadow = SITEURL+"images/map_icons/shadow.png";
		hospital.iconSize = new GSize(24,24);
		hospital.shadowSize = new GSize(28,26);
		hospital.iconAnchor = new GPoint(16,26);
		hospital.infoWindowAnchor = new GPoint(16,0);
		
		var kinderkarten = new GIcon(); //6
		kinderkarten.image = SITEURL+"images/map_icons/kinderkarten.gif";
		kinderkarten.shadow = SITEURL+"images/map_icons/shadow.png";
		kinderkarten.iconSize = new GSize(24,24);
		kinderkarten.shadowSize = new GSize(28,26);
		kinderkarten.iconAnchor = new GPoint(16,26);
		kinderkarten.infoWindowAnchor = new GPoint(16,0);
		
		var police = new GIcon(); //7
		police.image = SITEURL+"images/map_icons/police.gif";
		police.shadow = SITEURL+"images/map_icons/shadow.png";
		police.iconSize = new GSize(24,24);
		police.shadowSize = new GSize(28,26);
		police.iconAnchor = new GPoint(16,26);
		police.infoWindowAnchor = new GPoint(16,0);
		
		var post = new GIcon(); //8
		post.image = SITEURL+"images/map_icons/post.gif";
		post.shadow = SITEURL+"images/map_icons/shadow.png";
		post.iconSize = new GSize(24,24);
		post.shadowSize = new GSize(28,26);
		post.iconAnchor = new GPoint(16,26);
		post.infoWindowAnchor = new GPoint(16,0);
		
		var school = new GIcon(); //9
		school.image = SITEURL+"images/map_icons/school.gif";
		school.shadow = SITEURL+"images/map_icons/shadow.png";
		school.iconSize = new GSize(24,24);
		school.shadowSize = new GSize(28,26);
		school.iconAnchor = new GPoint(16,26);
		school.infoWindowAnchor = new GPoint(16,0);
		
		var supermarket = new GIcon(); //10
		supermarket.image = SITEURL+"images/map_icons/supermarket.gif";
		supermarket.shadow = SITEURL+"images/map_icons/shadow.png";
		supermarket.iconSize = new GSize(24,24);
		supermarket.shadowSize = new GSize(28,26);
		supermarket.iconAnchor = new GPoint(16,26);
		supermarket.infoWindowAnchor = new GPoint(16,0);
		
		var train = new GIcon(); //11
		train.image = SITEURL+"images/map_icons/train.gif";
		train.shadow = SITEURL+"images/map_icons/shadow.png";
		train.iconSize = new GSize(24,24);
		train.shadowSize = new GSize(28,26);
		train.iconAnchor = new GPoint(16,26);
		train.infoWindowAnchor = new GPoint(16,0);
		
		var office = new GIcon(); //12
		office.image = SITEURL+"images/map_icons/office.gif";
		office.shadow = SITEURL+"images/map_icons/shadow.png";
		office.iconSize = new GSize(24,24);
		office.shadowSize = new GSize(28,26);
		office.iconAnchor = new GPoint(16,26);
		office.infoWindowAnchor = new GPoint(16,0);
		
		var point = new GLatLng(parseFloat(some.position1),parseFloat(some.position2))
		var markerN = new GMarker(point, {icon:icon}); 
		map.addOverlay(markerN);
		
		
		for(var i=0;i<aMapItems.length;i++)
		{
			some=aMapItems[i];
			var ico=airport;
			var field_name='saved_airport_';
			var ff_tit='';
			if ((parseFloat(some.pos1)>0) && (parseFloat(some.pos2)>0))
			{
				var point = new GLatLng(parseFloat(some.pos1),parseFloat(some.pos2));
				if (some.type==1) 
					ico=airport;
					
				if (some.type==2) 
					ico=apteka;
					
				if (some.type==3) 
					ico=bus;
					
				if (some.type==4) 
					ico=gas;
					
				if (some.type==5) 
					ico=hospital;
					
				if (some.type==6) 
					ico=kinderkarten;
					
				if (some.type==7) 
					ico=police;
					
				if (some.type==8) 
					ico=post;
					
				if (some.type==9) 
					ico=school;
					
				if (some.type==10) 
					ico=supermarket;
					
				if (some.type==11) 
					ico=train;
					
				if (some.type==12) 
					ico=office;
					
				 var marker_plan =  new GMarker(point, {icon:ico, title:some.title}); 
				 map.addOverlay(marker_plan);
			}
			
		}// and of for
		
		
	}


	
	
	//]]>
}


function saveForm(lg,par) 
{ 
	if (par==1)
	{
		var name = document.forms['enquire_form'].elements['enquire_name'].value;
		var phone = document.forms['enquire_form'].elements['enquire_phone'].value;
		var email = document.forms['enquire_form'].elements['enquire_email'].value;
		var message = document.forms['enquire_form'].elements['request_messege'].value;
		var propertiesid = document.getElementById('id').value;
		var dev = document.getElementById('dev').value;
		var fr_email='';
		var fr_name='';
		var code='';
	}
	
	if (par==2)
	{
		var name = document.forms['write'].elements['name'].value;
		var email= document.forms['write'].elements['email'].value;
		var fr_name = '';
		var fr_email= '';
		var propertiesid =0;
		var dev = 0;
		var phone='';
		var message=document.forms['write'].elements['notes'].value;
		var code=document.forms['write'].elements['code'].value;
	}
	
	sendGetRequest(SITEURL+'server/save_form.php?name='+name+'&phone='+phone+'&email='+email+'&message='+message+'&propertiesid='+propertiesid+'&fr_name='+fr_name+'&fr_email='+fr_email+'&par='+par+'&dev='+dev+'&code='+code, 'showSaveFormResults');	
}

function showSaveFormResults(aSaveInfo)
{
	if (aSaveInfo.length>0)	
	{
		some=aSaveInfo[0];	
		
		document.getElementById(some.div).innerHTML=some.mes;
	}
}

function LogedInPartner(aUserInfo)
{
	if (aUserInfo.length>0)
	{
		some = aUserInfo[0];	
		if ((some.loged==0) && (some.logout==0))
		{
			$('errors').innerHTML=some.err;
		}
		else	 
		{
			window.location.reload();
		}
	}
}


function Myval(aResult)
{
	a = parseInt(aResult)
	return a;
}

function showSearchFileds(aSearchFields)
{
	var data ='';
	if (aSearchFields.length>0)
	{
		some = aSearchFields[0];
		if (some.par==1)
		{
			data = data+'<select name="search_city" id="search_city" onchange="setSearchFileds(2,'+some.type_apartmentid+',this.value,0);" style="width:140px">';
			data = data+'<option value ="0">'+some.default_val+'</option>';
			if (some.name)
			{
				for (var i=0; i<aSearchFields.length;i++)
				{
					some = aSearchFields[i];
					data = data+'<option value ="'+some.id+'">'+some.name+'</option>';								
				}
			}
			data = data +'</select>';
			
			document.getElementById('search_city_span').innerHTML=data;
			
			setSearchFileds(2,some.type_apartmentid,0,0);
		}
		
		if (some.par==2)
		{
			data = data+'<select name="search_complex" id="search_complex" style="width:140px">';
			data = data+'<option value ="0">'+some.default_val+'</option>';
			if (some.name)
			{
				for (var i=0; i<aSearchFields.length;i++)
				{
					some = aSearchFields[i];
					data = data+'<option value ="'+some.id+'">'+some.name+'</option>';								
				}
			}
			data = data +'</select>';
			
			document.getElementById('search_complex_span').innerHTML=data;
			
		}
		
		
	}
}


function SetGalleryButtons(id,thumb,par,title)
{
	
	if ($('cat_id_1_sel'))
		$('cat_id_1_sel').value='';
	if ($('cat_id_2_sel'))
		$('cat_id_2_sel').value='';
	if ($('cat_id_3_sel'))
		$('cat_id_3_sel').value='';
	if ($('cat_id_4_sel'))
		$('cat_id_4_sel').value='';
	
	
	if ($('cat_id_1_a'))
		$('cat_id_1_a').className='';
	if ($('cat_id_2_a'))
		$('cat_id_2_a').className='';
	if ($('cat_id_3_a'))
		$('cat_id_3_a').className='';
	if ($('cat_id_4_a'))
		$('cat_id_4_a').className='';
	
	if(par==4)
	{
		var cityid = $('cityid').value;
		var position1 = $('map_position1').value;
		var position2 = $('map_position2').value;
		
		
		$('map_div').innerHTML='<div class="gallery_bottom"><div class="gallery_top"><div id="map" style="width:355px; height:360px;float:left;"></div></div></div>';
		$('map_div').style.display='block';
		$('g1').style.display='none';
		
		SetMapItem(cityid,position1,position2);
	}
	else 
	{
		$('g1').style.display='block';
		$('map_div').style.display='none';
		$('big_thumb').innerHTML='';
		$('small_thumbss').innerHTML='';
		if (par!=3) SetBigThumb(thumb,title,'');

		getSmallThumbs($('id').value,$('dev').value,'0',par);	
	}
		
	
	
	document.getElementById(id+'_a').className='featured_current';
	document.getElementById(id+'_sel').value='1';		
}

function SetPropertyButtons(id)
{
	if ($('property_details_div'))
		$('property_details_div').style.display='none';	
	if ($('region_details_div'))
		$('region_details_div').style.display='none';	
	if ($('on_site_amenties_div'))
		$('on_site_amenties_div').style.display='none';
	if ($('price_div'))
		$('price_div').style.display='none';
	if ($('request_form_div'))
		$('request_form_div').style.display='none';
	if ($('viewing_trips_div'))
		$('viewing_trips_div').style.display='none';
	
	if ($('property_details_div_sel'))
		$('property_details_div_sel').value='';
	if ($('region_details_div_sel'))
		$('property_details_div').value='';
	if ($('on_site_amenties_div_sel'))
		$('on_site_amenties_div_sel').value='';
	if ($('price_div_sel'))
		$('price_div_sel').value='';
	if ($('request_form_div_sel'))
		$('request_form_div_sel').value='';
	if ($('viewing_trips_div_sel'))
		$('viewing_trips_div_sel').value='';
	
	if ($('property_details_div_a'))
		$('property_details_div_a').className='';
	if ($('region_details_div_a'))
		$('region_details_div_a').className='';
	if ($('on_site_amenties_div_a'))
		$('on_site_amenties_div_a').className='';
	if ($('price_div_a'))
		$('price_div_a').className='';
	if ($('request_form_div_a'))
		$('request_form_div_a').className='';
	
	if ($('viewing_trips_div_a'))
		$('viewing_trips_div_a').className='';
	
	document.getElementById(id).style.display='block';	
	document.getElementById(id+'_a').className='featured_current';
	document.getElementById(id+'_sel').value='1';		
}


function SetFeaturedItems(id)
{
	
	if ($('featured_dev'))
		$('featured_dev').style.display='none';	
	if ($('featured_prop'))
		$('featured_prop').style.display='none';	
	if ($('latests_prop'))
		$('latests_prop').style.display='none';
	
	
	if ($('latests_prop_sel'))
		document.getElementById('latests_prop_sel').value='';
	if ($('featured_dev_sel'))
		document.getElementById('featured_dev_sel').value='';
	if ($('featured_prop_sel'))
		document.getElementById('featured_prop_sel').value='';
	
	if ($('latests_prop_a'))
		document.getElementById('latests_prop_a').className='';
	if ($('featured_dev_a'))
		document.getElementById('featured_dev_a').className='';
	if ($('featured_prop_a'))
		document.getElementById('featured_prop_a').className='';
	
	if ($(id))
		$(id).style.display='block';	
	if ($(id+'_a'))
		document.getElementById(id+'_a').className='featured_current';
	if ($(id+'_sel'))
		document.getElementById(id+'_sel').value='1';
	
	
}

function clearField(par,val)
{
	if(par==1)
		document.getElementById('search_price').value='';
	else
	{
		if (document.getElementById('search_price').value=='')
			document.getElementById('search_price').value=val;
	}
}



function toggle_classes(par,id)
{
	
 	if (par==1)
	{
		document.getElementById(id+'_a').className='featured_current';
	}
	else 
	{	
		if (document.getElementById(id+'_sel').value=='')
			document.getElementById(id+'_a').className='';
		//else 
			//document.getElementById(id+'_a').className='featured_current';
	}
} 


function SetBigThumb123(image,title,real_image)
{
	
	var d= document.getElementById('big_thumb');
	var div_big  = d;
	d.innerHTML = '<img src="'+image+'" alt="'+title+'" border="0"/>';
	
}

function showSmallThumbs(aSmallTh)
{
	var div_exc  = document.getElementById('small_thumbss');
	var data='';
	
	if (aSmallTh.length>0)
	{
		
		new Effect.Opacity(div_exc, Object.extend(
                                   {
                                        duration: 0.5, 
                                        from:1.0, 
                                        to:0.0,
                                        afterFinishInternal: function(effect) 
                                        {
                                            showSmallThumbsAgain(aSmallTh);
											new Effect.Appear(div_exc,  Object.extend({duration: 0.5}));
                                        }
                                   }
                                ));
	}
}
function showSmallThumbsAgain(aSmallTh)
{
	var div_small  = document.getElementById('small_thumbss');
	data='';
	if (aSmallTh.length>0)
	{
		data = data +'<ul class="gal">';					
		for (var i=0; i < aSmallTh.length; i++) 
		{
			some=aSmallTh[i];
			data = data +'<li><a onclick="SetBigThumb(\''+ some.bigg +'\',\''+ some.title +'\')" style="cursor:pointer;"><img src="'+ some.p +'" alt="'+some.title+'" class="gallery_img"/></a></li>';
			if (i==aSmallTh.length-1) 
			{
				data = data +'<input type="hidden" id="first" value="'+some.h+'">';
			}
			
		}
		data = data +'</ul>';
	}
	div_small.innerHTML = data;
}
function showSmallThumbs123(aSmallTh)
{
	var div_small  = document.getElementById('small_thumbss');
	var data1='';
	if (aSmallTh.length>0)
	{
		data1 = data1 +'<div style="background:red;">';
		for (var i=0; i < aSmallTh.length; i++) 
		{
			some=aSmallTh[i];
			if (some.param!=3)
			{
				var funct=' onclick="SetBigThumb(\''+ some.bigg +'\',\''+ some.title +'\',\''+ some.image +'\')"  style="cursor:pointer;"';
				
			}
			else 
				var funct=' href="'+some.bigg+'" target="_blank" ';
			data1 = data1 +'<a  '+funct+'><img src="'+ some.p +'" class="gallery_img" alt="'+some.title+'" width="113" height="79"/></a>';
			//var tt='onclick="alert(\''+ some.bigg +'\')"';
			//data1 = data1 +'<a  '+tt+'><img src="'+ some.p +'" class="gallery_img" alt="'+some.title+'" width="113" height="79"/></a>';
			if (i==aSmallTh.length-1) 
			{
				data1 = data1 +'<input type="hidden" id="first" value="'+some.h+'">';
				data1 = data1 +'<input type="hidden" id="current_param" value="'+some.param+'">';
				data1 = data1 +'<input type="hidden" id="all_r" value="'+some.all_r+'">';
			}
			
		}
		data1 = data1 +'</div>';
		
	}
	
	div_small.innerHTML = data1;
	
	
	
	
}

function setPrevNext(next)
{
	if( $('first')) var first=parseInt($('first').value);
	if (next==0) 
	{
		if((first-3)>=0)
			getSmallThumbs($('id').value,$('dev').value,first-3,$('current_param').value);
	}
	else 
	{
		if ( (first+3)< parseInt($('all_r').value) )
			getSmallThumbs($('id').value,$('dev').value,first+3,$('current_param').value);
		//else var ord =;
		
	}
}

function SetBigThumb(image,title)
{
	
	var div_big = document.getElementById('big_thumb');
	new Effect.Opacity(div_big, Object.extend(
                                   {
                                        duration: 0.5, 
                                        from:1.0, 
                                        to:0.0,
                                        afterFinishInternal: function(effect) 
                                        {
                                            SetBigThumbAgain(image,title);
											Effect.Appear(div_big,  Object.extend({duration: 0.5}));
                                        }
                                   }
                                ));
	
}
function SetBigThumbAgain(image,title)
{
	
	document.getElementById('big_thumb').innerHTML = '<img src="'+image+'" alt="'+title+'" width="250" height="167"/>';
}
//-------------------
/// ALL THING YOU NEED FOR REQUEST FORMSs

function valideRegistration(lg)
{
	
	var div=document.getElementById('reg_errors');
	var res='';
	var right=true;
	if (lg=='en')
	{
	
		var mes_name="Please input company name.<br />";
		var mes_contact_name="Please input contact name.<br />";
		var mes_phone="Please input phone number.<br />";
		var mes_address="Please input address.<br />";
		var mes_email="Please input your correct email.<br />";
		var mes_business="Please input type of business.<br />";
		var mes_password="Please input password.<br />";
		var mes_password_retype="Please re-type password.<br />";
		var mes_password_mis="The fields 'Password' and 'Re-type password' mismatch<br />";
		var mes_username="Please input username.<br />";
		var mes_website="Please input website.<br />";
	}
	if (lg=='bg')
	{

		var mes_name="Моля въведете име на компанията.<br />";
		var mes_contact_name="Моля въведете лице за контакти.<br />";
		var mes_phone="Моля въведете телефонен номер.<br />";
		var mes_address="Моля въведете адрес.<br />";
		var mes_email="Моля въведете коректен e-mail.<br />";
		var mes_business="Моля въведете тип бизнес на компанията.<br />";
		var mes_password="Моля въведете парола.<br />";
		var mes_password_retype="Моля повторете парола<br />";
		var mes_password_mis="Несъвпадение на поле 'Парола' и 'Повторете Парола'<br />";
		var mes_username="Моля въведете потребителско име.<br />";
		var mes_website="Моля въведете website.<br />";
	}
	
	if (lg=='ru')
	{

		var mes_name="Моля въведете име на компанията.<br />";
		var mes_contact_name="Моля въведете лице за контакти.<br />";
		var mes_phone="Моля въведете телефонен номер.<br />";
		var mes_address="Моля въведете адрес.<br />";
		var mes_email="Моля въведете коректен e-mail.<br />";
		var mes_business="Моля въведете тип бизнес на компанията.<br />";
		var mes_password="Моля въведете парола.<br />";
		var mes_password_retype="Моля повторете парола<br />";
		var mes_password_mis="Несъвпадение на поле 'Парола' и 'Повторете Парола'<br />";
		var mes_username="Моля въведете потребителско име.<br />";
		var mes_website="Моля въведете website.<br />";
	}
	
	if (document.forms['register'].elements['username'].value == "") 
	{
		res = res + mes_username;
		//document.forms['register'].elements['password'].className="input_fileds_wrong";
		right=false;
	}
	
	if (document.forms['register'].elements['password'].value == "") 
	{
		res = res + mes_password;
		//document.forms['register'].elements['password'].className="input_fileds_wrong";
		right=false;
	}
	
	if (document.forms['register'].elements['repeat_password'].value == "") 
	{
		res = res + mes_password_retype;
		//document.forms['register'].elements['password'].className="input_fileds_wrong";
		right=false;
	}
	
	if (document.forms['register'].elements['repeat_password'].value != document.forms['register'].elements['password'].value) 
	{
		res = res + mes_password_mis;
		//document.forms['register'].elements['password'].className="input_fileds_wrong";
		right=false;
	}
	
	if (document.forms['register'].elements['company'].value == "") 
	{
		res = res + mes_name;
		//document.forms['register'].elements['company'].className="input_fileds_wrong";
		right=false;
	}
	if (document.forms['register'].elements['business'].value == "") 
	{
		res = res + mes_business;
		//document.forms['register'].elements['business'].className="input_fileds_wrong";
		right=false;
	}
	if (document.forms['register'].elements['contact_name'].value == "") 
	{
		res = res + mes_contact_name;
		//document.forms['register'].elements['contact_name'].className="input_fileds_wrong";
		right=false;
	}
	if (document.forms['register'].elements['address'].value == "") 
	{
		res = res + mes_address;
		//document.forms['register'].elements['address'].className="input_fileds_wrong";
		right=false;
	}
	if (document.forms['register'].elements['phone'].value == "") 
	{
		res = res + mes_phone;
		//document.forms['register'].elements['phone'].className="input_fileds_wrong";
		right=false;
	}
	if (document.forms['register'].elements['email'].value == "" || echeck(document.forms['register'].elements['email'].value)==false) 
	{
		res = res + mes_email;
		document.forms['register'].elements['email'].value = "";
		//document.forms['register'].elements['email'].className="input_fileds_wrong";
		wrong=1;
	}
	
	
	if (document.forms['register'].elements['website'].value == "") 
	{
		res = res + mes_website;
		//document.forms['register'].elements['website'].className="input_fileds_wrong";
		right=false;
	}
	if (right===false)
	{
		res='<span style="color:red;font-size:14px;font-weight:bold">' + res+ '</span>';
		div.innerHTML=res;
	}
	
	return right;

}




function valideRegistration_special_offers(lg)
{
	
	var div=document.getElementById('reg_errors');
	var res='';
	var right=true;
	if (lg=='en')
	{
	
		var mes_contact_name="Please input contact name.<br />";
		var mes_email="Please input your correct email.<br />";
	}
	if (lg=='bg')
	{

		var mes_contact_name="Моля въведете лице за контакти.<br />";
		var mes_email="Моля въведете коректен e-mail.<br />";
		
	}
	
	if (lg=='ru')
	{

		var mes_contact_name="Моля въведете лице за контакти.<br />";
		var mes_email="Моля въведете коректен e-mail.<br />";
		
	}
	
	
	
	
	if (document.forms['register'].elements['contact_name'].value == "") 
	{
		res = res + mes_contact_name;
		//document.forms['register'].elements['contact_name'].className="input_fileds_wrong";
		right=false;
	}
	
	if (document.forms['register'].elements['email'].value == "" || echeck(document.forms['register'].elements['email'].value)==false) 
	{
		res = res + mes_email;
		document.forms['register'].elements['email'].value = "";
		//document.forms['register'].elements['email'].className="input_fileds_wrong";
		wrong=1;
	}
	
	
	return right;

}
	
function validate()
{
	if (document.forms['request'].elements['request_name'].value == "") 
	{
		alert("Please input Your Name.!");
		document.forms['request'].elements['request_name'].focus();
		return false;
	}
	
	if (document.forms['request'].elements['request_email'].value == "" || echeck(document.forms['request'].elements['request_email'].value)==false) 
	{
		alert("Please select correct e-mail address.!");
		document.forms['request'].elements['request_email'].value = "";
		document.forms['request'].elements['request_email'].focus();
		return false;
	}
	
	checkCode(document.forms['request'].elements['code'].value);
	a= Myval();
	alert("Message is sending");
	//alert(a);
	if ((a==0) || (!a)) 
	{
		alert("The code is not correct");
		document.forms['request'].elements['code'].focus();
		return false;
	}
	
							
	return true
}




function CheckAndGo()
{
	var checked = false;
	checked = validate();
	if (checked) 
	{
		//fader.fadeOut();
		sendRequest('request');
		document.forms['request'].reset();
		//closeRequest();
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}



function getRequestBody(oForm) 
{
    var aParams = new Array();

    for (var i=0 ; i < oForm.elements.length; i++) 
	{
        var sParam = encodeURIComponent(oForm.elements[i].name);
        sParam += "=";
        sParam += encodeURIComponent(oForm.elements[i].value);
        aParams.push(sParam);
    }

    return aParams.join("&");
}
	
function sendRequest( formm) 
{
	  
    var oForm = document.forms[formm];
    var sBody = getRequestBody(oForm);

    var oXmlHttp = createXMLHttp();
    oXmlHttp.open("post", oForm.action, true);
   	oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    oXmlHttp.onreadystatechange = function () 
	{
        if (oXmlHttp.readyState == 4) 
		{
            if (oXmlHttp.status == 200) 
			{
                //saveResult(oXmlHttp.responseText);
            } 
			else 
			{
                saveResult("An error occurred: "+ oXmlHttp.statusText);
           	}
        }
    };
    oXmlHttp.send(sBody);
}

function sendMailRequest(formName) 
{
    var oForm = document.forms[formName];
    var sBody = getRequestBody(oForm);

    var oXmlHttp = createXMLHttp();
    oXmlHttp.open("post", oForm.action, true);
   	oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    oXmlHttp.onreadystatechange = function () 
	{
        if (oXmlHttp.readyState == 4) 
		{
            if (oXmlHttp.status == 200) 
			{
                clearForm(oXmlHttp.responseText, formName);
            } 
			else 
			{
                clearForm("An error occurred: "+ oXmlHttp.statusText, formName);
           	}
        }
    };
    oXmlHttp.send(sBody);
}

function number_format(a, b, c, d) {
	// number_format(number, decimals, comma, formatSeparator)
	a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
	e = a + '';
	f = e.split('.');
	if(!f[0]) f[0] = '0';
	if(!f[1]) f[1] = '';
	if(f[1].length < b){
		g = f[1];
		for(i = f[1].length + 1; i <= b; i++) {
			g += '0';
		}
		f[1] = g;
	}
	if(d != '' && f[0].length > 3) {
		h = f[0];
		f[0] = '';
		for(j = 3; j < h.length; j += 3) {
			i = h.slice(h.length - j, h.length - j + 3);
			f[0] = d + i +  f[0] + '';
		}
		j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
		f[0] = j + f[0];
	}
	c = (b <= 0) ? '': c;
	return f[0] + c + f[1];
}

function setBigImg(url){

document.getElementById('big_img').src=url;

}

