﻿function SubmitForm(formName)
{
    document.forms.item(formName).s
}

function startQuickPropertySearch() {
    var watermark = ScriptFX.UI.Behavior.getNamedBehavior($('MaxPrice'), 'watermark');
    var isValid = !watermark.get_isWatermarked();
    
    //$('nameValidator').style.visibility = isValid ? 'hidden' : 'visible';
    if (!isValid) {
        return false;
    }

}

function OpenGameWithTracking(url, trackerId)
{
    //
    // send
    //
    $.post("http://localhost/Trivia.Web.SkilledPartners/clickpost.ashx?trackerId="+trackerId);
	 
     windowprops = "width=" + (screen.width-10) + ",height=" + (screen.height-50) + ",top=0,left=0,resizable=no,toolbar=no,scrollbars=no,location=no,menubar=no,status=no";
	 
	 gameWnd = window.open(url ,"Game", windowprops);
	 if(gameWnd != null)
	    gameWnd.focus();
	 else
	    alert('Game window is blocked by popup blocker');
}



function ShowHideProperty(id)
	{			                       
	    var url = "/Property/Living/Any/Any/ShowProperty";     
        var height = "350" + "px"  
        var themeParameter ='&themeFolder=';
        var showBanenrsParameter = "";
        
        if (document.getElementById("row_"+id).style.display=="none") {
            document.getElementById("row_"+id).style.display = "";
            document.getElementById("span_"+id).innerHTML="<IFrame src='"+url+"?"
               + "PropertyID="+id+"' width='100%' height='"+ height +"' scrolling='no' frameborder='0' style='text-align:center;'></IFrame>";                                         
        }
        else {
            document.getElementById("row_"+id).style.display = "none";
            document.getElementById("span_"+id).innerHTML="";
		}
	}
	
	function ShowHideProperty1(id)
	{			                       
	    var url = "/Property/Living/Any/Any/ShowProperty";     
        var height = "350" + "px"  
        var themeParameter ='&themeFolder=';
        var showBanenrsParameter = "";

        if (document.getElementById("row_"+id).style.display=="none")
        {
            $(document).ready(function() {
            $('#td_'+id).html('<div style=text-align:center;height:30px;>Пожалуйста подождите...</div>')
            $('#row_'+id).css('display','');
            $('#td_'+id).load(url + '?PropertyID='+id + '&tick=' + new Date().getTime());
            
             });
        }
        else {

            document.getElementById("row_"+id).style.display = "none";
            document.getElementById("td_"+id).innerHTML="";
		}
	}
	
function OpenForPrint(id)
{
     var url = "/Property/Living/Any/Any/PrintProperty/?PropertyID="+id;
     windowprops = "width=800,height=450,top=0,left=0,resizable=no,toolbar=no,scrollbars=no,location=no,menubar=no,status=no"; 
     var printwindow = window.open(url,"Печать",windowprops);
     printwindow.focus(); 
}

function OpenCompanyForPrint(company)
{
     var url = "/Company/Print/"+company;
     windowprops = "width=800,height=450,top=0,left=0,resizable=no,toolbar=no,scrollbars=no,location=no,menubar=no,status=no"; 
     var printwindow = window.open(url,"Печать",windowprops);
     printwindow.focus(); 
}


function OpenMap(city, address)
{
     var url = "/Home/ShowMap?city="+city + "&address=" + address;
     windowprops = "width=800,height=450,top=0,left=0,resizable=no,toolbar=no,scrollbars=no,location=no,menubar=no,status=no"; 
     var printwindow = window.open(url,"Карта",windowprops);
     printwindow.focus(); 
}		
	
	
function ChangeDeal(sender)
{
	var sender = document.getElementById(sender);
	
	if(sender.options[sender.selectedIndex].value == 1) // let
	{
		span_dailyprice.style.display = 'inline';
	}
	else // sell
	{
		//not text-link
		span_dailyprice.style.display = 'none';
	}
}

function switchDummy(e, target)
{
	var src;
	if (!e) var e = window.event;
	if (e.target) src = e.target;
	else if (e.srcElement) src = e.srcElement;
	if (src.nodeType == 3) // defeat Safari bug
		src = targ.parentNode;
	
	target = document.getElementById(target);
	src.style.display = 'none';
	target.style.display = 'inline';
	target.focus();	
}

function switchReal(e, target)
{
	var src;
	if (!e) var e = window.event;
	if (e.target) src = e.target;
	else if (e.srcElement) src = e.srcElement;
	if (src.nodeType == 3) // defeat Safari bug
		src = targ.parentNode;
		
	if(src.value != '')
		return;
	
	var target = document.getElementById(target);
	src.style.display = 'none';
	target.style.display = 'inline';
}

function toggleCheckboxes(checkbox)
{
    var isChecked = checkbox.checked;
    var form = document.forms[0];
    
    for(i=0; i < form.length; i++)
    {
        if(form[i] != undefined)
        {
            if(form[i].name.indexOf('messageCheck') != -1)
            {
                form[i].checked = isChecked;
            }
        }
    }
}

function Search()
{
    if($('#SearchQuery').val() == 'Your query')
        return;
    $('#MainSearchFRM').submit();
}


function DeleteCollection(id, name) {
  var response = confirm('Are you sure you want to remove '+ name + '?');
  if(response)
  {
      $.getJSON('/Collection/Remove/'+ id, function(data) {
            switch(data[0].Code)
            {
               
                case 1:
                      $('#CollectionItem_'+ id).remove();
                      $('#CollectionItemHL_'+ id).remove();
                    break;
                default:
                    alert("Error while deleting");
                    break;
            }
        });
  }  
   	
};


function UserLoggedIn()
{
    if($('#Auth').val()=='')
        return false;
    return true;
}

function UserIsOwner()
{
    if($('#Owner').val()=='')
        return 0;
    return 1;
}


function getElementWidth(objectId) {
	x = document.getElementById(objectId);
	return x.offsetWidth;
}

function getAbsoluteLeft(objectId) {
	// Get an object left position from the upper left viewport corner
	o = document.getElementById(objectId)
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	return oLeft
}

function getAbsoluteTop(objectId) {
	// Get an object top position from the upper left viewport corner
	o = document.getElementById(objectId)
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	return oTop
}

function submitenter(myfield,e)
{
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;

    if (keycode == 13)
       {
       myfield.form.submit();
       return false;
       }
    else
       return true;
}


//function UrlAction(action, controller)
//{
//    
//}