/* function.js , functions for biggPimpin */

function addtag(tagName, tagId){
	liste = document.getElementById('liste');
	
	//Verifying if it exists
	var exists = 0;
	for(i=0; i<liste.length; i++){
		if(tagId == liste.options[i].value){
			//Test Alert
			alert("This Tag is already selected");
			exists = 1;
			break
		}
	}
	
	//Adding new Option
	if(!exists){
		newTag = new Option(tagName, tagId);
		liste.options[liste.options.length] = newTag;
	}
}

function removeTag(){
	liste = document.getElementById('liste');
	for(i = 0; i<liste.length; i++){
		if(liste.options[i].selected == true){
			liste.options[i] = null;
			i = i-1;
		}
	}
}

function validate(){
	liste = document.getElementById('liste');
	var tb_name = new Array();
	var tb_id = new Array();
	
	for(i = 0; i < liste.length; i++){
		tb_name.push(liste.options[i].text);
		tb_id.push(liste.options[i].value);
	}
	
	liste.length = 0;
	
	for(i = 0; i < tb_name.length; i++){
		p = new Option(tb_name[i], tb_id[i]);
		liste.options[i] = p;
		liste.options[i].selected = true;
	}
}

function page_init(){
	page = document.getElementById('page');
	page.value = 0;
}

function prevPage(){
	p = document.getElementById('page');
	if(p.value > 0){
		p.value--;
	}
	validate();
	document.getElementById('form1').submit();
}

function nextPage(){
	p = document.getElementById('page');
	p.value++;
	validate();
	document.getElementById('form1').submit();
}

function submitcomment(){
	submit = document.getElementById('submited');
	alarm = submit.value;
	submit.value = 1;
}


/* Image scaling functions */
function scaleImg() {
	if (fitsInWindow())
		return;
	what = document.getElementById('thepic');
	if(what.width==tableWidth()) {
		what.width=actualWidth;
		what.height=actualHeight;
		displayWarning("none");
	}else{
			what.style.cursor = "pointer";
			what.width=tableWidth();
			what.height = (actualHeight/actualWidth) * what.width;displayWarning("block");
	}
}

function liveResize() {
	if (fitsInWindow())
		return;
	what = document.getElementById('thepic');
	if (what.width!=actualWidth) {
		what.width=tableWidth();
		what.height = (actualHeight/actualWidth) * what.width;displayWarning("block");
	}
}

function setImgWidth() {
	if (fitsInWindow())return;
	document.getElementById('thepic').width=tableWidth();
	displayWarning("block");
}

function fitsInWindow() {
	if (actualWidth<tableWidth()) {
		displayWarning("none");
		return true;
	}
	return false;
}

function tableWidth() {
	return windowWidth()-100;
}

function windowWidth() {
	if (navigator.appName=="Netscape")
		return window.innerWidth;return document.body.offsetWidth;
}

function displayWarning(how) {
	document.getElementById('scalewarning').style.display=how;
}