var http = httpGetObject();

// Make sure file is not hosted in a different frameset
//if(top.location.href != window.location.href){
//	top.location.href = window.location.href
//}

function openWindow(url, w, h) {
	var windowprops = "width=" + w + ",height=" + h +",,left=10,top=10,scrollbars=no,status=yes,toolbar=no,location=no,directories=no,resizable=yes";
	popup = window.open(url,'newWin',windowprops);
	popup.focus();
}

function doBlink()
{
  // Blink, Blink, Blink...
  var blink = document.all.tags("BLINK")
  for (var i=0; i < blink.length; i++)
    blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : ""
}

function startBlink()
{
  // Make sure it is IE4
  if (document.all)
    setInterval("doBlink()",1000)
}
window.onload = startBlink;

function openPicture(pic,w,h) {

	var windowprops = "left=160,top=100,scrollbars=no,status=yes,toolbar=no,location=no,directories=no,resizable=yes,width=" + w + ",height=" + h;

	picture = window.open('','newPicture',windowprops);
	picture.close();
	picture = window.open('','newPicture',windowprops);
	picture.focus();

	picture.document.write("<html><head><title>Picture<\/title><\/head><body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>")
	picture.document.writeln("<img src=" + pic + " width=" + w + " height=" + h + ">")
	picture.document.write("<\/body><\/html>")
}

function showdate(){
	// Determine the current date and display it
   	var today = new Date();
   	var day = today.getDay();
   	var date = today.getDate();
   	var month = today.getMonth();
   	var year = today.getFullYear();

	//January,February,March,April,May,June,July,August,September,October,November,December
   	if (month == 0) {month='Jan'};
   	if (month == 1) {month='Feb'};
   	if (month == 2) {month='Mar'};
   	if (month == 3) {month='Apr'};
   	if (month == 4) {month='May'};
   	if (month == 5) {month='Jun'};
   	if (month == 6) {month='Jul'};
   	if (month == 7) {month='Aug'};
   	if (month == 8) {month='Sept'};
   	if (month == 9) {month='Oct'};
   	if (month == 10) {month='Nov'};
   	if (month == 11) {month='Dec'};

   	if (day == 0) {day='Sunday'};
   	if (day == 1) {day='Monday'};
   	if (day == 2) {day='Tuesday'};
   	if (day == 3) {day='Wednesday'};
   	if (day == 4) {day='Thursday'};
   	if (day == 5) {day='Friday'};
   	if (day == 6) {day='Saturday'};

   if ( document.all ) {
		document.write ('<span class="small">&nbsp;&nbsp;' + day + ', ' + month +  ' ' + date + ', ' + year + '</span>');
	} else {
		document.write ('<span class="smallNC">&nbsp;&nbsp;' + day + ', ' + month +  ' ' + date + ', ' + year +  '</span>');
	}
}

function switchClass(obj,strClassName) {
	obj.className	= strClassName;
}

function gotoURL(strUrl) {
	location = strUrl;
}

function copyrightYear(startYear){
		d = new Date();

		if (startYear != d.getFullYear())
			{
			return startYear + " - " + d.getFullYear();
			}
		else
			{
			return startYear;
			}
	}

	// Show current date in format "Nov 15, 2003".
function nsDate()
{
		// Get today's date.
	var sDate = new Date();
	var sToday = "";

		// Array with months.
	var aMonths = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

		// Get current month.
	var iMonth = sDate.getMonth();

		// Get current hour,minute,second.
	var iHours   = sDate.getHours();
	var iMinutes = sDate.getMinutes();
	var iSeconds = sDate.getSeconds();

	sToday = "";
		// Get today's date string.
	sToday += aMonths[iMonth] + " ";
	sToday += sDate.getDate() + ", ";
	sToday += sDate.getFullYear() + " ";

		// Display the date on the screen.
	document.write("<b>"+sToday+"</b>");
}

	// Get the current date in format "Nov 15, 2003  12:53:23 pm".
