function loadtwo(link1, link2, link3, link4, link5)
			{
			
			if (link1) parent.parent.frameA.location.href=link1;
			if (link2) parent.frameB.location.href=link2;
			if (link3) parent.frameC.location.href=link3;
			if (link4) parent.parent.frameD.location.href=link4;
			if (link5) parent.frameBC.location.href=link5;
			}

function loadmain(link1)
			{
			if (link1) top.main.location.href=link1;
			}

function loadfromA(link1, link2, link3, link4, link5)
			{
			if (link1) parent.frameA.location.href=link1;
			if (link2) parent.frameBCD.frameB.location.href=link2;
			if (link3) parent.frameBCD.frameC.location.href=link3;
			if (link4) parent.frameBCD.frameD.location.href=link4;
			if (link5) parent.frameBCD.location.href=link5;
			}

function loadfromB(link1, link2, link3, link4, link5)
			{
			if (link1) parent.parent.frameA.location.href=link1;
			if (link2) parent.frameB.location.href=link2;
			if (link3) parent.frameC.location.href=link3;
			if (link4) parent.frameD.location.href=link4;
			if (link5) parent.parent.frameBCD.location.href=link5;
			}

function loadfromM(link1)
			{
			if (link1) parent.parent.main.location.href=link1;
			}

function DisableLinkStatus()
	{
	document.onmouseover = function ( e ) {   
	if ( !e ) e = window.event;   
	var el = e.target ? e.target : e.srcElement;   
	while ( el != null && el.tagName != "A" ) el = el.parentNode;   
	if ( el == null ) return;   
	if ( e.preventDefault ) e.preventDefault();   
	else e.returnValue = true;};
	}


var preEl;
var preClickEl;
var preOverEl;

function setPointerClassForTD(theTD, action, cssname)
	{
	if (action == 'click' && theTD != preEl) 
		{
		if (typeof(preEl)!='undefined')			// jesli bylo cos wczesniej klikniete to
			{	
			if (theTD == preEl) return true;	// jesli to byl ten sam wiersz to nic nie robic

			var tmpcss = preClickEl.className;	// tworzy tablice klassCSS dla obiektu zaznaczonego wczesniej wiersza
			preEl.className = tmpcss;		// odznacza stary wiersz
			}
		preClickEl = preOverEl.cloneNode(true);	
		theTD.className = cssname;		// zaznaczenie kliknietego wiersza
		preEl = theTD;							// zapamietanie obiektu wskazanego
		preOverEl = theTD.cloneNode(true);		// ustawienie obiektu do podstawienia przy zdjeciu kursora
		}
	else if (action == 'over') 
		{
		preOverEl = theTD.cloneNode(true);		// wykonanie kopii obiektu przed wskazaniem pointerem
		theTD.className = cssname;		// ustawienie nowych class styli dla obiektu
		}
	else if (action == 'out') 
			{
			var tmpcss = preOverEl.className;
			theTD.className = tmpcss;
			}

	return true
	}


function setPointerClass(theRow, action)
	{

	/* stworzenie tablicy klas CSS na podstawie kolejnych parametr�w */
	argsnum = setPointerClass.arguments.length;
	var classArr = new Array ();
	var arr = new Array ();

	for (i=0; i<=argsnum; i++)
		{
		classArr[i] = setPointerClass.arguments[i+2];
		}
	/*****************************************************************/
	
	if (action == 'click' && theRow != preEl) 
		{
		if (typeof(preEl)!='undefined')
			{
			
		}
		if (typeof(preEl)!='undefined')			// jesli bylo cos wczesniej klikniete to
			{	
			if (theRow == preEl) return true;	// jesli to byl ten sam wiersz to nic nie robic

			arr = _getClassArray(preClickEl);	// tworzy tablice klassCSS dla obiektu zaznaczonego wczesniej wiersza
			_setPointerClass(preEl, arr);		// odznacza stary wiersz
			}
		preClickEl = preOverEl.cloneNode(true);	
		_setPointerClass(theRow, classArr);		// zaznaczenie kliknietego wiersza
		preEl = theRow;							// zapamietanie obiektu wskazanego
		preOverEl = theRow.cloneNode(true);		// ustawienie obiektu do podstawienia przy zdjeciu kursora
		}
	else if (action == 'over') 
		{
		preOverEl = theRow.cloneNode(true);		// wykonanie kopii obiektu przed wskazaniem pointerem
		_setPointerClass(theRow, classArr);		// ustawienie nowych class styli dla obiektu
		}
	else if (action == 'out') 
			{
			arr = _getClassArray(preOverEl);
			_setPointerClass(theRow, arr);
			}

	return true
	}

