// JavaScript Document

function phpads_deliverActiveX(content)
{
	document.write(content);	
}

function FlashHeader(divname)
{
	var so = new SWFObject("http://www.puellanova.pl/templates/Default/images/header_top.swf", "sotester", "942", "150", "8", "#f4c695");
	//so.addVariable("flashVarText", "this is passed in via FlashVars for example only"); // this line is optional, but this example uses the variable and displays this text inside the flash movie
	return so.write(divname);
}
function FlashAdd()
{
	/* <![CDATA[ */
	var bbs=screen,bbn=navigator,bbh;bbh='&ubl='+bbn.browserLanguage+'&ucc='+bbn.cpuClass+'&ucd='+bbs.colorDepth+'&uce='+bbn.cookieEnabled+'&udx='+bbs.deviceXDPI+'&udy='+bbs.deviceYDPI+'&usl='+bbn.systemLanguage+'&uje='+bbn.javaEnabled()+'&uah='+bbs.availHeight+'&uaw='+bbs.availWidth+'&ubd='+bbs.bufferDepth+'&uhe='+bbs.height+'&ulx='+bbs.logicalXDPI+'&uly='+bbs.logicalYDPI+'&use='+bbs.fontSmoothingEnabled+'&uto='+(new Date()).getTimezoneOffset()+'&uti='+(new Date()).getTime()+'&uui='+bbs.updateInterval+'&uul='+bbn.userLanguage+'&uwi='+bbs.width;
	document.write("<scr"+"ipt  language='JavaScript' type='text/javascript' src='http://ad2.pl.mediainter.net/please/showit/1037/1/2/30/?typkodu=js"+bbh+"&alttext=0&border=0&bust="+Math.random()+"&target=_blank'><"+"\/scr"+"ipt>");
	/* ]]> */
}

function GoToURL(URL)
{
	//if(confirm('{GLOBAL_CancelMessage}'))
	//{
		document.location.href=URL;
	//}
	//else
	//{
	//	return false;
	//}
}
	
function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}

function isChecked(object) {
    if (object.checked) return true;
    else return false;
}


//--------------------------------------------------------------------------------

/* Kalkulator - Poziom alkoholu we krwi */

function calculatorBAC(form) {
//	var ounces = eval(form.ounces.value);
	var message = '';
	var porcja = eval(form.porcja.value);
	var procent = eval(form.procent.value);
	var waga = eval(form.waga.value);
	var czas = eval(form.czas.value);
	var sex = eval(form.sex.value);

	for (i=0;i<form.sex.length;i++){ 
		if(form.sex[i].checked){ 
		
			if(form.sex[i].value == "K") {
				var sex_res = 0.6;			}
			
			if(form.sex[i].value == "M") {
				var sex_res = 0.7;
			}	
		
		} 
	}
	
	var result = ((porcja * procent) / (100 * waga * sex_res)) - (czas * 0.015); 

	var result_formatted = round_decimals(result,2);
	
	if (result_formatted < 0) {
		result_formatted = 0.00;
		message = "Wype3nij wszystkie pola i spróbuj jeszcze raz.";
		form.bacamount.value = result_formatted + " %";

		form.error.value = message;

	}
	
	else {
		if (result_formatted == "NaN.00")
			result_formatted = 0.00;
			message = "Wype3nij wszystkie pola i spróbuj jeszcze raz."; 
		if (result_formatted > 0.20) 
			message = "Przekroczy3es dopuszczalna zawartosc alkoholu we krwi.";
		if (result_formatted > 4.50) 
		
			message = "Przekroczyłeś śmiertelną dawkę alkoholu we krwi :/.";
			
			
		if (result_formatted < 0.08 && result_formatted > 0)
			message = "Nie jestes w pe3ni odtruty.";
		}
		
		m = escape(message);
		m2 = unescape(message);
		form.message.value = message;
		
		form.bacamount.value = result_formatted + " %";
		
		HideContent('bac-form');
		ShowContent('bac-form-result')

}

function snapIn(jumpSpaces,position) { 

	var msg = "PuellaNova.pl"; 

	var out = ""; 
	
	for (var i=0; i<position; i++) { 
		out += msg.charAt(i);
	} 
	
	for (i=1;i<jumpSpaces;i++) { 
		out += " ";
	} 
	
	out += msg.charAt(position); 
	window.status = out;

	if (jumpSpaces <= 1) { 
		position++; 
	
	if (msg.charAt(position) == ' ') { 
		position++;
	} 
	
	jumpSpaces = 100-position 
	
	} else if (jumpSpaces >  3) { 
	
		jumpSpaces *= .09;
	
	} else { 
		
		jumpSpaces--;
	
	} 
	
	if (position != msg.length) { 
		
		var cmd = "snapIn(" + jumpSpaces + "," + position + ")"; 
		
		window.setTimeout(cmd,10); 
	
	} 

	return true;

}

