var base = 'http://' + window.location.hostname
base += ( window.location.port != '' ) ? ':' + window.location.port + '/' : '/';
base += ( window.location.hostname.toLowerCase() == 'localhost'         ) ? 'Boards/'      : '';
base += ( window.location.hostname.toLowerCase() == 'www.go-lovely.com' ) ? 'boards-en/'   : '';
base += ( window.location.hostname.toLowerCase() == '212.179.58.92'     ) ? 'boards-en/'   : '';

function ShowHideMessage( obj, imgClose, imgOpen, src, iframeId )
{
    var detCls_icon = $Get( imgClose );
    var detOpn_icon = $Get( imgOpen );
    var oid = $Get( obj + "_Det" );
    var ifm = $Get( iframeId );
    
    if ( oid.style.display == 'none' )
    {
        oid.style.display = '';
        oid.style.visibility = 'visible';
        try {
            if ( ifm.src != src )
                ifm.src = src;
        }
        catch (e) {
            ifm.src = src;
        }
        detOpn_icon.style.display = 'none';
        detCls_icon.style.display = '';
    }
    else
    {
        var trHed = $Get( obj );
        trHed.className = trHed.className.replace('TrForClr','TrViewedForClr');
        oid.style.display = 'none';
        detOpn_icon.style.display = '';
        detCls_icon.style.display = 'none';
    }
}

function SetOrderForGrid( obj, hdOrder, btnOrder )
{
	var hid = $Get( hdOrder );
	var fld = obj.attributes.getNamedItem("Field").value;
	if ( hid.value.indexOf( fld ) < 0 )
	{
		if ( fld.indexOf( "Video" ) >= 0 || fld.indexOf( "Picture" ) >= 0 )
			hid.value = fld + ":>";
		else
			hid.value = fld + ":<";
	}
	else if ( hid.value.indexOf( '<' ) > 0 )
		hid.value = hid.value.replace( "<", ">" );
	else if ( hid.value.indexOf( '>' ) > 0 )
		hid.value = hid.value.replace( ">", "<" );
	$Get( btnOrder ).click();
}

function SetOrderSign()
{
	// To Avoid Hashpaa on other tables you can check the parent,
	// by identifying the first TR of each Grid.
	var hid = $Get( hdOrder ).value;
	if ( hid == '' )
		return;
	var hed = $Get( hid.split(":")[ 0 ] );
	if ( null == hed )
		return;
	if ( hid.indexOf( 'ASC' ) > 0 )
		hed.innerText = hed.innerText + '▼';
	else if ( hid.indexOf( 'DESC' ) > 0 )
		hed.innerText = hed.innerText + '▲';
	return false;
}

function GetPage( PageId, hdPageNum, btnPager )
{
	$Get( hdPageNum ).value = PageId;
	$Get( btnPager ).click();
}

function SetPageSize( PageSize, hdPageSize, hdPageNum )
{
	$Get( hdPageSize ).value = PageSize;
	$Get( hdPageNum ).value = 1;
}

/* Start *********************** Grid Result Selection Functions ***************************/
function OnAssetChecked( AdId, hdCheckedList )
{
    AdId = AdId.replace( "cb", "" );
    var CheckedList = $Get( hdCheckedList );
    if ( CheckedList.value.indexOf( "Q" + AdId + "Q" ) >= 0 )
        CheckedList.value = CheckedList.value.replace( "Q" + AdId + "Q", "" );
    else
        CheckedList.value += "Q" + AdId + "Q";
}

function ClearSelection( hdCheckedList )
{
    var hdList = $Get( hdCheckedList );
	//var selList = new Array();
	var cSelList = hdList.value.split("QQ");
	var AdCbId;
	var Cb;
	for ( var n = 0; n < cSelList.length; n++ ) 
	{
	    AdCbId = "cb" + cSelList[ n ].toString().replace( 'Q', '' ).replace( 'Q', '' );
	    Cb = $Get( AdCbId );
	    if ( Cb == null )
	        continue;
	    Cb.checked = false;
	}
    hdList.value = '';
}

function SelectAll( hdAdsIds, hdCheckedList )
{
    var AdsIds = $Get( hdAdsIds );
    var CheckedList = $Get( hdCheckedList );
	//var selList = new Array();
	var selList = AdsIds.value.split(",");
	var AdCbId;
	var Cb;
	for ( var n = 0; n < selList.length; n++ ) 
	{
	    AdCbId = "cb" + selList[ n ].toString();
	    Cb = $Get( AdCbId );
	    if ( Cb == null )
	        continue;
	    Cb.checked = true;

        if ( CheckedList.value.indexOf( "Q" + AdCbId.replace("cb","") + "Q" ) >= 0 )
            continue;
        else
            CheckedList.value += "Q" + AdCbId.replace("cb","") + "Q";	    
	}
}

function ViewSelected( NoSelMsg, hdCheckedList, ddlSelCurrency )
{
    var list = $Get( hdCheckedList ).value;
    if ( list == '' )
        alert( NoSelMsg );
    else
    {
        var ddl = $Get( ddlSelCurrency );
        var SelCurId = ddl.options[ ddl.selectedIndex ].value;
        window.open( base + 'RealEstate/CommercialForSale/AdsView.aspx?SelCur=' + SelCurId + "&SelList=" + list + "&FS=1",
            "_blank","toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, " +
            "resizable=no, copyhistory=no, width=900, height=600" );
    }
}
/* End ************************** Grid Result Selection Functions *************************/

function ViewAd( AssetId, SelCurId )
{
    window.open( base + 'RealEstate/CommercialForSale/AdsView.aspx?SelCur=' + SelCurId + "&SelList=Q" + AssetId +"Q",
        "_blank","toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, " +
        "resizable=no, copyhistory=no, width=900, height=600" );
}

function OpenEmailAdToOwner( path )
{
	window.open( path , 'EmailAdToOwner', 'status=no, scrollbars=no, height=260, width=410, top=200, left=350, titlebar=no, resizable=no', false);
	return false;
}
