/*
* Simple JS util lib.
*
* @copyright 2007-2010
* @Don021 <amsnimci@yahoo.com>
*/

function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( (!start ) && ( name!= document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
	( ( expires )? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
	( ( path )? ';path=' + path : '' ) +
	( ( domain )? ';domain=' + domain : '' ) +
	( ( secure )? ';secure' : '' );
}

function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + '=' +
	( ( path )? ';path=' + path : '') +
	( ( domain )? ';domain=' + domain : '' ) +
	';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

//can check bla.bla.bla[]..
isset = function(e) {
	try {
		if (eval(e)) {}
	}
	catch(err) {
		return false;
	}
	return true;
}

function pageWidth() {
	return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}
function pageHeight() {
	return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}
function microtime() {
	return new Date().getTime();
}

function switchMovie(o,flv,w,h) {
	o.parentNode.innerHTML = '<embed height="'+h+'" width="'+w+'" flashvars="config={playList: [ { url: \''+o.src+'\', overlayId: \'play\' },{ url: \''+flv+'\' } ], autoBuffering: false, useHwScaling: true, loop: false, autoRewind: true, usePlayOverlay: false, useSmoothing: true, autoPlay: true, useNativeFullScreen: true, showMenu: false, initialScale: \'scale\' }" allowfullscreen="true" allowscriptaccess="always" quality="high" bgcolor="#FFFFFF" name="SwfPlayer" id="SextronixPlayer" src="images/movies/player.swf" type="application/x-shockwave-flash"/>';
}

function switchMovie_hd(o,flv,w,h) {
	o.parentNode.innerHTML = '<embed height="'+h+'" width="'+w+'" flashvars="config={playList: [ { url: \''+flv+'\' } ], splashImageFile: \''+o.src+'\', usePlayOverlay: false, autoPlay: true, initialScale: \'scale\', autoBuffering: false, bufferLength: 1, autoRewind: true, loop:false, showStopButton: true, showScrubber: false, showVolumeSlider: false, showMuteVolumeButton: true, showFullScreenButton: false, showMenu: false, controlsOverVideo: \'locked\', controlBarBackgroundColor: \'-1\' }" allowscriptaccess="always" quality="high" bgcolor="#FFFFFF" name="swfPlayer" id="swfPlayer" src="images/movies/Player.swf" type="application/x-shockwave-flash"/>';
}

function urlencode( str ) {
	var histogram = {}, unicodeStr='', hexEscStr='';
	var ret = (str+'').toString();
	var replacer = function(search, replace, str) {
		var tmp_arr = [];
		tmp_arr = str.split(search);
		return tmp_arr.join(replace);
	};
	histogram["'"]   = '%27';
	histogram['(']   = '%28';
	histogram[')']   = '%29';
	histogram['*']   = '%2A';
	histogram['~']   = '%7E';
	histogram['!']   = '%21';
	histogram['%20'] = '+';
	histogram['\u00DC'] = '%DC';
	histogram['\u00FC'] = '%FC';
	histogram['\u00C4'] = '%D4';
	histogram['\u00E4'] = '%E4';
	histogram['\u00D6'] = '%D6';
	histogram['\u00F6'] = '%F6';
	histogram['\u00DF'] = '%DF';
	histogram['\u20AC'] = '%80';
	histogram['\u0081'] = '%81';
	histogram['\u201A'] = '%82';
	histogram['\u0192'] = '%83';
	histogram['\u201E'] = '%84';
	histogram['\u2026'] = '%85';
	histogram['\u2020'] = '%86';
	histogram['\u2021'] = '%87';
	histogram['\u02C6'] = '%88';
	histogram['\u2030'] = '%89';
	histogram['\u0160'] = '%8A';
	histogram['\u2039'] = '%8B';
	histogram['\u0152'] = '%8C';
	histogram['\u008D'] = '%8D';
	histogram['\u017D'] = '%8E';
	histogram['\u008F'] = '%8F';
	histogram['\u0090'] = '%90';
	histogram['\u2018'] = '%91';
	histogram['\u2019'] = '%92';
	histogram['\u201C'] = '%93';
	histogram['\u201D'] = '%94';
	histogram['\u2022'] = '%95';
	histogram['\u2013'] = '%96';
	histogram['\u2014'] = '%97';
	histogram['\u02DC'] = '%98';
	histogram['\u2122'] = '%99';
	histogram['\u0161'] = '%9A';
	histogram['\u203A'] = '%9B';
	histogram['\u0153'] = '%9C';
	histogram['\u009D'] = '%9D';
	histogram['\u017E'] = '%9E';
	histogram['\u0178'] = '%9F';
	ret = encodeURIComponent(ret);
	for (unicodeStr in histogram) {
		hexEscStr = histogram[unicodeStr];
		ret = replacer(unicodeStr, hexEscStr, ret); // Custom replace. No regexing
	}
	return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
		return "%"+m2.toUpperCase();
	});
}

function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	}
	return false;
}