/* JavaScript Zeon System Util
	Written by 				= Hazhir Haghshenas
	Version 				= 1.3.0.1
	Last Update				= 26/02/2008
	
	USING{
		1 - util.js
	}
*/
//************************* ELEMENT AND WINDOW SIZE!**********************

function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}

function getww(){
  var winW = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    winW = window.innerWidth;
  } else if( document.documentElement && document.documentElement.clientWidth) {
    //IE 6+ in 'standards compliant mode'
    winW = document.documentElement.clientWidth;
  } else if( document.body && document.body.clientWidth ) {
    //IE 4 compatible
    winW = document.body.clientWidth;
  }
  return winW;
}

function getwh(){
  var winH = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    winH = window.innerHeight;
  } else if( document.documentElement && document.documentElement.clientHeight ) {
    //IE 6+ in 'standards compliant mode'
    winH = document.documentElement.clientHeight;
  } else if( document.body && document.body.clientHeight ) {
    //IE 4 compatible
    winH = document.body.clientHeight;
  }
	return winH;
}

function geteh(elem){
	var elemH;
	if (document.getElementById(elem) != null){
		if (document.getElementById(elem).offsetHeight)
			elemH = document.getElementById(elem).offsetHeight;
		else
			elemH = 0;
	}
	else{
		alert('element not found : \n ' + elem);
		elemH = 0;
	}
	return elemH;
}

function getew(elem, percok){
	var elemW;
	//Set Percent ok to return yout width in percent if aviable!
	
	if (typeof (elem) == 'object'){
		if (elem.clientWidth){
			elemW = elem.clientWidth;
		}else if (elem.offsetWidth){
			elemW = elem.offsetWidth;
		}
		
		if (elem.style.width && percok == 1){
			elemW = elem.style.width;
		}
	}else{elemW = 0}
	return elemW;
}
//************************* END! **********************

//************************* CHECK ALL CHECK BOXES! **********************
function check_ch(p, val)
{
	if (p.childNodes.length == 0){
		if (p.tagName == 'INPUT'){
			if (val == 'invers')p.checked = !p.checked; else p.checked = val;
			if (p.onchange) p.onchange();
		}
	}else{
		var l = p.childNodes.length;
		for(var i=0;i<l;i++){
			var ch = p.childNodes[i];
			if (ch.childNodes.length >= 1) check_ch(ch, val);
			if (ch.tagName == 'INPUT'){
				if (val == 'invers'){
					ch.checked = !ch.checked;
				}else{
					ch.checked = val;
				}
				if (ch.onchange)ch.onchange();
			}
		}
	}
}

function checkall(moth, ch)
{
	if (!moth.childNodes) moth = document.getElementById(moth);
	if(moth){
		check_ch(moth, ch);	
	}else{
		alert("No object Detected!");
		//return false;
	}
}
//************************* END! **********************


//************************* DISABLE ALL CHECK BOXES! **********************
function dis_all(p, val, cond)
{
	var l = p.childNodes.length;
	if (cond) var re = new RegExp(cond);
	for(var i=0;i<l;i++){
		var ch = p.childNodes[i];
		if (ch.childNodes.length >= 1) dis_all(ch, val, cond);
		if (ch.tagName == 'INPUT' && (!re || re.test(ch.id) )){
			if (val == 'invers'){
				ch.disabled = !ch.disabled;
			}else{
				ch.disabled = val;
			}
		}
	}
}

function disableall(moth, ch, cond)
{
	if (!moth.childNodes) moth = document.getElementById(moth);
	if (!cond) var cond = '';
	if(moth){
		dis_all(moth, ch, cond);	
	}else{
		alert("No object Detected!");
		return false;
	}
}
//************************* END! **********************



//************************* Location & Parameteres **********************
function getURLParam(strParamName){
	var strReturn = "";
	var strHref = window.location.href;
	if ( strHref.indexOf("?") > -1 ){
		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
		{
			if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
		 	}
		}
	}
	return unescape(strReturn);
}

/*function get_para_names(){
	var hrf = window.location.href;
	var is_p_e = 0;
  	if ( hrf.indexOf("?") > -1 ){
		var pa = hrf.substr(hrf.indexOf("?"));
		var params = hrf.split("&");
		var t,temp = params[0].split("?");
		params[0] = temp[1];
		for (var i=0;i<=params.length;i++){
			var a = params[i].split("=");
		}
	}
	return params;
}

function get_para_values(){
}
*/

