var W3CDOM = (document.createElement && document.getElementsByTagName);

var Color= new Array();
Color[7] = "ff";
Color[6] = "ee";
Color[5] = "dd";
Color[4] = "cc";
Color[3] = "bb";
Color[2] = "aa";
Color[1] = "99";

function fadeBackground(objectname, phase) {

	if (!objectname) return;
	if (!document.getElementById(objectname)) return;
	
	if ((phase >= 1) && (phase < 8)) {
		document.getElementById(objectname).style.padding= "10px 0px";
		document.getElementById(objectname).style.backgroundColor = "#ffff" + Color[phase];
		phase++;
		if (phase < 8) setTimeout("fadeBackground('" + objectname + "', '" + phase + "')", 200);
		else {
			document.getElementById(objectname).style.padding= "0px 0px";
		}
	}
	
	return;
}

function changeImages(imageName, k) {

	if (k > 0) {
		for (i = 1; i <= 5; i++) {
			swapImage(imageName + i, 'images/rate/rate_star_off.png');
		}
		for (i = 1; i <= k; i++) {
			swapImage(imageName + i, 'images/rate/rate_star_on.png');
		}
	} else for (i = 1; i <= 5; i++) restoreImage(imageName + i);
}

function swapImage(imageName, newImage) {
	var newimage = new Image();
	newimage.src = newImage;
	if (!document.IMGS) document.IMGS = new Array();
	if (!document.IMGS[imageName]) {
		document.IMGS[imageName] = new Image();
		document.IMGS[imageName].src = document.images[imageName].src;
	}
    document.images[imageName].src = newimage.src;
}

function restoreImage(imageName) {
	if (!document.IMGS) document.IMGS = new Array();
	if (document.IMGS[imageName]) document.images[imageName].src = document.IMGS[imageName].src;
}

function hideAnswers(endpos) {

	for (i = 0; i < endpos; i++) {
		visibility(false, 'im_answer_'+i);
	}
}

function showAnswers() {

	for (i = 0; i < 255; i++) {
		visibility(true, 'im_answer_'+i);
	}
}

function im_new_message_submit() {

	if (document.im_new_message_form.im_message.value.length < 10) {
		alert('Kérlek ne felejts el hozzászólást írni!');
		return;
	}
	else {
		document.im_new_message_form.submit();
	}
}

function sgnbox_check() {

	var count = 0;
    for (i = 0; i < 4; i++) {
		var n = document.sgnbox_new_form["sgtypes[" + i + "]"].checked;
		if (n) {
			count++;
		}
	}
	return count;
}

function sgnbox_submit() {

	if (!sgnbox_check()) {
		alert('Egy problémát mindenképpen meg kell jelölnöd!');
		return;
	}
	alert('Köszönjük észrevételed!');
	document.sgnbox_new_form.submit();
}

function change_background(obj, bg_str) {
    if (document.all) {
		window.document.all(obj).style.background=bg_str;
		// window.document.all(obj).style.background=bg_str;
    }
    else
	if (document.getElementById) {
		document.getElementById(obj).style.display='';
		// document.getElementById(obj).style.background=bg_str;
	}
    return true;
}

var opened = 0;
var bulletsOn = new Array();
var currentStar = 0;
var lpnr = 0;

c = 255;
l = 0;
function a() {
	if (c > 0) {
		document.getElementById("content").style.color="rgb(" + c + "," + c + "," + c + ")";
		setTimeout('a()', 40);
		c -= 5; // valtoztassuk a szinet
	}
	else if (l < 255) {
		document.getElementById("content").style.color="rgb(" + l + "," + l + "," + l + ")";
		setTimeout('a()', 40);
		l += 5; // valtoztassuk a szinet
	}
	if (l == 255) {
		l = 0;
		c = 255;
	}
}

function show_f_answer(num) {
	// nyitott eltuntetese
    if (opened > 0) {
		visibility('change','f_question' + opened);
		visibility('change','f_answer' + opened);
    }
	// aktualis kinyitasa
	visibility('change','f_question' + num);
   	visibility('change','f_answer' + num);
	opened = num;
    
}

function show_cc_f_answer(num) {
	// nyitott eltuntetese
    if (opened > 0) {
		visibility('change','cc_f_question' + opened);
		visibility('change','cc_f_answer' + opened);
    }
	// aktualis kinyitasa
	visibility('change','cc_f_question' + num);
   	visibility('change','cc_f_answer' + num);
	opened = num;
    
}