function calculatorSK(form) 
{
	
	var norma = 0;
	var pmin = 0;
	var pmax = 0;
	
	var wiek = eval(form.sk_l.value);
	var aktywnosc = form.sk_a.options[form.sk_a.options.selectedIndex].value;

	for (i=0;i<form.sk_spec.length;i++){ 
		if(form.sk_spec[i].checked){ 
		
			if(form.sk_spec[i].value == "no") {
				var spec = 0;			
			}

			if(form.sk_spec[i].value == "preg") {
				var spec = 1;			
			}
			
			if(form.sk_spec[i].value == "karm") {
				var spec = 2;
			}	
		
		} 
	}
 

	for (i=0;i<form.sk_sex.length;i++){ 
		if(form.sk_sex[i].checked){ 
		
			if(form.sk_sex[i].value == "m") {
				var sex = 1;
			}
			
			if(form.sk_sex[i].value == "f") {
				var sex = 2;
			}	
		
		} 
	}


	//alert("Kalklulator jeszcze nie działa");

//	return true;

	
	if (wiek<=3) { norma="1300"; } //Dzieci 1-3
	if (wiek>=4&&wiek<7) { norma="1700"; } //Dzieci 4-6
	if (wiek>=7&&wiek<11) { norma="2100"; } //Dzieci 7-9
	if (wiek>=10&&wiek<13&&sex==1) { norma="2600"; } //Chłopcy 10-12
	if (wiek>=10&&wiek<13&&sex==2) { norma="2300"; } //Dziewczęta 10-12
	if (wiek>=13&&wiek<16&&sex==1) { norma="p"; pmin="3000"; pmax="3300"; }
	if (wiek>=13&&wiek<16&&sex==2) { norma="p"; pmin="2600"; pmax="2800"; }
	if (wiek>=16&&wiek<21&&sex==1) { norma="p"; pmin="3200"; pmax="3700"; }
	if (wiek>=16&&wiek<21&&sex==2) { norma="p"; pmin="2500"; pmax="2700"; }
	if (wiek>=21&&wiek<65&&sex==1&&aktywnosc==1) { norma="p"; pmin="2400"; pmax="2600"; }
	if (wiek>=21&&wiek<65&&sex==1&&aktywnosc==2) { norma="p"; pmin="2800"; pmax="3200"; }
	if (wiek>=21&&wiek<65&&sex==1&&aktywnosc==3) { norma="p"; pmin="3500"; pmax="4000"; }
	if (wiek>=21&&wiek<65&&sex==1&&aktywnosc==4) { norma="p"; pmin="4000"; pmax="4500"; }
	if (wiek>=21&&wiek<60&&sex==2&&aktywnosc==1) { norma="p"; pmin="2100"; pmax="2300"; }
	if (wiek>=21&&wiek<60&&sex==2&&aktywnosc==2) { norma="p"; pmin="2400"; pmax="2800"; }
	if (wiek>=21&&wiek<60&&sex==2&&aktywnosc==3) { norma="p"; pmin="2900"; pmax="3200"; }
	if (wiek>=21&&wiek<60&&sex==2&&aktywnosc==4) { norma="p"; pmin="2900"; pmax="3200"; }
	if (wiek>=65&&wiek<76&&sex==1) { norma="2300"; } //MężczyĽni 65-75 lat
	if (wiek>=75&&sex==1) { norma="2100"; } //MężczyĽni powyżej 75 lat
	if (wiek>=60&&wiek<76&&sex==2) { norma="2200"; } //Kobiety 65-75 lat
	if (wiek>=75&&sex==2) { norma="2000"; } //Kobiety powyżej 75 lat
	if (spec==1) { norma="2800"; } //Kobiety ciężarne (II połowa ciąży)
	if (spec==2) { norma="3400"; } //Kobiety karmiące


	//alert('Norma: '+norma+' min:'+pmin+' max:'+pmax+' | Wiek:'+wiek+' | Sex:'+sex+' | Aktywnosc:'+aktywnosc+' | Spec:'+spec);
	
	if(norma!="p")
		resultformated = norma;
	else
		resultformated = pmin+' - '+pmax;
		
	form.result.value = resultformated;
	

	HideContent('sk-form-step1');
	ShowContent('sk-form-step2')


}