function today()
{
	var ie4=document.all;
    var ns4=document.layers;
    var ns6=document.getElementById&&!document.all;

		// Get today's date.
	var sDate = new Date();
	var sToday = "";

		// Array with months.
	var aMonths = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

		// Get current month.
	var iMonth = sDate.getMonth();

		// Get current hour,minute,second.
	var iHours   = sDate.getHours();
	var iMinutes = sDate.getMinutes();
	var iSeconds = sDate.getSeconds();

		// If iHour > 12.
	if(iHours>12)
		iHours = iHours - 12;

	if(iMinutes < 10)
		iMinutes = "0" + iMinutes;

	if(iSeconds < 10)
		iSeconds = "0" + iSeconds;

	sToday = "";
		// Get today's date string.
	sToday += aMonths[iMonth] + " ";
	sToday += sDate.getDate() + ", ";
	sToday += sDate.getFullYear() + " ";

	sToday += iHours + ":";
	sToday += iMinutes + ":" ;
	sToday += iSeconds;


		// Set am or pm
	if(sDate.getHours() < 12)
		sToday += " am ";
	else
		sToday += " pm ";

		// Display the date on the screen.

		// Write the clock to the layer:
	if (ns4)
	{
		return;
	}
	else
		if (ie4)
		{
			document.getElementById("LiveClock").innerHTML = "<b>"+sToday+"</b>";
		}
		else
			if (ns6)
			{
				document.getElementById("LiveClock").innerHTML = "<b>"+sToday+"</b>";
            }

		setTimeout("today()",1000);
		//window.setInterval(today(),100);
}

function FillQuantity(cardID, form) {
	/*
	var cardQty = prompt('How many copies woud you like (min 50)?', '50');

	if (cardQty == null) {
		// cancel
		return false;
	}
	*/
	cardQty = form.Qty.value;

	if (cardQty > 0 && cardQty != '') {

		re = new RegExp('^[0-9]+$');
		if(!re.test(cardQty)) {
			alert('Please enter integer for the quantity.');
			return false;
		}

		if ( cardQty < 1 ) {
			alert('Please enter a valid number greater than 1.');
			return false;
		}


		//form.action .indexOf('&qty=');

		// add quantity to form action attribute
		form.action = form.action + '&qty=' + cardQty;

		return true;

	} else {
		alert('Please enter quantity.');
		return false;
	}

	return false;
}

function openWindow2(url,wname,w,h,props)
{
	var winTop=(screen.height-h)/2;
	var winLeft=(screen.width-w)/2;

	var windowprops = "width=" + w + ",height=" + h +",left="+winLeft+",top="+winTop+","+props;
	return window.open(url,wname,windowprops);
}

/*
* change image source
*
* @param string mainImageId - image id
* @param string imageUrl - url of the image that have to be put as a sourse to original image
*/
function changeMainImage(mainImageId, imageUrl) {
	var mainImage = document.getElementById(mainImageId);
	if (mainImage) {
		// change image source to imageUrl
		mainImage.src = imageUrl;
	}
}

function ShowHideElement(elemID, displayType) {
	var obj = document.getElementById(elemID);
	if (obj) {
		if (obj.style.display == 'none') {
			obj.style.display = displayType;
		} else {
			obj.style.display = 'none';
		}
	}
}

function ShowElem(elemID) {
	var obj = document.getElementById(elemID);
	if (obj) {
		obj.style.display = 'block';
	}
}

function SetElemValue(elemID, elemValue) {
	var obj = document.getElementById(elemID);
	if (obj) {
		obj.value = elemValue;
	}

}

/*
function existingZIP(val){
	if(http){
		xmlUrl = '/existingzip.php?zipcode=' + val;
		http.open('GET', xmlUrl, false);
		http.send(null);
		return !!parseInt(http.responseText);
	} else {
		alert('httpGetObject does not exist');
		return false;
	}
}
*/

function uncheck(theRadio)
{
	if(theRadio.getAttribute("wasChecked") == "true")
	{
		theRadio.checked = false;
		theRadio.setAttribute("wasChecked","false");
	}
	else
	{
		theRadio.setAttribute("wasChecked","true");
	}
}

function AddFavourite(prom, btn, tr)
{
	url = './search-segments.php?AjaxCMD=add-favourite&aID=' + prom;
	http.open('GET', url, false);
	http.send(null);

	btn.style.display = 'none';
	tr.style.display = '';
}

/*var xmlhttp;
if (window.XMLHttpRequest)
{
	// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
	// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
	alert("Your browser does not support XMLHTTP!");
}*/

function CloseBox()
{
	$.fancybox.close();
}

function ParentCloseBox()
{
	parent.$.fancybox.close();
}

function IncrementCounter(prom)
{

	strrpos = prom['href'].indexOf("aid");
	if (strrpos > 0)
	{

		strrpos = strrpos + 4;
		strlen = prom['href'].length - strrpos;

		aID = (prom['href'].substring(strrpos, strrpos + strlen));


		var rand_no = Math.random();

		url = './search-segments.php?AjaxCMD=update-counter&aID=' + aID + '&randNum=' + rand_no;

		//alert(url);
		http.open('GET', url, false);
		http.send(null);
		res = http.responseText;
		//alert(res);
		//aOptions = unserialize(res);
	}
}

