// JavaScript Document
/*
	Developer   : Codlib
	E-Mail      : codlib@gmail.com
	Description : Ajax Functions
*/
/* --------------------------   AJAX FUNCTION STARTS HERE  -------------------------- */
/*
Return the id of the attribute.
*/
//function $(id){return document.getElementById(id);}

/*
Return the value of the attribute.
*/
//function $F(id){return document.getElementById(id).value;}

/*
Return the xmlHttpObject
*/
function GetXmlHttpObject(handler)
{ 
	var objXmlHttp=null
	if (navigator.userAgent.indexOf("Opera")>=0)
	{
		alert("Opera Is Not Supporting. Use Some Other Browsers") 
		return 
	}
	if (navigator.userAgent.indexOf("MSIE")>=0)
	{ 
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
			strName="Microsoft.XMLHTTP"
		} 
		try
		{ 
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler 
			return objXmlHttp
		} 
		catch(e)
		{ 
			alert("Error. Scripting for ActiveX might be disabled") 
			return 
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0)
	{
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler 
		return objXmlHttp
	}
} 
/*
Send an ajax request to the url mentioned
URL : 	SERVER SIDE SCRIPT NAME
PARAMETERS : URL parameters
callback   : callback function
requesttype: POST OR GET
async      : asycronous or synchronous, TRUE or FALSE
*/
function makeRequest(url,parameters,callback,requesttype,async)
{
	
	if(requesttype=='POST')
	{
		xmlHttp=GetXmlHttpObject(callback) 
		xmlHttp.open("POST",url,async);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		xmlHttp.send(parameters);
	}else if(requesttype=="GET")
	{
		url    = url+'?'+parameters;
		xmlHttp=GetXmlHttpObject(callback) 
		xmlHttp.open("GET", url , async) 
		xmlHttp.send(null) 
	}
}
/**
* Function : dump()
* Arguments: The data - array,hash(associative array),object
*    The level - OPTIONAL
* Returns  : The textual representation of the array.
* This function was inspired by the print_r function of PHP.
* This will accept some data as the argument and return a
* text that will be a more readable version of the
* array/hash/object that is given.
*/
function dump(arr,level) {
var dumped_text = "";
if(!level) level = 0;

//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += "    ";

if(typeof(arr) == 'object') { //Array/Hashes/Objects
 for(var item in arr) {
  var value = arr[item];
 
  if(typeof(value) == 'object') { //If it is an array,
   dumped_text += level_padding + "'" + item + "' ...\n";
   dumped_text += dump(value,level+1);
  } else {
   dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
  }
 }
} else { //Stings/Chars/Numbers etc.
 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}
return dumped_text;
} 

/*-----------------------------------------------------------------*/
// Slide show caller function

/*-----------------------------------------------------------------*/
function openSlideShow(searchType,searchTag,albumOwner,albumId)
{
	
	var parameters = 'searchType='+searchType;
	parameters = parameters+'&searchTag='+encodeURIComponent(searchTag);
	parameters = parameters+'&albumOwner='+albumOwner;
	parameters = parameters+'&albumId='+albumId;
	
	//alert(parameters);
	
	var url = 'user_slideshow.php?'+parameters;
	//var width  = screen.width;
	//width = width-17;
	//var height = screen.height;
	//height = height-60;
	//var windowparameters = "resizable=no,scrollbars=no,status=no,width="+width+"px,height="+height+"px,screenX=150,screenY=150,top=0,left=0";
	var windowparameters = "resizable=yes,scrollbars=yes,status=no,fullscreen=yes,screenX=150,screenY=150,top=0,left=0";
	window.open(url,'SLIDESHOW',windowparameters);

}
function openFlashSlideShow(searchType,searchTag,albumOwner,albumId)
{
	
	var parameters = 'searchType='+searchType;
	parameters = parameters+'&searchTag='+encodeURIComponent(searchTag);
	parameters = parameters+'&albumOwner='+albumOwner;
	parameters = parameters+'&albumId='+albumId;
	
	//alert(parameters);
	
	var url = 'user_slideshow_flash.php?'+parameters;
	//var width  = screen.width;
	//width = width-17;
	//var height = screen.height;
	//height = height-60;
	//var windowparameters = "resizable=no,scrollbars=no,status=no,width="+width+"px,height="+height+"px,screenX=150,screenY=150,top=0,left=0";
	var windowparameters = "resizable=yes,scrollbars=yes,status=no,fullscreen=yes,screenX=150,screenY=150,top=0,left=0";
	window.open(url,'SLIDESHOW',windowparameters);

}