function addElement() 
{
 	
	if(document.getElementById('razem').value == '')
		var razem =  0;
	else 
		var razem =  document.getElementById('razem').value;
	
	var ni = document.getElementById('myDiv');
	var numi = document.getElementById('theValue');
	var num = (document.getElementById('theValue').value -1)+ 2;

	var selected  = document.getElementById('produkt').options[document.getElementById('produkt').options.selectedIndex];
	var gramatura  = document.getElementById('gramatura').value;
	
	var prodname = selected.text;
	var prodcal = selected.value;

	//alert(razem)
	
	kcal = Math.round(gramatura*prodcal)/100;
	
	document.getElementById('razem').value = parseFloat(razem)+parseFloat(kcal);
	
	
	numi.value = num;
	var newdiv = document.createElement('div');
	var divIdName = 'my'+num+'Div';
	
	//alert(divIdName);
	
	newdiv.setAttribute('id',divIdName);
	//  newdiv.innerHTML = '+ '+num+' <b>'+prodname+'</b> '+gramatura+'g '+kcal+'kcal <a href=\'javascript:;\' onclick=removeElement("'+divIdName+'","'+kcal+'")><span class="red">- Usuń</span></b></a>';
	newdiv.innerHTML = '+ <b>'+prodname+'</b> '+gramatura+'g '+kcal+'kcal <a href=\'javascript:;\' onclick=removeElement("'+divIdName+'","'+kcal+'")><span class="red">- Usuń</span></b></a>';
	
	ni.appendChild(newdiv);
}

//onclick=removeElement("'+divIdName+'")

function removeElement(divNum,divKal) {
  var d = document.getElementById('myDiv');
  var olddiv = document.getElementById(divNum);

	if(document.getElementById('razem').value == '')
		var razem =  0;
	else 
		var razem =  document.getElementById('razem').value;

 
 	d.removeChild(olddiv);

	document.getElementById('razem').value = parseFloat(razem)-parseFloat(divKal);
}

var count = "1";
function addRow(in_tbl_name)
{
	var tbody = document.getElementById(in_tbl_name).getElementsByTagName("TBODY")[0];
	// create row
	var row = document.createElement("TR");
	// create table cell 1
	var td1 = document.createElement("TD")
	var strHtml1 = "<FONT>*</FONT>";
	td1.innerHTML = strHtml1.replace(/!count!/g,count);
	// create table cell 2
	var td2 = document.createElement("TD")
	var strHtml2 = "<SELECT NAME=\"produkt\">{ITEMS_LIST}</SELECT>";
	td2.innerHTML = strHtml2.replace(/!count!/g,count);
	// create table cell 3
	var td3 = document.createElement("TD")
	var strHtml3 = "<INPUT TYPE=\"text\" NAME=\"nowy\" SIZE=\"5\" MAXLENGTH=\"5\" >";
	td3.innerHTML = strHtml3.replace(/!count!/g,count);
	// create table cell 4
	var td4 = document.createElement("TD")
	var strHtml4 = "<INPUT TYPE=\"Button\" CLASS=\"Button\" onClick=\"delRow()\" VALUE=\"Delete Row\">";
	td4.innerHTML = strHtml4.replace(/!count!/g,count);
	// append data to row
	row.appendChild(td1);
	row.appendChild(td2);
	row.appendChild(td3);
	row.appendChild(td4);
	// add to count variable
	count = parseInt(count) + 1;
	// append row to table
	tbody.appendChild(row);
}

function delRow()
{
	var current = window.event.srcElement;
	//here we will delete the line
	while ( (current = current.parentElement)  && current.tagName !="TR");
			 current.parentElement.removeChild(current);
}

function calculatorKP(form) 
{
//	var ounces = eval(form.ounces.value);
	var kpresult = '';
	var pap_na_dzien = eval(form.p_nd.value);
	var pap_w_paczce = eval(form.p_wp.value);
	var koszt_paczki = eval(form.p_kp.value);
	var wzrost_ceny_paczki = eval(form.p_wcp.value);
	
	paczka1rok = koszt_paczki;
	paczka2rok = koszt_paczki + (koszt_paczki * wzrost_ceny_paczki/100);
	paczkórok = paczka2rok + (paczka2rok * wzrost_ceny_paczki/100);
	
	koszt_1_papierosa = koszt_paczki / pap_w_paczce;
	
	koszt_1_papierosa_w_1_roku = paczka1rok / pap_w_paczce;
	koszt_1_papierosa_w_2_roku = paczka2rok / pap_w_paczce;
	koszt_1_papierosa_w_3_roku = paczkórok / pap_w_paczce;
	
	rok = 365;
	
	var result = ((koszt_1_papierosa_w_1_roku * pap_na_dzien) * rok);

	var result_3_rok = ((koszt_1_papierosa_w_1_roku * pap_na_dzien) * rok) 
						
						+ ((koszt_1_papierosa_w_2_roku * pap_na_dzien) * rok)
						
						+ ((koszt_1_papierosa_w_3_roku * pap_na_dzien) * rok);
						
						
						



	//var result_3_rok = result + result_2_rok + (result_2_rok * (wzrost_ceny_paczki/100));
	
	//var result = ((porcja * procent) / (100 * waga * sex_res)) - (czas * 0.015); 

	var result_formatted = round_decimals(result,2);

	var result_formatted2 = round_decimals(result_3_rok,2);
	
	if (result_formatted < 0) {
		result_formatted = 0.00;
		kpresult = "Wypelnij wszystkie pola i spróbuj jeszcze raz.";
		
		form.kpresult.value = result_formatted;
	}
	
	else if (result_formatted > 0) {
		kpresult = "";
	}
	else {
		if (result_formatted == "NaN.00")
			result_formatted = 0.00;
			kpresult = "Wypelnij wszystkie pola i spróbuj jeszcze raz."; 
		if (result_formatted2 == "NaN.00")
			result_formatted2 = 0.00;
			kpresult = "Wypelnij wszystkie pola i spróbuj jeszcze raz."; 
		}
	
		form.kpresult.value = kpresult;
		form.kpresult.value = result_formatted + " zl / 1 rok \n" + result_formatted2 + " zl / 3 lata \n" + kpresult;

	
	HideContent('kp-form');
	ShowContent('kp-form-result')
}

    MONTHS = new Array();
    MONTHS[0]="Styczen";  MONTHS[1]="Luty"; MONTHS[2]="Marzec";
    MONTHS[3]="Kwiecien"; MONTHS[4]="Maj";  MONTHS[5]="Czerwiec";
    MONTHS[6]="Lipiec";   MONTHS[7]="Sierpien"; MONTHS[8]="Wrzesien";
    MONTHS[9]="PaLdziernik"; MONTHS[10]="Listopad"; MONTHS[11]="Grudzien";


