﻿var mainScreen =
{
    result : null
}


mainScreen.fetchnews = function (catgname,newsid,year,month,seltype) {

document.getElementById('hidjssptyp').value=seltype;
document.getElementById('ctl00_ContentPlaceHolder1_hidcatg').value=catgname;
 
    PageMethods.fetchnews(catgname,newsid,year,month,seltype,mainScreen.ExecuteCommandCallback, mainScreen.ExecuteCommandFailed);
};
mainScreen.ExecuteCommandCallback = function (result) {


    if(result) {
 
        try {
       // alert(result.length);
       // alert(result[1].VCATEGORY);
        var stringhtml="";
       var ssptyp=document.getElementById('hidjssptyp').value
       
       if(ssptyp=='selectbycat'){
               if(result.length>0){
                        for(var i=0;i<result.length;i++)
                        {
                                if(i==0)
                                stringhtml+="<p><img src=\"images/trans.gif\" alt=\"\" /></p>";
                                else
                                stringhtml+="<p class=\"border_block\"><img src=\"images/trans.gif\" alt=\"\" /></p>";
                                
                                stringhtml+="<h5>"+result[i].VTITLE+"</h5>";
                                stringhtml+="<h6>Date: <span>"+ result[i].STRDATE +"</span></h6>";
                                stringhtml+="<img height=\"120\" width=\"140\" src="+result[i].VIMAGEPATH+" alt=\"\"  class=\"news_img\">";
                                stringhtml+="<p>"+result[i].VSHORTDESCRIPTION+"</p>";
                                stringhtml+="<p>&nbsp;</p>";
                                  stringhtml+="<p><a href=\"real_estate_news.aspx?ns="+ result[i].INEWSROOMID +"&view="+ result[i].VCATEGORY  +"\">More</a></br></p>";
                                //stringhtml+="<p><a href='javascript:void(0)' onclick='displaymore("+ result[i].INEWSROOMID +")'>More</a></br></p>";
                        }
                }else
                {
                //Then no records found
                              stringhtml="<span style=\"padding-left:180px;\"> No records found </span>";
                }
                
        }else if(ssptyp=='selectbyid'){
        
       // var imgcoll=document.getElementById('hidimagcoll');
        //var imgcolltol=document.getElementById('hidimagtol');
        
       // alert(result.length);
        
        //imgcoll.value="";
        //imgcolltol.value=result.length;
                if(result.length>0){
                stringhtml+="<p><img src=\"images/trans.gif\" alt=\"\" /></p>";
                stringhtml+="<h5>"+result[0].VTITLE+"</h5>";
                stringhtml+="<h6>Date: <span>"+ result[0].STRDATE +"</span></h6>";
                stringhtml+="<img height=\"48\" width=\"79\" src="+result[0].VIMAGEPATH+" alt=\"\"  class=\"news_img\">";
                stringhtml+="<p>"+result[0].VSHORTDESCRIPTION+"</p>";
                stringhtml+="<p>"+result[0].DESCRIPTION+"</p>";
                stringhtml+="<p class=\"border_block\"><img src=\"images/trans.gif\" alt=\"\" /></p>";
                   
//                                stringhtml+="Title:"+result[0].VTITLE+"<img src="+result[0].VIMAGEPATH+">";
//                                stringhtml+="desp:"+result[0].DESCRIPTION+"</br>";
               
               
               stringhtml+="<div class=\"thumbnail\">";              
                        for(var i=0;i<result.length;i++)
                        {
                                stringhtml+="<a href=\""+ result[i].VIMAGEPATH +"\" class=\"lightwindow page-options\" ><img  src=\""+ result[i].VIMAGEPATH +"\" alt=\"\" /></a>";
                               // stringhtml+="<img onclick='dispModal("+ i +")' src="+result[i].VIMAGEPATH+"> -- ";
                               // imgcoll.value+=result[i].VIMAGEPATH+"|";
                        }
                        alert(stringhtml);
               stringhtml+="</div>"; 
               
               
                         
                }else
                {
                //Then no records found
                stringhtml="<span style=\"padding-left:180px;\"> No records found </span>";
                }
        
        }
        
        
        
        document.getElementById("pagemainbody").innerHTML=stringhtml;
           // mainScreen.result = result[0];
           // eval(result[1]+"(mainScreen.result);");
        } catch(err) {
           
        }  
    }
};
mainScreen.ExecuteCommandFailed = function (error, userContext, methodName) {

    if(error) {
        ;// TODO: add error handling, and show it to the user
    }
};

mainScreen.Init = function() {

    /// Initializes mainScreen variables

};

Sys.Application.add_load(applicationLoadHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequestHandler);

function applicationLoadHandler() {

  mainScreen.Init()
}

function endRequestHandler() {
    /// <summary>
    /// Raised before processing of an asynchronous 
    /// postback starts and the postback request is 
    /// sent to the server.
    /// </summary>
    
    // TODO: Add your custom processing for event
}

function beginRequestHandler() {
    /// <summary>
    /// Raised after an asynchronous postback is 
    /// finished and control has been returned 
    /// to the browser.
    /// </summary>

    // TODO: Add your custom processing for event
}

function display(arch,tabname,catgname)
{
    mainScreen.fetchnews(catgname,'0','0','0','selectbycat');
    document.getElementById('headarchiv').innerHTML=catgname+" Archive";
    document.getElementById('spn1').className="show1";
    document.getElementById('spn2').className="show1";
    document.getElementById('spn3').className="show1";
    var spnid=document.getElementById(tabname);
    spnid.className="show1 test2";
    document.getElementById('archNews').style.display="none";
    document.getElementById('archevents').style.display="none";
    document.getElementById('archcons').style.display="none";
    var spnid2=document.getElementById(arch);
    
    spnid2.style.display="block";

    document.getElementById('ctl00_ContentPlaceHolder1_hidcatg').value=catgname;
}

function displayarch(arch,tabname)
{

    document.getElementById('spn1').className="show1";
    document.getElementById('spn2').className="show1";
    document.getElementById('spn3').className="show1";
    var spnid=document.getElementById(tabname);
    spnid.className="show1 test2";

    document.getElementById('archNews').style.display="none";
    document.getElementById('archevents').style.display="none";
    document.getElementById('archcons').style.display="none";
    var spnid2=document.getElementById(arch);
    spnid2.style.display="block";
   
}


function displaybydate(year,month)
{

    mainScreen.fetchnews(document.getElementById('ctl00_ContentPlaceHolder1_hidcatg').value,'0',year,month,'selectbycat');
}

function displaymore(newsid)
{
    mainScreen.fetchnews('',newsid,'0','0','selectbyid');
}

function dispModal(imgindex)
{


var imgcoll=document.getElementById('hidimagcoll');
var imgSplitResult = imgcoll.value.split('|');

var imgcolltol=document.getElementById('hidimagtol').value;

var strHTML="";


if((imgcolltol>=imgindex+1)&&(imgindex>=0))
{
document.getElementById('hidcurindex').value=imgindex;
strHTML="<img src='"+imgSplitResult[imgindex] +"' />";
document.getElementById('modalbody').innerHTML=strHTML;
}



$find("CMX").show();

}

function dispnext(dirindex)
{
var curindex=document.getElementById('hidcurindex').value
if(dirindex=='prv')
dispModal(parseInt(curindex)-1);
else if(dirindex=='nxt')
dispModal(parseInt(curindex)+1);

}