//document.oncontextmenu=disableRightClick;
var windowcount=0;
//var tasks= new Array();

/*/function disableRightClick()
{
   return false; 
}*/


function winWidth()
{
    var viewportwidth;
    var viewportheight;
 
         // the more standards compliant browsers (mozilla/netscape/opera/IE7) use      window.innerWidth and window.innerHeight
 
    if (typeof window.innerWidth != 'undefined')
    {
        viewportwidth = window.innerWidth;
    }
 
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

    else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
    {
        viewportwidth = document.documentElement.clientWidth;

    }
 
 // older versions of IE
 
    else
    {
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth;

    }
	return viewportwidth;
}
function winHeight()
{	
    var viewportheight;
 
         // the more standards compliant browsers (mozilla/netscape/opera/IE7) use      window.innerWidth and window.innerHeight
 
    if (typeof window.innerWidth != 'undefined')
    {        
        viewportheight = window.innerHeight;
    }
 
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

    else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
    {        
        viewportheight = document.documentElement.clientHeight;
    }
 
 // older versions of IE
 
    else
    {
        
        viewportheight = document.getElementsByTagName('body')[0].clientHeight;
    }
	return viewportheight;
}
function resizeBody()
{
	
	var winW=winWidth()-10;
	taskbarWidth=(winW)+"px";	
	var winH=winHeight()-100;        
	//var winH=winWidth()-30;
	document.getElementById('desktop').style.width=(winW+"px");
	//$('desktop').style.height=("200px");
	document.getElementById('desktop').style.height=(winH+"px");
	
	//new myWindow('desktop','home');
	
}
function createRequestObject()
{
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer")
	{
    	return new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
	{
    	return new XMLHttpRequest();
    }   
}
var idcount=0;

function showFrameAfter(index)
{
    $("#"+myWindow.Objects[index].id).show();

}
function menu(page,title)
{
     var mywindow=new myWindow("desktop");
     mywindow.onClose=closeFrame;  
     mywindow.onMinimize=minimizeFrame;
     mywindow.onMaximize=maximizeFrame;
     mywindow.onNormal=normalFrame;
     
     mywindow.setTitle(title);      
     mywindow.setBounds(200,150,400,300);
     mywindow.setBody("Please wait.Page is Loading...."); 
     //addTask(mywindow.index,"home.png");
     
    
      	
  var url = ""; 	  
  if(page=="home")
  {
    if(! (navigator.appName.indexOf("Microsoft")!=-1) )
    {
        
        $("#icon1").effect("transfer", { to: "#"+mywindow.id }, 500);
        $("#"+mywindow.id).hide();
        setTimeout('showFrameAfter('+mywindow.index+')', 500);    
    }
    url="Home/index.php"; 
  }  
  else if(page=="sample")
  {
    if(! (navigator.appName.indexOf("Microsoft")!=-1) )
    {
        $("#icon2").effect("transfer", { to: "#"+mywindow.id }, 500);
        $("#"+mywindow.id).hide();
        setTimeout('showFrameAfter('+mywindow.index+')', 500); 
    }
	url="Sample/index.php?index="+mywindow.index;
  }
  else if(page=="download")
  {
    if(! (navigator.appName.indexOf("Microsoft")!=-1) )
    {
        $("#icon3").effect("transfer", { to: "#"+mywindow.id }, 500);
        $("#"+mywindow.id).hide();
        setTimeout('showFrameAfter('+mywindow.index+')', 500); 
    }
	url="Download/index.php"; 
  }
  else if(page=="chat")
  {
    if(! (navigator.appName.indexOf("Microsoft")!=-1) )
    {
        $("#icon4").effect("transfer", { to: "#"+mywindow.id }, 500);
        $("#"+mywindow.id).hide();
        setTimeout('showFrameAfter('+mywindow.index+')', 500); 
    }
	url="Chat/index.php?index="+mywindow.index;
  }
  
  else 
  {
	//echo $page."<br>under construction.......";
  }
  var ajax=createRequestObject();
  ajax.onreadystatechange = function()	
  {		
    if(ajax.readyState == 4)
    {
      var text=ajax.responseText;			           
     
      mywindow.setBody(text); 
      
    }
   }
   ajax.open("GET", url, true);
   ajax.send(null); 
   
}
function normalFrame()
{
     if (navigator.appName.indexOf("Microsoft")!=-1) 
    {
  		//this.close();
  		//maximizeFrameAfter(this.index);
  		this.normal();
 	}
    else
    {        
        
        this.normal();        
        //alert("here");
        
        this.innernormal=document.getElementById(this.id).innerHTML;
        document.getElementById(this.id).innerHTML="";
        //$("#"+this.id).show("puff", {}, 500);  
        
        //$("#"+this.id).show("scale", { percent: 100 }, 500);     
         
        $("#fullscreen").effect("transfer", { to: "#"+this.id}, 500); 
        
        setTimeout('normalFrameAfter('+this.index+')', 500);        
        
   /*document.getElementById(this.id).innerHTML="";   
   $("#"+this.id ).hide("scale", {}, 1000);  
   setTimeout('closeFrameafter('+this.index+')', 1000); */
   }
}
function normalFrameAfter(index)
{    
    document.getElementById(myWindow.Objects[index].id).innerHTML=myWindow.Objects[index].innernormal;
    
}
function maximizeFrame()
{
    var wid= winWidth();
    var hei=winHeight();
    $('#fullscreen').width(wid);		
    $('#fullscreen').height(hei);	
    if (navigator.appName.indexOf("Microsoft")!=-1) 
    {
  		//this.close();
  		//maximizeFrameAfter(this.index);
  		this.maximize();
 	}
    else
    {       
        //this.maximize();
        this.innermaximum=document.getElementById(this.id).innerHTML;        
        document.getElementById(this.id).innerHTML="";
        
        $("#"+this.id).effect("transfer", { to: "#fullscreen"}, 500); 
        
        //$("#"+this.id).show("scale", { percent: 100 }, 500);      
        setTimeout('maximizeFrameAfter('+this.index+')', 500);           
   }
}
function maximizeFrameAfter(index)
{    
    //document.getElementById(myWindow.Objects[index].id).innerHTML=myWindow.Objects[index].innermaximum;
    document.getElementById(myWindow.Objects[index].id).innerHTML=myWindow.Objects[index].innermaximum;
    myWindow.Objects[index].maximize();
    
}
function addTask(index,imagesrc,menutitle)
{     

      $("<a class='dock-item2' href='#' id='openedmenu"+index+"' onclick='taskClick("+index+")' ><span>"+menutitle+"</span><img src='"+imagesrc+"' alt='"+menutitle+"' /></a>").appendTo("#openedmenu") 
    $('#dock2').Fisheye(
				{
					maxWidth: 20,
					items: 'a',
					itemsText: 'span',
					container: '.dock-container2',
					itemWidth: 30,
					proximity: 80,
					alignment : 'left',
					valign: 'bottom',
					halign : 'center'
				}
			)
    
    windowcount=windowcount+1;
    if(windowcount==1)
        document.getElementById('openedmenu').style.backgroundImage="url(menuimages/dock-bg3.gif)";
}
function minimizeFrame()
{
    var imagesrc="";
    var menutitle=""
    if(this.getTitle()=="www.shaifulonline.com")
    {
        imagesrc="menuimages/home.png";
        menutitle="ABOUT ME";
    }
    else if(this.getTitle()=="My Work Samples")
    {
        imagesrc="menuimages/sample.png";
        menutitle="MY WORK SAMPLES";
    }
    else if(this.getTitle()=="Download")
    {
        imagesrc="menuimages/download.png";
        menutitle="DOWNLOADS";
    }
    else if(this.getTitle()=="Chat")
    {
        imagesrc="menuimages/contact.png";
        menutitle="CHAT WITH ME";
    }
    addTask(this.index,imagesrc,menutitle);

    if (navigator.appName.indexOf("Microsoft")!=-1) 
    {
  		//this.close();
  		//minimizeFrameAfter(this.index);
//  		myWindow.Objects[index].minimize();
 	}
    else
    {   
        $("#"+this.id).effect("transfer", { to: "#openedmenu"+this.index }, 500); 
        //setTimeout('minimizeFrameAfter('+this.index+')', 500); 
    }   
    myWindow.Objects[this.index].minimize(); 
}
function closeFrameafter(index)
{
    myWindow.Objects[index].close();
    //$("#"+myWindow.Objects[index].id).remove();
}
function closeFrame()
{   
    if (navigator.appName.indexOf("Microsoft")!=-1) 
    {
  		this.close();  		
 	}
    else
    {
        if(this.getTitle()=="www.shaifulonline.com")
            $("#"+this.id).effect("transfer", { to: "#icon1" }, 500);
        else if(this.getTitle()=="My Work Samples")
            $("#"+this.id).effect("transfer", { to: "#icon2" }, 500);
        else if(this.getTitle()=="Download")
            $("#"+this.id).effect("transfer", { to: "#icon3" }, 500);
        else if(this.getTitle()=="Chat")
            $("#"+this.id).effect("transfer", { to: "#icon4" }, 500);
        $("#"+this.id).hide();
        setTimeout('closeFrameafter('+this.index+')', 500);         
    }
    
}
function restoreFrameAfter(index)
{
    myWindow.Objects[index].restore();    
}
function taskClick(index)//id==index
{    
    if (navigator.appName.indexOf("Microsoft")!=-1) 
    {  		
  		    myWindow.Objects[index].restore();
  		   
    }
    else
    {   
        $("#openedmenu"+index).effect("transfer", { to: "#"+myWindow.Objects[index].id}, 500); 
        setTimeout('restoreFrameAfter('+index+')', 500);                  
    }    
    removeTask(index);    
}
function removeTask(index)
{
    $("#openedmenu"+index).remove();
    $('#dock2').Fisheye(
				{
					maxWidth: 20,
					items: 'a',
					itemsText: 'span',
					container: '.dock-container2',
					itemWidth: 30,
					proximity: 80,
					alignment : 'left',
					valign: 'bottom',
					halign : 'center'
				}
			)
    
    windowcount=windowcount-1;
    if(windowcount==0)
        document.getElementById('openedmenu').style.backgroundImage="";
}

function crawlLinks(index)
{
    
	document.getElementById("crawlerresult"+index).innerHTML ="Please wait......";
	var url=document.getElementById('crawlerurl'+index).value;
	if(url=="")
		alert("Url cannot be empty.");
	else
	{
		var url = "Crawler/crawlLinks.php?url="+url;
		var ajax=createRequestObject();
		ajax.onreadystatechange = function()	
		{		
			if(ajax.readyState == 4)
			{
				var text=ajax.responseText;
				document.getElementById("crawlerresult"+index).innerHTML =text;
			}
		}
		ajax.open("GET", url, true);
		ajax.send(null); 	 
	}
}
function crawlImages(index)
{
	document.getElementById("crawlerresult"+index).innerHTML ="Please wait......";
	var url=document.getElementById('crawlerurl'+index).value;
	if(url=="")
		alert("Url cannot be empty.");
	else
	{
		var url = "Crawler/crawlImages.php?url="+url;
		var ajax=createRequestObject();
		ajax.onreadystatechange = function()	
		{		
			if(ajax.readyState == 4)
			{
				var text=ajax.responseText;
				document.getElementById("crawlerresult"+index).innerHTML =text;
			}
		}
		ajax.open("GET", url, true);
		ajax.send(null); 	 
	}
}
function downloadclick(type)
{		
  var url = "Download/download.php?type="+type;
	var ajax=createRequestObject();
	ajax.onreadystatechange = function()	
	{		
		if(ajax.readyState == 4)
		{
			//var text=ajax.responseText;
			//document.getElementById("desktop").innerHTML =text;                        
		}
	}
	ajax.open("GET", url, true);
	ajax.send(null); 	  
}
function crawler(index)
{
    //alert(index);
    var url = "Crawler/index.php?index="+index;
	var ajax=createRequestObject();
	ajax.onreadystatechange = function()	
	{		
		if(ajax.readyState == 4)
		{
			var text=ajax.responseText;
			//document.getElementById("sample"+index).innerHTML =text;
                        //alert(index);
                        myWindow.Objects[index].setBody(text);
                        
		}
	}
	ajax.open("GET", url, true);
	ajax.send(null); 	 
}
function win(index)
{
    
    var url = "Window/index.php?index="+index;
	var ajax=createRequestObject();
	ajax.onreadystatechange = function()	
	{		
		if(ajax.readyState == 4)
		{
			var text=ajax.responseText;
			//document.getElementById("sample"+index).innerHTML =text;
                        //alert(index);
                        myWindow.Objects[index].setBody(text);
                        
		}
	}
	ajax.open("GET", url, true);
	ajax.send(null); 	 
}
function imageVerify(index)
{
    
    var url = "Imageverification/index.php?index="+index;
	var ajax=createRequestObject();
	ajax.onreadystatechange = function()	
	{		
		if(ajax.readyState == 4)
		{
			var text=ajax.responseText;
			//document.getElementById("sample"+index).innerHTML =text;
                        //alert(index);
                        myWindow.Objects[index].setBody(text);
                        
		}
	}
	ajax.open("GET", url, true);
	ajax.send(null); 	 
}
function veryfyImage(index)
{
     document.getElementById("imageVerify"+index).innerHTML="please go to<br>www.shaifulonline.com/others/imageverification1<br> for verification.";           
}
function sample(index)
{
    var url = "Sample/index.php?index="+index;
	var ajax=createRequestObject();
	ajax.onreadystatechange = function()	
	{		
		if(ajax.readyState == 4)
		{
			var text=ajax.responseText;
			//var child=document.getElementById("sample"+index);
			//child.parentNode.innerHTML=text;
                        myWindow.Objects[index].setBody(text);                        
		}
	}
	ajax.open("GET", url, true);
	ajax.send(null); 	 
}