function numofdays (y,m)
{
	var n;
	if ((m==1)||(m==3)||(m==5)||(m==7)||(m==8)||(m==10)||(m==12)) {n=31;}
	else {if ((m==4)||(m==6)||(m==9)||(m==11)) {n=30;}
	else {if (y%4==0) {if (y%100==0) {if (y%400==0) {n=29;} else {n=28;}}
	else {n=29;}}
	else { n=28; }}}
	return n;
}
	
function calculatorDP(form) {
	
	var kpresult = '';
	
	cd = eval(form.fd.value);
    cm = eval(form.fm.value);
    cy = eval(form.fy.value);
	fc = eval(form.fc.value);
	
	t = new Date();
    //cd=t.getDate(); cm=t.getMonth()+1; cy=t.getYear(); if (cy<2000) { cy=2000; }
	
	//cy=t.getYear(); if (cy<2000) { cy=2000; }
	
	n = numofdays(cy,cm);
	
	
	 //n=numofdays(cy,cm);
	 
	//n = form.fd.length;
	
	while (n>cd) {
		n--;
	};
	
	 
	 a = form.fc.value - 14;
	 
	 ld = cd + a - 4;
	 lm = cm;
	 ly = cy;
	 
	 hd = cd + a + 3;
	 hm = cm;
	 hy = cy;
	 
	 while (ld > numofdays(ly,lm)) { 
		ld = ld - numofdays(ly,lm); 
		lm++; 
		if (lm > 12) {
			lm = 1;
			ly++;
		} 
	 }
	 while (hd > numofdays(hy,hm)) { 
		hd = hd - numofdays(hy,hm); 
		hm++; 
		if (hm > 12) { 
			hm = 1;
			hy++;
		} 
	 }
	 while (ld<=0) { 
	 
		lm--;
		if (lm < 1) { 
			lm = 12;
			ly--;
		} 
		ld = ld + numofdays(ly,lm); 
	 }
	 
	 while (hd <= 0) { 
		hm--;
		if (hm < 1) { 
			hm = 12;
			hy--;
		} 
		ld = hd + numofdays(hy,hm); 
	 }
	 
 	// form.fl.value = numofdays(cy,cm);
	
	if(lm > 12) {

		message = "Niepoprawny miesiac [1-12]. Sprubój jeszcze raz."; 
		form.message.value = message;
	} else if(fc < 21) {
		
		message = "Twój cykl jest krótszy niz 21 dni, skonsultuj sie z lekarzem.";
		form.message.value = message;

	} else if(fc > 35) {
		
		message = "Twój cykl jest dÂ3uzszy niz 36 dni, skonsultuj sie z lekarzem.";
		form.message.value = message;

	} else {
	
		form.fl.value = ld+" "+MONTHS[lm-1]+" "+ly;
		 
		form.fh.value = hd+" "+MONTHS[hm-1]+" "+hy;
		 
		
		HideContent('dp-form');
		ShowContent('dp-form-result')
	
	}

}