function ChangeFocus(obj, ekeyCode)
{
	var num = parseInt(obj.name.replace("cCode", ""));

	if (ekeyCode == 37 || ekeyCode == 8)
	{
		num = (num == 1) ? 1 : (num - 1);
	}
	else if (ekeyCode != 9)
	{
		num = (num != 8) ? (num + 1) : 8;
	}

	if (ekeyCode == 8)
	{
		document.getElementById("cCode" + num).value = '';
	}
	document.getElementById("cCode" + num).select();
}



$(document).ready(function()
{
	$("a[id^=tip]").fancybox
	(
		{
		'width'				: 980,
		'height'			: 1000,
		'autoScale'     	: true,
		'type'				: 'iframe',
		'onClosed'			:  function()
			{
				//fixing fancy box bug.
				IncrementCounter(this);
			}
		}
	);

	$("a[id^=miniTip]").fancybox
	(
		{
		'width'				: 960,
		'height'			: 450,
		'autoScale'     	: true,
		'type'				: 'iframe',
		'autoDimensions'	: false,
		/*'width'         	: 940,
		'height'        	: 'auto',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',*/
		'onClosed'			:  function()
			{
				//fixing fancy box bug.
				IncrementCounter(this);
				//alert('w');
			}
		}
	);

	$(".multiple").fancybox
	(
		{
		'autoDimensions'	: true,
		'width'				: 450,
		'height'			: 500,
		'autoScale'     	: true,
		'type'				: 'iframe'
		}
	);

	$("a[id$=lands]").fancybox
	(
		{
		'autoDimensions'	: true,
		'autoDimensions'	: false,
		'width'         	: 800,
		'height'        	: 'auto',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
		}
	);
	
	$(".bannerText").fancybox
	(
		{					
		'width'				: 600,
		'height'			: 170,
		'autoScale'     	: true,
		'type'				: 'iframe'
		}
	);

	$(".contactinfo1").fancybox
	(
		{
		'autoDimensions'	: false,
		'width'         	: 960,
		'height'        	: 'auto',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
		}
	);

	$("a[id$=contactinfo]").fancybox
	(
		{
		'autoDimensions'	: false,
		'width'         	: 960,
		'height'        	: 'auto',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
		}
	);

	$(".registeruser").fancybox
	(
		{
		'width'				: 940,
		'height'			: 440,
		'autoScale'     	: true,
		'type'				: 'iframe'
		}
	);

	$("a[id$=correction]").fancybox
	(
		{
		'width'				: 600,
		'height'			: 280,
		'autoScale'     	: true,
		'type'				: 'iframe'
		}
	);

	$("#login").fancybox
	(

		{
		'width'				: 600,
		'height'			: 280,
		'autoScale'     	: true,
		'type'				: 'iframe'
		}
	);

	$("#activateSubs").fancybox
	(

		{
		'width'				: 700,
		'height'			: 320,
		'autoScale'     	: true,
		'type'				: 'iframe',
		'onClosed'			:  function()
			{
				//alert('a');
				document.location = './index.php';
			}
		}
	);

	$("#login1").fancybox
	(
		{
		'width'				: 600,
		'height'			: 300,
		'autoScale'     	: true,
		'type'				: 'iframe'
		}
	);

	$("a[id$=checkView]").fancybox
	(
		{
		'width'				: 520,
		'height'			: 180,
		'autoScale'     	: true,
		'type'				: 'iframe'
		}
	);

	
	
	$(".btnDeleteAdv").hover(
		function()
		{
			var elemID = "#ttDeleteBtn" + this["id"].replace('deletebtn', '');
			$(elemID).fadeIn();
		},

		function()
		{
			var elemID = "#ttDeleteBtn" + this["id"].replace('deletebtn', '');
			$(elemID).fadeOut();
		}
	);
	
});



function showText(id, show) {
	var divText = document.getElementById(id);
	if(show == 1) {
		$(divText).slideDown(300);
	} else {
		$(divText).slideUp(300);
	}
}

