﻿// JScript File


//Global XMLHTTP Request object
var XmlHttp;

//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp()
{
	//Creating object of XMLHTTP in IE
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;
		}
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
	}
}


function PostData(requestUrl,strFilter)
{
  
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange =HandleResponse;
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("Post", requestUrl,  true);	
		XmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        XmlHttp.setRequestHeader("Content-length", strFilter.length);
        XmlHttp.setRequestHeader("Connection", "close");	
		//Sends the request to server
		//alert(strFilter);
		XmlHttp.send(strFilter);		
	}
	else 
	 alert("This browser does not support. Try in some other browser."); 
	
}

//Called when response comes back from server
function HandleResponse()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
	     // To make sure valid response is received from the server, 200 means response received is OK
		
	    if(XmlHttp.status == 200)
	    {	
		if (XmlHttp.responseText=="Success")
		{
               //nothing so far
		}
            if (XmlHttp.responseText.toString().indexOf(",")!=-1)
                ReplaceMissingFile(XmlHttp.responseText.substring(XmlHttp.responseText.toString().indexOf(",") +1));
            
            var ni = document.getElementById("Gallary");
            var newdiv = document.createElement('div');
            var myDate=new Date();
            var divIdName = ni.id + "Child"
            newdiv.setAttribute('id',divIdName);
            if (XmlHttp.responseText.toString().indexOf(",")==-1)
                newdiv.innerHTML = XmlHttp.responseText;
            else
                newdiv.innerHTML = XmlHttp.responseText.substring(0,XmlHttp.responseText.toString().indexOf(","));

            ni.appendChild(newdiv);
  	    }
	    else
	    {
		alert("Host the page in IIS." );
	    }
	}
}
function ReplaceMissingFile(missingFile)
{
//Folder1="" ,Folder2="sdfsdf"
//style:display 
//Folder:NewFile
    var e=document.getElementsByTagName("a");
    var fFile = missingFile.split(','); 
   
    for(var i=0;i<fFile.length;i++)
    {
        for(var j=0;j<e.length;j++)
        {
            //alert(e[j].rel.length +"<<len "+ e[j].rel.substring(e[j].rel.indexOf("[") +1,e[j].rel.lastIndexOf("]")) + "==" + fFile[i]);
            if ((fFile[i].indexOf("=")==-1 && fFile[i].length>0) && (e[j].rel.substring(e[j].rel.indexOf("[") +1,e[j].rel.lastIndexOf("]"))==fFile[i]))
                e[j].style.display="none";  
            else
            {
                
                if ( e[j].rel.length>0 && e[j].rel.substring(e[j].rel.indexOf("[") +1,e[j].rel.lastIndexOf("]"))==fFile[i].substring(0,fFile[i].indexOf("=")))
                {
                    if (fFile[i].indexOf("=")==-1)
                          e[j].style.display="none";                    
                    else
                        {
                        e[j].href=e[j].href.replace(e[j].href.substring(e[j].href.lastIndexOf("/") + 1), fFile[i].substring(fFile[i].indexOf("=")+1));
                        }
                }
            } 
        }
    }
}
function LoadAllImage()
{
   
   var e=document.getElementsByTagName("a");
   
   var FName="";
   for(var i=0;i<e.length;i++)
    {
      if (e[i].rel.length>0 && e[i].rel.substring(0,e[i].rel.indexOf("["))=="lightbox")
      FName+=e[i].rel.substring(e[i].rel.indexOf("[") +1,e[i].rel.lastIndexOf("]")) + "," + e[i].href.substring(e[i].href.lastIndexOf("/") + 1) + "," ;
    }

    PostData("LightBoxImageFetch.aspx",FName);
}