function calculatorBMI(form) {
	
	var message = '';
	var bmi_kg = eval(form.bmi_kg.value);
	var bmi_m = eval(form.bmi_m.value);
	var bmi_l = eval(form.bmi_l.value);
	//var bmi_sex = eval(form.bmi_sex.value);
	
	//var sex = form.sex.value;
	
	//var sex_res = '';
	
	//alk = (porcja * (procent / 100) * 0.8);
	
	for (i=0;i<form.bmi_sex.length;i++){ 
		if(form.bmi_sex[i].checked){ 
		
			if(form.bmi_sex[i].value == "K") {
				var sex_res = 0;			}
			
			if(form.bmi_sex[i].value == "M") {
				var sex_res = 1;
			}	
		
		} 
	}

	//$tluszcz = 1.2*$bmi + 0.23*$_POST['bmi_l'] - (10.8*$_POST['bmi_p']) - 5.5;
	

	
	resultbmi = (bmi_kg / (bmi_m * bmi_m)) * 10000;
	resultt = 1.2*resultbmi + 0.23*bmi_l - (10.8*sex_res) - 5.4;
	
	result_formatted = round_decimals(resultbmi,2);
	result_formatted2 = round_decimals(resultt,2);

	if(resultbmi < 15) {
		message = "BMI ponizej 15 oznacza NIEDOWAGE! Skorzystaj z porady lekaza! Zagrozenie zycia!."; 
	} else if(resultbmi > 15 && resultbmi < 19) {
		message = "BMI w granicach 15 - 19 oznacza niedowage! Skorzystaj z porady lekarza! Zagrozenie anoreksja. Brak kalorii tez zabija!."; 
	} else if(resultbmi > 19 && resultbmi < 25) {
		message = "Gratulacje! Twoja waga jest idealna!."; 
	} else if(resultbmi > 25 && resultbmi < 30) {
		message = "BMI w granicach 25 - 30 oznacza nadwage! Jeszcze nie jest niebezpiecznie, ale pomyzl o diecie i zacznij uprawie sport. Zagrozenie otylosci?!."; 
	} else if(resultbmi > 30 && resultbmi < 40) {
		message = "BMI w granicach 30 - 40 oznacza otylosc, która zagraza zdrowiu, wybierz sie do lekarza jak najszybciej. Zagrozenie takimi chorobami, jak cykrzyca, choroby serca."; 
	} else if(resultbmi >= 40) {
		message = "BMI powyzej 40 oznacza OTYLOSC zagrazajaca zyciu!."; 
	}
	
	form.message.value = message;
	form.bmiresult1.value = result_formatted + "  ";
	form.bmiresult2.value = "  " + result_formatted2 + " %";
	
	
	HideContent('bmi-form');
	ShowContent('bmi-form-result')


}

function CheckAddCommentFormFunction(MSG1, MSG2)
{
	
	if(document.getElementById("fTitle").value == "")
	{
		alert(MSG1);
    document.getElementById("fTitle").style.borderColor  = '#da251d';
    document.getElementById("fTitle").style.background = '#f9e0df';
		document.getElementById("fTitle").focus();
		
		return false;
	}

	if(document.getElementById("fContent").value == "")
	{
		alert(MSG2);
		
    document.getElementById("fContent").style.borderColor  = '#da251d';
    document.getElementById("fContent").style.background = '#f9e0df';
		document.getElementById("fContent").focus();
		
		return false;
	}

	return true;	
	
}

function CheckLoginForm(MSG1, MSG2)
{
	if(document.getElementById("Username").value == "")
	{
		alert(MSG1);
		document.getElementById("Username").focus();
		return false;
	}

	if(document.getElementById("Password").value == "")
	{
		alert(MSG2);
		document.getElementById("Password").focus();
		return false;
	}

	return true;
}

function CheckBigLoginForm(MSG1, MSG2)
{
	if(document.getElementById("bUsername").value == "")
	{
		alert(MSG1);
		document.getElementById("bUsername").focus();
		return false;
	}

	if(document.getElementById("bPassword").value == "")
	{
		alert(MSG2);
		document.getElementById("bPassword").focus();
		return false;
	}

	return true;
}

function CheckPassLoginForm(MSG1, MSG2, MSG3)
{
	if(document.getElementById("fbUsername").value == "")
	{
		alert(MSG1);

		document.getElementById("fbUsername").style.borderColor  = '#da251d';
		document.getElementById("fbUsername").focus();
		return false;
	}

	if(document.getElementById("fbPassword").value == "")
	{
		alert(MSG2);
		document.getElementById("fbPassword").focus();
		return false;
	}

	if((document.getElementById("fbPassword").value) != (document.getElementById("fcbPassword").value))
	{
		alert(MSG2);
		document.getElementById("fbPassword").style.borderColor  = '#da251d';
		document.getElementById("fcbPassword").style.borderColor  = '#da251d';
			
		return false;
	}		
		
	return true;
}


// CLEAR DEFAULT VALUE

function clearText(thefield) 
{
	if (thefield.defaultValue==thefield.value)
	thefield.value = ""
} 

function ReplaceToNum(thefield) 
{
	
	if(thefield.value.match(/[^0-9^.]/))
		thefield.value=thefield.value.replace(/[^0-9]/g,'');
	
	//return true;

}

function setBg(elem) 
{
    if (document.getElementById) {
      elem.style.borderColor  = '#333333';
    }
	if (elem.value == elem.defaultValue)
		elem.value = ""

}

function setRedBg(elem) 
{
    if (document.getElementById) {
      elem.style.borderColor  = '#ff0000';
    }
}