function _setPointerClass(theRow, classArr)
	{
	if (typeof(document.getElementsByTagName) != "undefined") 
		{
		var theCells = theRow.getElementsByTagName("td");
		}
	else if (typeof(theRow.cells) != "undefined") 
		{
		var theCells = theRow.cells;
		}
	else 
		{
		return false;
		}
	var rowCellsCnt  = theCells.length;
	for (var c = 0; c < rowCellsCnt; c++) 
		{
		if (classArr[c] == "" || classArr[c] == "undefined") theCells[c].className='';
		else theCells[c].className = classArr[c];
		}
	return true;
	}

function _getClassArray(theRow)
	{
	var classArr = new Array ();

	if (typeof(document.getElementsByTagName) != "undefined") 
		{
		var theCells = theRow.getElementsByTagName("td");
		}
	else if (typeof(theRow.cells) != "undefined") 
		{
		var theCells = theRow.cells;
		}
	else 
		{
		return false;
		}
	var rowCellsCnt  = theCells.length;
	for (var c = 0; c < rowCellsCnt; c++) 
		{
		classArr[c] = theCells[c].className;
		}
	return classArr;
	}

function PrintDocument(page)
	{
	var newWin=null;

  newWin = window.open(page, 'print', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=50,height=10');
  newWin.focus();
  newWin.print();
	}

function PrintPage()
	{
	window.print();
	window.close();
	}

function OpenPrintPage(page)
	{
	var newWin=null;
	newWin = window.open(page, 'print', 'width=10,height=10,top=0,left=0,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes');
	}

function OpenPreviewPage(page)
	{
	var newWin=null;
	newWin = window.open(page, 'print', 'width=600,height=490,top=0,left=0,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no');
	newWin.focus();
	}

function OpenHistoryPage(page)
	{
	var newWin=null;
	newWin = window.open(page, 'print', 'width=600,height=470,top=0,left=0,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no');
	newWin.focus();
	}

function openWin(url, title, width, height, scrollbars, resizable,statusbar,toolbar,menubar,location)
	{
	if (!scrollbars) scrollbars = 'yes';
	if (!resizable) resizable = 'yes';
	if (!statusbar) statusbar = 'yes';
	
	if (!toolbar) toolbar = 'no';
	if (!menubar) menubar = 'no';
	if (!location) location = 'no';

	var newWin=null;
	newWin = window.open(url,title, 'top=0,left=0,toolbar=no,location=no,status=' + statusbar + ',menubar=no,scrollbars=' + scrollbars + ',resizable=' + resizable + ',toolbar=' + toolbar + ',menubar=' + menubar + ',location=' + location + ',width=' + width + ',height=' + height);
	newWin.focus();
	return false;
	}

function openReport(url, title, formname, errmsg)
	{
	idrace=document.forms[formname].elements['dataarray[IDrace]'].value;
	idsession='undefined';
	
	if (document.forms[formname].elements['dataarray[IDsession]'][0].checked) idsession=1;
	else if (document.forms[formname].elements['dataarray[IDsession]'][1].checked) idsession=3;
	else if (document.forms[formname].elements['dataarray[IDsession]'][2].checked) idsession=5;
	else if (document.forms[formname].elements['dataarray[IDsession]'][3].checked) idsession=2;
	else if (document.forms[formname].elements['dataarray[IDsession]'][4].checked) idsession=4;
	else if (document.forms[formname].elements['dataarray[IDsession]'][5].checked) idsession=6;
	else if (document.forms[formname].elements['dataarray[IDsession]'][6].checked) idsession=12;
	
	if (idrace=='undefined' || idsession=='undefined') 
		{
		alert(errmsg, 'SLS');
		return false;
		}
	
	url=url + '?dataarray[IDrace]=' + idrace + '&dataarray[IDsession]=' + idsession;
	openWin(url, title, 600,400,'yes','no','no');
	}

function TempDisableChecking(formnr, elementnr)
	{
	if (document.forms[formnr].elements[elementnr].on)
	{
	}
	}


function CheckRadioButtonsAndWarn(form, radioname, radioitem, message)
	{
	
	var whichitem = 0;
	var ret;


	while (whichitem < document.forms[form].elements[radioname].length) 
		{
		if (document.forms[form].elements[radioname][whichitem].checked) 
			{
			ret = confirm(message);
			break;
			}
		whichitem++;
		}
	
	if (ret) document.forms[form].elements[radioname][radioitem].checked = true
	return ret;
	}


function LockDNF(srcobj, form, dstobj)
	{
	if (srcobj.value==3 || srcobj.value==4) document.forms[form].elements[dstobj].disabled = false;
	else 
		{
		document.forms[form].elements[dstobj].disabled = true;
		}
	}

function LockLive(obj_id, mode)
	{
	if (mode==1) mode = false;
	else mode = true;
	document.getElementById(obj_id).disabled = mode;
	}

function ConfirmCheckMark(obj, val, msg)
	{
	if (obj.checked && val==1 || !obj.checked && val==0)
		{
		ret = confirm(msg);
		
		if (val==0 && ret==false) obj.checked=true;
		if (val==1 && ret==false) obj.checked=false;
		
		return ret;
		}
	}

function SetDate(sw)
	{
	var today = new Date();
	var prevday = new Date();

	var curDay =	(new Date()).getDate();
	var curMonth =	(new Date()).getMonth() + 1;
	var curYear =	(new Date()).getYear();

	var curDayNr = (new Date()).getDay();

	var pastday = new Date;
	var dif

	

	switch (sw)
		{
		case '1':
			document.forms[0].elements['dataarray[sDay]'].value = '';
			document.forms[0].elements['dataarray[sMonth]'].value = '';
			document.forms[0].elements['dataarray[sYear]'].value = '';
			break;

		case '2':
			var prevday = new Date(curYear,curMonth-1,curDay-curDayNr+1);
			break;

		case '3':
			var prevday = new Date(curYear,curMonth-1,curDay-curDayNr+1-7);
			break;

		case '4':
			var prevday = new Date(curYear,curMonth-1,1);
			break;
		
		case '5':
			if (curMonth >= 10) prevday = new Date(curYear,10-1,1);
			else if (curMonth >= 7) prevday = new Date(curYear,7-1,1);
			else if (curMonth >= 4) prevday = new Date(curYear,4-1,1);
			break;

		case '6':
			if (curMonth <= 6) prevday = new Date(curYear,1-1,1);
			else prevday = new Date(curYear,7-1,1);
			break;
		
		case '7':
			prevday = new Date(curYear,1-1,1);
			break;
		}

	if (sw != 1)
		{
		document.forms[0].elements['dataarray[sDay]'].value = prevday.getDate();
		document.forms[0].elements['dataarray[sMonth]'].value = prevday.getMonth() + 1;
		document.forms[0].elements['dataarray[sYear]'].value = prevday.getYear();

		document.forms[0].elements['dataarray[eDay]'].value = curDay;
		document.forms[0].elements['dataarray[eMonth]'].value = curMonth;
		document.forms[0].elements['dataarray[eYear]'].value = curYear;
		}
	}

function KeyCheck(myfield,e, mode)
	{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

//	alert (mode + ' ' + keycode );

	// decimal
	if (mode == 'decimal' && (keycode==44 || keycode==46)) return true;
	// space
	if ((mode == 'alphanumpl' || mode == 'alphapl' || mode == 'alphanum' || mode == 'alpha' || mode == 'phone') && keycode==32) return true;
	// numeric
	if ((mode == 'num' || mode == 'alphanumpl' || mode == 'alphanum' || mode == 'nip' || mode == 'postal' || mode == 'phone' || mode == 'email' || mode == 'decimal') && ((keycode>47 && keycode<58 )  || keycode==8 || keycode==13)           ) return true;
	if (mode == 'nip' && keycode==45) return true;
	if (mode == 'postal' && keycode==45) return true;
	if (mode == 'phone' && (keycode==45 || keycode==41 || keycode==43)) return true;
	if ((mode == 'alphanum' || mode == 'alpha' || mode == 'email') && ((keycode>=65 && keycode<=90) || (keycode>=97 && keycode<=122))) return true;
	if (mode == 'email' && (keycode==64 || keycode==45 || keycode==46 || keycode==94)) return true;
	if ((mode == 'alphanumpl' || mode == 'alphapl') && ((keycode>=65 && keycode<=90) || (keycode>=97 && keycode<=122) || (keycode>=260 && keycode<=263) || keycode==280 || keycode==281 || (keycode>=321 && keycode<=324) || keycode==211 || keycode==243 || keycode==346 || keycode==347 || (keycode>=377 && keycode<=380)  )) return true;
	
	return false;
	}

function CondKeyCheck(myfield,e)
	{
	var a = myfield;
	var b = e;
//	alert (document.forms[0].elements['dataarray[filterName]'].value);
	if (document.forms[0].elements['dataarray[filterName]'].value == 'CL_KOD' ||
		document.forms[0].elements['dataarray[filterName]'].value == 'PART_ID' ||
		document.forms[0].elements['dataarray[filterName]'].value == 'KOD' ||
		document.forms[0].elements['dataarray[filterName]'].value == 'INDEX' ||
		document.forms[0].elements['dataarray[filterName]'].value == 'INDEKS')
		{
		return KeyCheck(a,b, 'num');
		}
	else if (document.forms[0].elements['dataarray[filterName]'].value == 'NIP') return KeyCheck(a,b, 'nip');
	else return true;
	}

function IsSomthingSelected()
	{
	var sel = document.selection;
	if (sel!=null) 
		{
		var rng = sel.createRange(); 
		if (rng!=null) 
			{
			if (rng.text != '')	
				{
				return true; 
				}
			}
		}
	return false
	}

function CountAndJump(formnr, elementnr, len, dstelnr, e)
	{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	if ((keycode==8) || (keycode==9) || (keycode==13) || (keycode==16) || (keycode==39) || (keycode==37) || (keycode==38) || (keycode==40)) { return true; }

	var m = document.forms[formnr].elements[elementnr].value;
	var mm = m.length;

	

	if (mm>=len)
		{
		if  (IsSomthingSelected()) return true;
		
		if (document.forms[formnr].elements[dstelnr].type == 'text') document.forms[formnr].elements[dstelnr].select();
		else document.forms[formnr].elements[dstelnr].focus();

		return false;
		}
	return true;
	}

function CountAndPrevent(formnr, elementnr, len, e, mode)
	{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	if ((keycode==8) || (keycode==9) || (keycode==13) || (keycode==16) || (keycode==39) || (keycode==37) || (keycode==38) || (keycode==40)) { return true; }

	var m = document.forms[formnr].elements[elementnr].value;
	var mm = m.length;
	var modea = mode;

	if (!mode) modea = 'num';
	if (!KeyCheck(0,e,modea)) return false;
	
	if (mm>=len) 
		{
		if  (IsSomthingSelected()) return true;

		return false;
		}
	return true;
	}

function CountAndPreventAllChars(formnr, elementnr, len, e, mode)
	{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	if ((keycode==8) || (keycode==9) || (keycode==13) || (keycode==16) || (keycode==39) || (keycode==37) || (keycode==38) || (keycode==40)) { return true; }

	var m = document.forms[formnr].elements[elementnr].value;
	var mm = m.length;

	if (mm>=len) return false;

	return true;
	}

function CountSpecyficChars(formnr, elementnr, len, e, mode)
	{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	if ((keycode==8) || (keycode==9) || (keycode==13) || (keycode==16) || (keycode==39) || (keycode==37) || (keycode==38) || (keycode==40)) { return true; }

	var m = document.forms[formnr].elements[elementnr].value;
	var mm = m.length;

	if (mode) if (!KeyCheck(0,e,mode)) return false;

	if (mode == 'decimal')
		{
		if (m.indexOf('.') >=0)
			{
			if (mm - m.indexOf('.') > 2) return false;
			else return true;
			}

		if (m.indexOf(',') >=0)
			{
			if (mm - m.indexOf(',') > 2) return false;
			else return true;
			}
		}
	
	if (mm>=len) return false;

	return true;
	}

function CopyFormContent(form_name, el_src, el_dst)
	{
	var teststr;
	var strlen;
	
	teststr = document.forms[form_name].elements[el_src].value;

	teststr = teststr.substr(0, (teststr.length)-1);
	if (teststr == document.forms[form_name].elements[el_dst].value)
		{

		document.forms[form_name].elements[el_dst].value = document.forms[form_name].elements[el_src].value;
		}

	return true;
	}

function SwitchLapDetails(IDdriver)
	{
	if (document.getElementById(IDdriver).style.display == "none")
		{
		document.getElementById(IDdriver).style.display=""
		}
	else document.getElementById(IDdriver).style.display = "none"
	}



function SetSeasons(idseas, casel)
	{
	
	LockLive('cb_live',LiveViewArray[idseas]);	
	LockLive('cm_llbonus',LLbonusesArray[idseas]);
	LockLive('cm_mlbonus',MLbonusesArray[idseas]);
	LockLive('cm_flbonus',FLbonusesArray[idseas]);
	LockLive('cm_ppbonus',PPbonusesArray[idseas]);
	LockLive('cm_weighpen',WeightPenArray[idseas]);
//	LockLive('cm_pits',Pitstops[idseas]);
	
	var tmpArr = new Array();
	z = 0;
	for (id in carnoArray)
		{
		if (carnoArray[id][0] != idseas) continue;
		tmpArr[z++] = Array(0, carnoArray[id][1], carnoArray[id][2]);
		}
	
	FillCombo('cb_carnomode', tmpArr, 0, casel);
	}
	
function FillCombo(dstElem, srcArray, key, optselect, zeroopt, mark)	
	{
	var srcVal = document.getElementById(dstElem).value;
	var dstobj = document.getElementById(dstElem);
	dstobj.options.length = 0;

	var z=0;

	if (zeroopt!=undefined && zeroopt != '')
		{
		dstobj.options.length++;
		dstobj.options[z].text = zeroopt;
		dstobj.options[z].value = 0;
		z++;
		}

	for (id in srcArray)
		{
		if (srcArray[id][0] != key) continue;
		dstobj.options.length++;
		dstobj.options[z].text = srcArray[id][2];
		dstobj.options[z].value = srcArray[id][1];
		if (srcArray[id][1]==optselect) dstobj.options[z].selected=true;
		if (mark!=undefined && mark!='' && srcArray[id][3]==1)  dstobj.options[z].className = mark 
		z++;
		}
	}