function AreaSelected2(cmbArea)
{
	document.myform1.Lands.disabled = true;
	document.myform1.Lands.options.length = 0;
	//document.myform1.Lands.options[0] = new Option('всички', '', false, false);
	document.myform1.Lands.options[0] = new Option('избери', '', false, false);

	document.myform1.Regions.options.length = 0;
	//document.myform1.Regions.options[0] = new Option('всички', '', false, false);
	document.myform1.Regions.options[0] = new Option('избери', '', false, false);

	document.myform1.aAreasValue.value = cmbArea.value;

	if (cmbArea.value != "")
	{

		document.myform1.Regions.disabled = false;

		url = './search-segments.php?AjaxCMD=selectRegions&id=' + cmbArea.value;
		http.open('GET', url, false);
		http.send(null);
		res = http.responseText;

		aOptions = unserialize(res);
		i = 1;

		for(key in aOptions)
		{
			document.myform1.Regions.options[i] = new Option(aOptions[key], key, false, false);
			i++;
		}

		document.myform1.Regions.value = '';
		//document.myform1.aLandsValue.value = "";
		ChangeToolTip2();
	}
	else
	{
		document.myform1.Regions.disabled = true;
		document.getElementById('trSearchHelpText').style.display = 'none';		
	}
	
	return false;
}


function RegionSelected2(cmbRegion)
{
	document.myform1.Lands.options.length = 0;
	//document.myform1.Lands.options[0] = new Option('всички', '', false, false);
	document.myform1.Lands.options[0] = new Option('избери', '', false, false);

	if (cmbRegion.value != "")
	{
		document.myform1.Lands.disabled = false;

		url = './search-segments.php?AjaxCMD=selectLands&id=' + cmbRegion.value;
		http.open('GET', url, false);
		http.send(null);
		res = http.responseText;

		aOptions = unserialize(res);
		i = 1;


		for(key in aOptions)
		{
			document.myform1.Lands.options[i] = new Option(aOptions[key], key, false, false);
			i++;
		}

		document.myform1.aRegionsValue.value = cmbRegion.value;
	}
	else
	{
		document.myform1.Lands.disabled = true;
		document.myform1.aRegionsValue.value = "";
		document.myform1.aLandsValue.value = "";
	}

	//LandSelected2(document.myform1.Lands);
	
	ChangeToolTip2();
	
	return false;
}

function ChangeToolTip2()
{
	
	var cmbRegions = document.myform1.Regions;
	//alert(document.myform1.aLandsValue.value);
	//if (document.myform1.aLandsValue.value == "") {
		
		document.getElementById('topTooltip').innerHTML  = (cmbRegions.value != '')
		 	? "Съвет: За да видите купувачите на земя и арендатори по землища, изберете конкретно землище!"
			: "Съвет: За да видите  купувачите на земя и арендатори по  землища, изберете конкретна община и землище!";		
		//document.myform1.aLandsValue.value = "";
		document.getElementById('trSearchHelpText').style.display = '';
	//}
}

function LandSelected2(cmbLand)
{
	var cmbRegions = document.myform1.Regions;	
			
	if (cmbLand.value != "")
	{
		document.myform1.aLandsValue.value = cmbLand.value;
		document.getElementById('trSearchHelpText').style.display = 'none';
	}
	else
	{
		document.getElementById('topTooltip').innerHTML  = (cmbRegions.value != '')
		 	? "Съвет: За да видите купувачите на земя и арендатори по землища, изберете конкретно землище!"
			: "Съвет: За да видите  купувачите на земя и арендатори по  землища, изберете конкретна община и землище!";		
		document.myform1.aLandsValue.value = "";
		document.getElementById('trSearchHelpText').style.display = '';
	}
}

function CheckAreaSelected2(frm)
{
	if(frm.Areas.value == '') {
		alert('Моля, изберете област.');
		return false;
	}

	return true;

}

function limitText(limitField, limitNum)
{
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    }
}














function ShowHiddeTooltip(show)
{
	if (show) {
		$("#ttCompany").fadeIn();
	}
	else {
		$("#ttCompany").fadeOut();
	}
	//$("#ttCompany").Stop();
}

function ppShowHide(id,f)
{
	if (f==1){$("#"+id).fadeIn();}
	if (f==0){$("#"+id).fadeOut();}
}

function ppShowHidePriceToolTip(input,id,f)
{
	if (f==1)
	{
		var aURL = input.value;
		var aPosition = aURL.indexOf(",");
		if (aPosition > -1)
		{
			$("#"+id).fadeIn();
		}
		else
		{
			$("#"+id).fadeOut();
		}
	}
	if (f==0){$("#"+id).fadeOut();}
}

function ppShowHideUrgently(id,f)
{
	if (f==1){$("#"+id).fadeIn();}
	if (f==0){$("#"+id).fadeOut();}
}


$(document).ready(
	function()
	{
		/*
		$("#divVIP").hover(
			function()
			{
				//
				if($("#supperOffersCountValue").val() == 10 && $("#aVIP").is(':checked'))
				{

				}
				else
				{
					$("#ttUrgently").fadeIn();
				}
			},

			function()
			{
				$("#ttUrgently").fadeOut();
			}
		);
		*/

 	}
 );