function removeBg(elem) 
{ 
	//clearall(); 
	//var bg2 = "#ffcccc"; 	
	elem.style.borderColor = ""; 
	if (elem.value == '')
		elem.value = elem.defaultValue;
	else 
		elem.value = elem.value;
} 

function CheckEmail(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}


// SHOW HIDE CONTENT

function HideContent(d) 
{
	document.getElementById(d).style.display = "none";
}
function ShowContent(d) 
{
	document.getElementById(d).style.display = "";
}

function DisableFormItem(d) 
{
	
	namen = document.getElementById(d);
	//namen.disabled=true;
	
	for (i=0;i<document.getElementById(d).length;i++)
	{ 

		document.namen[i].disabled=true;
		
		alert('ok');
	}

}

function EnableFormItem(d) 
{
	document.getElementById(d).disabled=false;
}

function ReverseDisplay(d) 
{
	if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
	else { document.getElementById(d).style.display = "none"; }
}

function DisplayForm(form, rform) 
{
	document.getElementById(rform).style.display = "none";
	document.getElementById(form).style.display = "";
}

function CheckLength(form, textarea) 
{
	var MaxLength = 1000;

	biolen = textarea.value.length;

	if (biolen > MaxLength) {
		form.textarea.value = form.textarea.value.substr(0, MaxLength);
		return;
	}

	var RemainingLength = (MaxLength - biolen);
	//limitcheck = '{LANG_authBioTypeAnother}' + RemainingLength + '{LANG_authBioTypeAnotherCharacters}';
	limitcheck = RemainingLength;
	
	document.getElementById('biolength').innerHTML = limitcheck;
}


function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function CheckUsernameExists(){
	if(document.getElementById('rUsername').value.length > 0){
		what = "CheckUsernameReturn(req.responseXML)";
		DoCallback("w=CheckUsername" + "&Username=" + document.getElementById('Username').value	);
		return true;
	}
}

function CheckUsernameReturn(returned){
		
		// get the status of the ajax response
		// our getXMLData function relies on a global variable called 'xml'
		// so we just put the response into that.
		xml = returned.documentElement;
		var status = getXMLData('status');

		if(status == 1){
			// user account was successfully create
			document.getElementById("UsernameCheck").innerHTML =  getXMLData('message');
			return true;
			
		}else{
			document.getElementById("UsernameCheck").innerHTML = '%%LNG_UsernameError%%';
			return false;
		}

}

function CheckUserForm(form,LANG1,LANG2,LANG3,LANG4,LANG5,LANG6,LANG7)
{
	if(form == "rform") { 

		var username = document.getElementById('rUsername');
		var password = document.getElementById('rPassword');
		var passwordc = document.getElementById('rPasswordConfirm');
		var fname = document.getElementById('rFirstName');
		var sname = document.getElementById('rLastName');
		var email = document.getElementById('rEmail');
		
		if(username.value == "")
		{
			alert(LANG1);
			username.focus();
			username.style.borderColor  = '#da251d';
			username.style.background = '#f9e0df';
			
			return false;
		}
		
		if(password.value == "")
		{
			alert(LANG2);
			//password.focus();
	      password.style.borderColor  = '#da251d';
				password.style.background = '#f9e0df';

			return false;
		}
	
		if(password.value != passwordc.value)
		{
			alert(LANG3);
			
	        password.style.borderColor  = '#da251d';
	        passwordc.style.borderColor  = '#da251d';
					
			return false;
		}		

/*		if(fname.value == "")
		{
			alert(LANG4);
			//password.focus();
	      fname.style.borderColor  = '#da251d';
				fname.style.background = '#f9e0df';

			return false;
		}

		if(sname.value == "")
		{
			alert(LANG5);
			//password.focus();
	      sname.style.borderColor  = '#da251d';
				sname.style.background = '#f9e0df';
				
			return false;
		}*/
		
		if(email.value == "")
		{
			alert(LANG6);
			//password.focus();
	      email.style.borderColor  = '#da251d';
				email.style.background = '#f9e0df';
				
			return false;
		}
		
		if(email.value.indexOf('.') == -1 || email.value.indexOf('@') == -1)
		{
			alert(LANG7);
			//password.focus();
	      email.style.borderColor  = '#da251d';
				email.style.background = '#f9e0df';
				
			return false;
		}
		
	} else {
		alert("Form Error...")
	}

	return true;
}


function CheckUserConfirmForm(form,MSG1) {

	if(form == "cform") { 
	
		var cf1 = document.getElementById("cconfirm1");
		var cf2 = document.getElementById("cconfirm2");
		
		if ((cf1.checked == false) && (cf2.checked == false))
		{
			alert(MSG1);
			return false;
			
		}
	
	} else {
		alert("Form ERROR!");
	}
	
	return true;
}
	