function show_dvdshop_f_answer(num) {
	// nyitott eltuntetese
    if (opened > 0) {
		visibility('change','dvdshop_f_question' + opened);
		visibility('change','dvdshop_f_answer' + opened);
    }
	// aktualis kinyitasa
	visibility('change','dvdshop_f_question' + num);
   	visibility('change','dvdshop_f_answer' + num);
	opened = num;
    
}

function open_bigpic_window(url) {
	if (url != '') window.open(url,'','resizable=no,width=310,height=310,scrollbars=no');
}

function lendIt(movie_id, imageName, small) {
	var selected = 0;
	var reqStr = '';

	if ((imageName) && (document.images[imageName].src.indexOf("already_wishlist") > 0)) {
		alert('Ez a film már szerepel a kívánságlistádon!');
		return;
	}

	for (bullet in bulletsOn) {
		if (bulletsOn[bullet].value == 'clicked') {
			selected++;
			if (reqStr == '') reqStr = 'id[' + selected + ']=' + bullet.substring(bullet.length-1);
			else reqStr = reqStr + '&id[' + selected + ']=' + bullet.substring(bullet.length-1);
		}
	}
	if (lpnr > 1) {
		if (selected < 1) {
			alert('Legalább 1 lemezt meg kell jelölnöd!');
			return;
		}
	}
	else reqStr = '';
	
	if (reqStr == '') reqStr = 'index.ftx?module=rents&action=addqueue&small=' + small + '&iname=' + imageName + '&m_id=' + movie_id;
	else reqStr = 'index.ftx?module=rents&action=addqueue&small=' + small + '&iname=' + imageName + '&m_id=' + movie_id + '&' + reqStr;

	document.getElementById('nullframe').src = reqStr;

	/*
	parent.wltracker.location.href="?module=browse&action=wltracker";
	if (imageName) {
		if (small) swapImage(imageName, 'images/item/item_already_wishlist_button_small.png');
		else swapImage(imageName, 'images/item/item_already_wishlist_button.png');
	}
	*/
}

function bulletClick(bulletName) {
	// if (!bulletsOn) bulletsOn = new Array();
	
	if (!bulletsOn[bulletName]) bulletsOn[bulletName] = new String;
	
	if (bulletsOn[bulletName].value == 'clicked') {
		bulletsOn[bulletName].value = '';
		bulletOn(bulletName, false);
	}
	else bulletsOn[bulletName].value = 'clicked';
}

function bulletOn(bulletName, action) {
	var newbullet = new Image();
	
	// if (!bulletsOn) bulletsOn = new Array();
	
	if (action) {
		if (!bulletsOn[bulletName]) bulletsOn[bulletName] = new String;
	}

	if ((action) || (bulletsOn[bulletName].value == 'clicked')) {
		newbullet.src = 'images/item/item_disc_bullet_on.png';
	}
	else if (bulletsOn[bulletName] != 'clicked') newbullet.src = 'images/item/item_disc_bullet.png';

	document.images[bulletName].src = newbullet.src;	
}

function bulletsClear() {

	for (bullet in bulletsOn) {
		if (bulletsOn[bullet].value == 'clicked') {
			bulletsOn[bullet].value = '';
			bulletOn(bullet, false);
		}
	}
}

function changeImages(imageName, k, rankTitle, small) {

	if (small == 1) {
		var img1='images/rate/rate_small_none_off.png';
		var img2='images/rate/rate_small_star_off.png';
		var img3='images/rate/rate_small_star_on.png';
		var img4='images/rate/rate_small_none_on.png';
	}
	else {
		var img1='images/rate/rate_stop_off.png';
		var img2='images/rate/rate_star_off.png';
		var img3='images/rate/rate_star_on.png';
		var img4='images/rate/rate_stop_on.png';
	}

	if (k > 0) {
		swapImage(imageName + k, img1);
		// document.getElementById(rankTitle).innerHTML = textArray[k];
		for (i = 1; i <= 5; i++) {
			swapImage(imageName + i, img2);
		}
		for (i = 1; i <= k; i++) {
			swapImage(imageName + i, img3);
		}
	}
	if (k == -1) {
		swapImage(imageName + k, img4);
		// document.getElementById(rankTitle).innerHTML = 'nem érdekel';
	} 
	if (k == -2) {
		k++;
		restoreImage(imageName + k);
		/*
		if (textArray[currentStar] == '') {
			document.getElementById(rankTitle).innerHTML = 'nem érdekel';
		}
		else {
			document.getElementById(rankTitle).innerHTML = textArray[currentStar];
		}
		*/
		// swapImage(imageName + k, 'images/wishlist/rank_stop_off.gif');
	} 
	if (k == 0) {
		// document.getElementById(rankTitle).innerHTML = textArray[currentStar];
		for (i = 0; i <= 5; i++) restoreImage(imageName + i);
	}
}

