/*
        Ivy Four's global.js, super-shortened sidormedia.pl eidition
*/


/* --------------------
        GLOBAL
        DEFINITIONS
   -------------------- */

 var Version		= '0.12sid';				// Framework version
 var blankImage		= 'images/layout/blank.gif';		// Blank image path (for PNG fixer)
 var openWindows	= new Array();				// for openInWindow() function

/* --------------------
        FUNCTIONS &
        ENVIRONMENT
   -------------------- */

// ## BROWSER: Open a popup window
function openInWindow(width,height,url) {

	// [DEFAULTS] Set the new window config
	var config =  'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,';
	config += 'width='+width+',height='+height;
	config += ',left=' + (screen.width - width)/2 + ',top=' + (screen.height - height)/2;

	// Check if the window already exists in array
	if((openWindows[url]) && (!openWindows[url].closed)) {

		// Focus
		openWindows[url].focus();
	}

	// If the window is not open for sure (not even in the array)
	else {

		// Open and focus
		 //	using the random string generator for the NAME argument cause of idiotic MSIE behavior
		 //	which cannot accept URL as the name
		openWindows[url] = window.open(url,randomString(16),config);
		openWindows[url].focus();
	}
}


// ## BROWSER: Refresh current window
function windowRefresh() { window.location.href = window.location.pathname; }



/* ## PHP-like string handling framework (beta!)
   ## */

// # strstr() 
function strstr(haystack, needle) {

 // try to check the index of desired 'needle' within the 'haystack', and add 1 to make it integer
 var exists = haystack.indexOf(needle) + 1;

 // check the above integer results and return true/false for the caller
 if(exists > 0) { return true; } else { return false; }
}

// # stristr()	( case insensitive strstr() )
function stristr(haystack, needle) {

 // convert both needle and the haystack to lowercase
 haystack = haystack.toLowerCase();
 needle = needle.toLowerCase();

 // now do strstr() on em!
 return strstr(haystack, needle);
}

// # randString()	( random string generator )
function randomString(length) {

 // define our charracter set for randomizing
 var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";

 // prepare the output var
 var randomstring = '';

 // run a loop and build it
 for (var i=0; i<length; i++) {
	var rnum = Math.floor(Math.random() * chars.length);
	randomstring += chars.substring(rnum,rnum+1);
 }

 return randomstring;
}