function isarg(p,v){
//	&Order=id
	var url = window.location.toString();
	if (url.indexOf("?") > -1){
		var uuu = url.split("?");
		url.match(/\?(.+)$/);
		var params = RegExp.$1;
		// split up the query string and store in an
		// associative array
		var params = params.split("&");
		var queryStringList = {};	
		for(var i=0;i<params.length;i++)
		{			
			var tmp = params[i].split("=");
			if (v == null){
					//Just Find a parameters
					if (tmp[0] == p){
						return 1;
					}
				}
			else{
					//find param with special value
					if ((tmp[0] == p) && (tmp[1] == v)){
						return 1;
					}
				}
		}
	}
	return 0;	
}
function change_p(p,v){
	// get the current URL
	var realhref = "", isf = 0;
	var url = window.location.toString();
	//get the parameters
	if (url.indexOf("?") > -1){
		var uuu = url.split("?");
		url.match(/\?(.+)$/);
		var params = RegExp.$1;
		// split up the query string and store in an
		// associative array
		var params = params.split("&");
		var queryStringList = {};		
		for(var i=0;i<params.length;i++)
		{
			var tmp = params[i].split("=");
			if ((tmp[0] == p) && (isf != 1)){
					queryStringList[tmp[0]] = unescape(v);
					tmp[1] = v;
			 		isf = 1;
		 	}else{
			 	queryStringList[tmp[0]] = unescape(tmp[1]);
		 	}
			
			if (i == 0){
				realhref +="?"+tmp[0]+"="+tmp[1];
			}else{
				realhref +="&"+tmp[0]+"="+tmp[1];
			}
		} 
	
		if (isf == 0){
			window.location.href += "&" + p + "=" + v;
		}else{
			window.location.href = uuu[0] + realhref;
		}
	}
}

function changelocation(p, v){
	var url = window.location.toString();
	for (var i=0; i<p.length; i++){
		if (url.indexOf("?") == -1 && i == 0){
			url += "?"+p[i]+"="+v[i];
		}else{
			url += "&"+p[i]+"="+v[i];
		}
	}
	window.location = url;
	window.location.href = url;
}

function remarg(p,v){
	var realhref = "", isf = 0;
	var url = window.location.toString();
	//get the parameters
	if (url.indexOf("?") > -1){
		var uuu = url.split("?");
		url.match(/(.+)\?(.+)$/);
		var loc = RegExp.$1;
		var params = RegExp.$2;
		
		if (params.match(p+'=')){
			alert('changing');
			var a = params.replace(/$p=/,'');
		}
		alert(params);
		alert(a);
		// split up the query string and store in an
		// associative array
//		var params = params.split("&");
//		var queryStringList = {};		
//		for(var i=0;i<params.length;i++)
//		{
//			var canadd;
//			if (h = null){
//				var tmp = params[i].split("=");
//			}else{
//			}
//		}
	}	
}


//*************************            END!             **********************


//************************* DIV SHOW & HIDE **********************
function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}

function hideit(p){
	if (!p.childNodes) p = document.getElementById(p);
	p.style.display = "none";
}

function ishide(p){
	if (!p.childNodes) p = document.getElementById(p);
	if (p.style.display == "none"){
		return true;
	}else{
		return false;
	}
}

function isshow(p){
	if (!p.childNodes) p = document.getElementById(p);
	if (p.style.display != "none"){
		return true;
	}else{
		return false;
	}
}

function showit(p){
	if (!p.childNodes) p = document.getElementById(p);
	p.style.display = "";
}

function showobject(id, millisec){
    opacity(id, 0, 100, millisec); 		
	document.getElementById(id).style.display = "";
}

function fadeobject(id, millisec){
    opacity(id, 100, 0, millisec); 
	setTimeout('hideit("'+id+'");', millisec);
}

function showfade(p, millisec, ret) { 
    //if an element is invisible, make it visible, else make it ivisible 
	var r;
	if (!p.childNodes) p = document.getElementById(p);
    if(p.style.opacity == 100 || p.style.display != "none") { 
        opacity(p.id, 100, 0, millisec);
		setTimeout('hideit("'+p.id+'");', millisec);
		r = false;
    } else 	if (!p.style.opacity || p.style.opacity == 0){ 
        opacity(p.id, 0, 100, millisec); 
		setTimeout('document.getElementById("'+p.id+'").style.display = ""', 10);
		r = true;
    }
	if (ret == 1){
		return r;
	}
} 



