/* ----------------------------------------------------
/* onClick */
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i = 0; i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/* ----------------------------------------------------
/* onClick */
function onClick() {
	//if(readCookie('link') != 1){
		//var win = window.open('', '_blank');
		//win.location = 'http://e-down.eu';
	//}
}


/* ----------------------------------------------------
/* mouseover */
function mouseover(value){
	var e = document.getElementById(value);
	try {
    	oldcolor = document.getElementById(value).currentStyle.backgroundColor;
	} catch(err) {
    	oldcolor = document.defaultView.getComputedStyle(document.getElementById(value), '').getPropertyValue("background-color");
	}
	e.style.background = '#FFFFFF';
	return true;
}
function mouseout(value){
	var e = document.getElementById(value);
	e.style.background = '#FFFFFF';
	return true;	
}

/* ----------------------------------------------------
/* textCounter */

function textCounter(field,counter,maxlimit,linecounter) {
	// text width//
	var fieldWidth =  parseInt(field.offsetWidth);
	var charcnt = field.value.length;        

	// trim the extra text
	if (charcnt > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);
	}

	else { 
	// progress bar percentage
	var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
	document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
	document.getElementById(counter).innerHTML= percentage+"%"
	// color correction on style from CCFFF -> CC0000
	setcolor(document.getElementById(counter),percentage,"background-color");
	}
}

function setcolor(obj,percentage,prop){
	obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}
function title_php(url, title, width, height, color){
	if(color=='') 	color 	= '0/0/0';
	return '<img src="'+url+'inc/title.produs.php?title='+title+'&width='+width+'&height='+height+'&color='+color+'" border="0" alt="'+title+'">';
}

function ajaxBrowser(){
	var ajaxRequest;  // Variabilele sunt urmatoarele
 	try{
  	// Opera 8.0+, Firefox, Safari
  		ajaxRequest = new XMLHttpRequest();
		}catch (e){
  		// Internet Explorer Browsers
  		try{
   			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
  		}catch(e){
   		try{
    		ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
   			}catch (e){
    		// Daca ceva nu e in regula
    		alert("Your browser broke!");
    		return false;
   			}
 		}
	}
	return ajaxRequest;
}
/* ----------------------------------------------------
/* ajaxFunction */
function ajaxFunction(id, php, JID, JIA, friends){
	
	ajaxRequest = ajaxBrowser();
	ajaxRequest.onreadystatechange = function(){
		
		//document.getElementById("test_wait").innerHTML = "Server Time is : " + ajaxRequest.responseText;
		
		if(ajaxRequest.readyState == 1){
			if(JID != null || JIA != null){
			document.getElementById(JID).style.display = 'block';
			document.getElementById(JIA).style.display  = 'none';
			}
		}
		if(ajaxRequest.readyState == 4){
			if (ajaxRequest.status == 200) {
				e = document.getElementById(id);
				e.innerHTML = ajaxRequest.responseText;
				if(JID != null || JIA != null){
					document.getElementById(JID).style.display 	= 'none';
					document.getElementById(JIA).style.display  = 'block';
				}
	
				if(friends == true) ajaxFunction('friends', '../inc/inc.friends.php?pag=1');
			
			}
		}
	}
	 ajaxRequest.open("POST", php, true);
	 ajaxRequest.send(null); 
}



/* ----------------------------------------------------
/* ajaxFunction */
function ajaxTEST(id, php){
	
	ajaxRequest = ajaxBrowser();
	ajaxRequest.onreadystatechange = function(){
		
		//document.getElementById("test_wait").innerHTML = "Server Time is : " + ajaxRequest.responseText;
		
		if(ajaxRequest.readyState == 1){
		}
		if(ajaxRequest.readyState == 4){
			if (ajaxRequest.status == 200) {
				e = document.getElementById(id);
				e.innerHTML = ajaxRequest.responseText;
			}
		}
	}
	 ajaxRequest.open("POST", php, true);
	 ajaxRequest.send(null); 
}






function get(obj){
	
	/*
	var c = encodeURI(document.getElementById('Yid').value);
	var id = Base64["encode"](c);
	var x26rand = Math["floor"](Math["random"]()*100000);
	document.getElementById('f1_scan_note').style.display = 'none';
	ajaxFunction('myspan', '../../inc/inc.scan01.php?statusmessage=""&target=' + c + '&uid=' + id + '\x26rand=' + x26rand, 'f1_upload_process', 'myspan', true);
	*/
	
	/*
	var c = encodeURI(document.getElementById('Yid').value);
	document.getElementById('f1_scan_note').style.display = 'none';
	ajaxFunction('myspan', '../../inc/inc.scan.php?id=' + c, 'f1_upload_process', 'myspan', true);
	*/

	var c = encodeURI(document.getElementById('Yid').value);
	var ids = encode(c);
	var t = Math.random();
	document.getElementById('f1_scan_note').style.display = 'none';
	ajaxFunction('myspan', '../../inc/inc.scan01.php?target=' + c + '&id=' + ids + '&t' + t, 'f1_upload_process', 'myspan', true);
}

/*
function get_new(obj){
	var name = encodeURI(document.getElementById('Yid').value);
	var id = encode(name);

	document.getElementById('f1_scan_note').style.display = 'none';
	ajaxFunction('myspan', '../../inc/inc.scan_new.php?id=' + id + '&name=' + name, 'f1_upload_process', 'myspan', true);
}
*/

function new_get(target){
	
	/*
	var c = encodeURI(id);
	document.getElementById('Yid').value = id;

	var id = Base64["encode"](c);
	var x26rand = Math["floor"](Math["random"]()*100000);
	document.getElementById('f1_scan_note').style.display = 'none';
	ajaxFunction('myspan', '../../inc/inc.scan01.php?statusmessage=""&target=' + c + '&uid=' + id + '\x26rand=' + x26rand, 'f1_upload_process', 'myspan', true);
	*/
	
	/*
	var c = encodeURI(id);
	document.getElementById('f1_scan_note').style.display = 'none';
	document.getElementById('Yid').value = id;
	ajaxFunction('myspan', '../../inc/inc.scan.php?id=' + c, 'f1_upload_process', 'myspan', true);
	*/
	var target = encodeURI(target); //document.getElementById('Yid').value);
	var t = Math.random();
	var ids = encode(target);
	//var ids = encode(c);
	document.getElementById('f1_scan_note').style.display = 'none';
	document.getElementById('Yid').value = target;
	ajaxFunction('myspan', '../../inc/inc.scan01.php?target=' + target + '&id=' + ids + '&t' + t, 'f1_upload_process', 'myspan', true);
}