/*
	if(form.form.getElementById("Password").value == "")
	{
		alert("{LNG_authNoPassword}");
		document.getElementById("Password").focus();
		return false;
	}

	if(document.form.getElementById("Password").value != document.form.getElementById("PasswordConfirm").value)
	{
		alert("%%LNG_authBadPassword%%");
		document.getElementById("Password").focus();
		document.getElementById("Password").select();
		return false;
	}

	if(document.getElementById("FirstName").value == "")
	{
		alert("%%LNG_authNoFirstName%%");
		document.getElementById("FirstName").focus();
		return false;
	}

	if(document.getElementById("LastName").value == "")
	{
		alert("%%LNG_authNoLastName%%");
		document.getElementById("LastName").focus();
		return false;
	}

	if(document.getElementById("Email").value == "")
	{
		alert("%%LNG_authNoEmail%%");
		document.getElementById("Email").focus();
		return false;
	}
	
	if(document.getElementById("Email").value.indexOf('.') == -1 || document.getElementById("Email").value.indexOf('@') == -1)
			{
				alert('This email address is not valid.');
				document.getElementById("Email").focus();
				document.getElementById("Email").select();
				return false;
			}

	if(document.getElementById("Biography").value == "")
	{
		alert("%%LNG_authNoBio%%");
		document.getElementById("Biography").focus();
		return false;
	}
*/

function popUp(url,w,h) {
  var x= (screen.width/2 - w/2);
  var y = (screen.height/2 - h/2);
    window.open(url,'','left='+x+',top='+y+',width='+w+',height='+h);
}

function popitup5(url, title, css, under, iwidth, iheight, colour) {
	var pwidth, pheight;
	
	if ( !newwindow || newwindow.closed ) {
	pwidth=iwidth+30;
	pheight=iheight+50;
	newwindow=window.open('','htmlname','width=' + pwidth +',height=' +pheight + ',top=0,left=10,resizable=0,scrollbars=no,menubar=no');
	
 
	
	if (iheight >= screen.availHeight) iheight += 10;
	if (iwidth >= screen.availWidth)  iwidth += 10;

	newwindow.moveTo((screen.availWidth-iwidth)/2, (screen.availHeight-iheight)/2);

	wheight=iheight;
	wwidth=iwidth;
	}
	
	if (wheight!=iheight || wwidth!=iwidth ) {
	pwidth=iwidth+10;
	pheight=iheight+10;
	newwindow.resizeTo(pwidth, pheight);

	wheight=iheight;
	wwidth=iwidth;
	}
	
	newwindow.document.clear();
	newwindow.focus();
	newwindow.document.writeln('<html> <head> <title>' + title + '<\/title><link href=\"' + css +'\" rel=\"stylesheet\" type=\"text/css\" /><\/head> <body bgcolor= \"' + colour + '\" > <center>');
	newwindow.document.writeln('<a href="javascript:window.close()"><img src=' + url + ' title=\"' + title + '\" alt=\"' + title + '\" class=\"gallimage\"></a>');
	newwindow.document.writeln('<\/center><center>' + under +'</center><\/body> <\/html>');
	newwindow.document.close();
	newwindow.focus();
	}

// Routines to tidy up popup windows when page is left
// Call with an onUnload="tidy5()" in body tag
var newwindow;
var wheight = 0, wwidth = 0;

function tidy5() {
	if (newwindow && !newwindow.closed) { newwindow.close(); }
}

function selecturl(s) {
	var gourl = s.options[s.selectedIndex].value; window.top.location.href = gourl;
}

// DODAJ DO ULUBIONYCH Z FLASHA
function bookmarkit(){
	window.external.addFavorite('http://puellanova.pl','PuellaNova - Internetowe Pismo Kobiece')
}

function mm_setAsHomePage()
{
  if (ie5 || ie55) {
    itemObj = gmobj("el" + _itemRef);
    itemObj.style.behavior = "url(#default#homepage)";
    itemObj.setHomepage(location.href);
  }
  else
    alert("Sorry, your browser does not support this function.");
}


//Kalendarz
var months = new Array("1", "2", "3","4", "5", "6", "7", "8", "9","10", "11", "12");
var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31,30, 31, 30, 31);
var days = new Array("SU","MO", "TU", "WE","TH", "FR", "SA");
var classTemp;
var today=new getToday();
var year=today.year;
var month=today.month;
var newCal; 

function getDays(month, year) {
	if (1 == month) return ((0 == year % 4) && (0 != (year % 100))) ||(0 == year % 400) ? 29 : 28;
	else return daysInMonth[month];
}

function getToday() {
	this.now = new Date();
	this.year = this.now.getFullYear();
	this.month = this.now.getMonth();
	this.day = this.now.getDate();
}

