function cd() {
 	mins = 1 * m("00"); // change minutes here
 	secs = 0 + s(":30"); // change seconds here (always add an additional second to your total)
 	redo();
}

function m(obj) {
 	for(var i = 0; i < obj.length; i++) {
  		if(obj.substring(i, i + 1) == ":")
  		break;
 	}
 	return(obj.substring(0, i));
}

function s(obj) {
 	for(var i = 0; i < obj.length; i++) {
  		if(obj.substring(i, i + 1) == ":")
  		break;
 	}
 	return(obj.substring(i + 1, obj.length));
}

function dis(mins,secs) {
 	var disp;
 	if(mins <= 9) {
  		disp = " 0";
 	} else {
  		disp = " ";
 	}
 	disp += mins + ":";
 	if(secs <= 9) {
  		disp += "0" + secs;
 	} else {
  		disp += secs;
 	}
 	return(disp);
}

function redo() {
 	secs--;
 	if(secs == -1) {
  		secs = 59;
  		mins--;
 	}
 	document.cd.disp.value = dis(mins,secs); // setup additional displays here.
 	if((mins == 0) && (secs == 0)) {
  		//window.alert("Time is up. Press OK to continue.");
  		window.location = "<?=$out['link']?>";
 	} else {
 		cd = setTimeout("redo()", 1000);
 	}
}

function init() {
  cd();
}

/* color table */
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;	
}
/* ----------------------------------------------------
/* toggleDisplay */
function toggleDisplay(element) {
    var style;

    if (typeof element == 'string')
        element = document.getElementById ? document.getElementById(element) : null;
    if (element && (style = element.style))
        style.display = (style.display == 'none') ? 'block' : 'none';
}

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){
	
	ajaxRequest = ajaxBrowser();
	ajaxRequest.onreadystatechange = function(){
		
		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;
				//document.location.href =  'http://' + Tlink;
				
				if(JID != null || JIA != null){
					document.getElementById(JID).style.display 	= 'none';
					document.getElementById(JIA).style.display  = 'block';
				}
			}
		}
	}
	 ajaxRequest.open("GET", php, true);
	 ajaxRequest.send(null); 
}

/* ----------------------------------------------------
/* ajaxFunction */
function Msort(id, Mload, get_sort, Mref){
	ajaxFunction(id, '../../inc/cookie.set.php?sort=' + get_sort, Mload, id, Mref);
}