function swapImage(imageName, newImage) {
	var newimage = new Image();
	newimage.src = newImage;
	if (!document.IMGS) document.IMGS = new Array();
	if (!document.IMGS[imageName]) {
		document.IMGS[imageName] = new Image();
		document.IMGS[imageName].src = document.images[imageName].src;
	}
    document.images[imageName].src = newimage.src;
}

function restoreImage(imageName) {
	if (!document.IMGS) document.IMGS = new Array();
	if (document.IMGS[imageName]) document.images[imageName].src = document.IMGS[imageName].src;
}

function set_current_value(starcount) {
	currentStar = starcount;
}

function sb_click(imageName, starcount, small) {
	
	set_current_value(starcount);
	window.location.href = 'index.ftx?setrating=1&rating=' + starcount + '&m_id='+ imageName;	
	// window.setTimeout("starbarSave("+imageName+", "+starcount+")", 10);
	starbarSave(imageName, starcount, small);
}

function starbarSave(imageName, starcount, small) {
	var star = new Image();
	var bullet = new Image();
	var bulletStopOn = new Image();
	var bulletStopOff = new Image();
	var temp_imageName;
	if (small == 1) {
		star.src = 'images/rate/rate_small_star_on.png';
		bullet.src = 'images/rate/rate_small_star_off.png';
		bulletStopOn.src = 'images/rate/rate_small_none_on.png';
		bulletStopOff.src = 'images/rate/rate_small_none_off.png';
	}
	else {
		star.src = 'images/rate/rate_star_on.png';
		bullet.src = 'images/rate/rate_star_off.png';
		bulletStopOn.src = 'images/rate/rate_stop_on.png';
		bulletStopOff.src = 'images/rate/rate_stop_off.png';
	}
	
	if (!document.IMGS) document.IMGS = new Array();
	
	if (starcount < 0) {
		temp_imageName = imageName + starcount;
		if (!document.IMGS[temp_imageName]) document.IMGS[temp_imageName] = new Image();
		document.IMGS[temp_imageName].src = bulletStopOn.src;
		document.images[temp_imageName].src = bulletStopOn.src;
		for (i = 1; i <= 5; i++) {
			temp_imageName = imageName + i;
			if (!document.IMGS[temp_imageName]) document.IMGS[temp_imageName] = new Image();
			document.IMGS[temp_imageName].src = bullet.src;
			document.images[temp_imageName].src = bullet.src;
		}
		return;
	}
	else {
		temp_imageName = imageName + '-1';
		if (!document.IMGS[temp_imageName]) document.IMGS[temp_imageName] = new Image();
		document.IMGS[temp_imageName].src = bulletStopOff.src;
		document.images[temp_imageName].src = bulletStopOff.src;
	}
	for (i = 1; i <= starcount; i++) {
		temp_imageName = imageName + i;
		if (!document.IMGS[temp_imageName]) document.IMGS[temp_imageName] = new Image();
		document.IMGS[temp_imageName].src = star.src;
		document.images[temp_imageName].src = star.src;
	}
	starcount++;
	for (i = starcount; i <= 5; i++) {
		temp_imageName = imageName + i;
		if (!document.IMGS[temp_imageName]) document.IMGS[temp_imageName] = new Image();
		document.IMGS[temp_imageName].src = bullet.src;
		document.images[temp_imageName].src = bullet.src;
	}						
}

function getWindowWidth() {
  
  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;
  }
  
  return myWidth;
  
}

function checkDIV(divname, minsize) {

	var current_width = 0;
	
	current_width = getWindowWidth();
	
	if (current_width < minsize) visibility(false, divname);
	else visibility(true, divname);
}

function tpointSelect(id) {

	for (i = 0; i < document.images.length; i++) {
		if (document.images[i].name.substring(0, 13) == 'select_button') {
			if (document.images[i].name == id) {
				document.images[i].src = 'images/rents/selected_button.png';
			}
			else {
				document.images[i].src = 'images/rents/select_button.png';
			}
		}
	}
}