function Calendar() {
	newCal = new Date(year,month,1);
	today = new getToday(); 
	var day = -1;
	var startDay = newCal.getDay();
	var endDay=getDays(newCal.getMonth(), newCal.getFullYear());
	var daily = 0;
	
	if ((today.year == newCal.getFullYear()) &&(today.month == newCal.getMonth()))
	{
	day = today.day;
	}
	var caltable = document.all.caltable.tBodies.calendar;
	var intDaysInMonth =getDays(newCal.getMonth(), newCal.getFullYear());
	
	for (var intWeek = 0; intWeek < caltable.rows.length;intWeek++)
	for (var intDay = 0;intDay < caltable.rows[intWeek].cells.length;intDay++)
	{
	var cell = caltable.rows[intWeek].cells[intDay];
	var montemp=(newCal.getMonth()+1)<10?("0"+(newCal.getMonth()+1)):(newCal.getMonth()+1); 
	if ((intDay == startDay) && (0 == daily)){ daily = 1;}
	var daytemp=daily<10?("0"+daily):(daily);
	var d="<"+newCal.getFullYear()+"-"+montemp+"-"+daytemp+">";
	if(day==daily) cell.className="DayNow";
	else if(intDay==6) cell.className = "DaySat";
	else if (intDay==0) cell.className ="DaySun";
	else cell.className="Day";
	if ((daily > 0) && (daily <= intDaysInMonth))
	{
	cell.innerText = daily;
	daily++;
	} else
	{
	cell.className="CalendarTD";
	cell.innerText = "";
	}
}
	document.all.year.value=year;
	document.all.month.value=month+1;
}

function subMonth()
{
	if ((month-1)<0)
	{
		month=11;
		year=year-1;
	} else
	{
		month=month-1;
	}
	Calendar();
}

function addMonth()
{
	if((month+1)>11)
	{
		month=0;
		year=year+1;
	} else
	{
		month=month+1;
	}
	Calendar();
}

function setDate() 
{
	if (document.all.month.value<1||document.all.month.value>12)
	{
	alert("Effect month is between 1--12");
	return;
}
	year=Math.ceil(document.all.year.value);
	month=Math.ceil(document.all.month.value-1);
	Calendar();
}
 
function buttonOver()
{
	var obj = window.event.srcElement;
	obj.runtimeStyle.cssText = "background-color:#FFFFFF";
	// obj.className="Hover";
}

function buttonOut()
{
	var obj = window.event.srcElement;
	window.setTimeout(function(){obj.runtimeStyle.cssText = "";},300);
}

//-------------------------------------------------------------------------------------------------------//
// GALERIA //
 
function changePhoto( sFile, iMediaID, sTitle, sAuthor, sAlbumName, iRate, rateSum, rateCount )
{
	var oOldImg = document.getElementById("temPhotoID");
//	oOldImg.style.backgroundImage = "url(images/galleries/"+sAlbumName+"normal_"+sFile+")";
	oOldImg.style.backgroundImage = "url(../../images/galleries/"+sAlbumName+sFile+")";
	
	
	//alert("http://localhost/04.2008.PuellaNova/images/galleries/"+sAlbumName+"normal_"+sFile+"");
	changeTitle( sTitle );
	changePicAuthor ( sAuthor );
	//changeRate( iRate, rateSum, rateCount );
	changeMediaID( iMediaID );
	changeRating ( iRate );
	return false;
}

function changeTitle( sTitle )
{
	var oTitleDiv = document.getElementById("sTitleDiv");
	oTitleDiv.innerHTML = sTitle;
}
			
function changeMediaID( iMediaID )
{
	var oPhotoID = document.getElementById("sPicID");
	oPhotoID.innerHTML = iMediaID;
}

function changePicAuthor( sAuthor )
{
	var oAuthorDiv = document.getElementById("sAuthorDiv");
	oAuthorDiv.innerHTML = sAuthor;
}

function changeRating( iRate )
{
	var oAuthorDiv = document.getElementById("sRating");
	oAuthorDiv.innerHTML = iRate;
}

function ShowUploadForm() 
{
	document.getElementById("iUploadForm").style.display = "";
	document.getElementById("iUploadFormTitleHide").style.display = "";
	document.getElementById("iUploadFormTitleShow").style.display = "none";
}

function HideUploadForm() 
{
	document.getElementById("iUploadFormTitleHide").style.display = "none";
	document.getElementById("iUploadFormTitleShow").style.display = "";
	document.getElementById("iUploadForm").style.display = "none";
}

function charCounter(field,maxLength,countTarget)
{

	field = document.getElementById(field);
	countTarget = document.getElementById(countTarget);
	var inputLength=field.value.length;

	if(inputLength >= maxLength)
	{
		field.value=field.value.substring(0,maxLength);

	}
	countTarget.innerHTML=maxLength-field.value.length;
}

function ConfirmDeleteUser(UserId)
{
	if(confirm('Czy usun&#261;&#263; to konto?'))
	{
		document.location.href = 'index.php?option=user&action=deleteaccount&userId='+UserId;
	}
}
		

// End of JavaScript