function showelement(p){
	var r;
	if (!p.childNodes) p = document.getElementById(p);
	if (p.style.display == 'none'){
		p.style.display = '';
		r = true;
	}else{
		p.style.display = 'none';
		r = false;
	}
	return r;
}

//************************* MOUSE Position **********************
function getMouseX( e ) {	return e.pageX		|| ( e.clientX + ( document.documentElement.scrollLeft		|| document.body.scrollLeft ) );}
function getMouseY( e ) {	return e.pageY		|| ( e.clientY + ( document.documentElement.scrollTop		|| document.body.scrollTop ) );}


//************************* Scroll Width & Height **********************
function getScrollW()
{
   var w = window.pageXOffset ||
           document.body.scrollLeft ||
           document.documentElement.scrollLeft;
           
   return w ? w : 0;
} 

function getScrollH()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
           
   return h ? h : 0;
}

//************************ Parameters & Forms *************************
function chv(p,v,form){
	for (i=0; i<p.length;i++)
	if ((document.getElementById(p[i]) != null)){
		document.getElementById(p[i]).value = v[i];
	}
	if (typeof (form) != 'object'){
		if ((document.getElementById(form) != null)){
			document.getElementById(form).submit();
		}
	}else{
		form.submit();
	}
}



//************************ PNG FIX FOE IE >=5.5 *************************
function pngfix(p){
/*	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	
	if ((version >= 5.5) && (document.body.filters)) 
	{
	   for(var i=0; i<document.images.length; i++)
	   {
		  var img = document.images[i]
		  var imgName = img.src.toUpperCase()
		  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		  {
			 var imgID = (img.id) ? "id='" + img.id + "' " : ""
			 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			 var imgStyle = "display:inline-block;" + img.style.cssText 
			 if (img.align == "left") imgStyle = "float:left;" + imgStyle
			 if (img.align == "right") imgStyle = "float:right;" + imgStyle
			 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			 var strNewHTML = "<span " + imgID + imgClass + imgTitle
			 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			 img.outerHTML = strNewHTML
			 i = i-1
		  }
	   }
	}*/
	supersleight.init(p);
};



//************************ AJAX *************************
function getAjax(){
	var req;
	if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return req;
}

function do_eval(resp){
	try{
		var r = new RegExp("<!-- [-~]{2}\{(.*[\\s\\S]*)\}[-~]{2} -->", "mig");
		var res = r.exec(resp);
		
		if (resp.match(r)){
			for (i=1;i<=res.length;i++){
				alert(res[i]);
				if (res[i]){
					eval(res[i]);
				}
			}
		}
		
		resp = resp.replace(r, '');
		
		r = new RegExp("\&lt;!-- [-~]{2}{(.*[\s\S]*)}[-~]{2} --\&gt;", "mig");
		var res = r.exec(resp);
		if (resp.match(r)){
			for (i=1;i<=res.length;i++){
				if (res[i]){
					eval(res[i]);
				}
			}
		}
		resp = resp.replace(r, '');	
	}catch (e){
		alert(e);
		//document.write(a);*/
	}
	return resp;
}


function num2money(n_value) {
// validate input
if (isNaN(Number(n_value)))
return 'ERROR';

// save the sign
var b_negative = Boolean(n_value < 0);
n_value = Math.abs(n_value);

// round to 1/100 precision, add ending zeroes if needed
var s_result = String(Math.round(n_value * 1e2) % 1e2 + '00').substring(0, 2);

// separate all orders
var b_first = true;
var s_subresult;
while (n_value >= 1) {
s_subresult = (n_value >= 1e3 ? '00' : '') + Math.floor(n_value % 1e3);
s_result = s_subresult.slice(-3) + (b_first ? '.' : ',') + s_result;
b_first = false;
n_value = n_value / 1e3;
}
// add at least one integer digit
if (b_first)
s_result = '0.' + s_result;

// apply formatting and return
return b_negative
? '(' + s_result + ')'
: '' + s_result;
}