var errFormBG = "#FFC4C4";

popupWin = null;
function openPopUp(urlPop, properties, title)
{
	NFW = window.open("", 'PopUp' , properties)     
    NFW.blur()
    window.focus()       
    var frameString=""+
					"<html>"+
					"<head>"+
					"<title>"+title+"</title>"+
					"<base href='http://www.djscene.lt/'>"+
					"</head>"+
					"<body topmargin='0' leftmargin='0' rightmargin='0' marginwidth='0' marginheight='0' framespacing='0'>"+
					"<div><img src='"+urlPop+"' border='0'></div>"+
					"</body></html>"
    NFW.document.open();
    NFW.document.write(frameString)
    NFW.document.close()
    NFW.focus()

}

function WindowPopUp(fname, properties)
	{
		if( popupWin && !popupWin.closed )
		{
			popupWin.focus();
		}
		else
		{
			popupWin = window.open(fname, 'PopUp', properties);
		}
	}

function dl(txt) {
   return confirm(txt);
}

function jumpToOpener(url)
{
	window.opener.document.location.href = url;
	window.close();
}

function rowOver(object, toClass) {
	object.className = toClass;
}

function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
  else if (object.className == 'Row1') object.className = 'RowOver1';
  else if (object.className == 'Row2') object.className = 'RowOver2';
}

function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
  else if (object.className == 'RowOver1') object.className = 'Row1';
  else if (object.className == 'RowOver2') object.className = 'Row2';
}


//Roll Over Image
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function toggleLayer(whichLayer, valExp, valCol)
{
	if (document.getElementById)
	{
	// this is the way the standards work
	    var style2 = document.getElementById(whichLayer).style;
	    var text2  = document.getElementById(whichLayer+'txt');
	    if (text2.state == "0") 
	    {
	    	style2.display = "";
	    	text2.innerHTML = valExp;
	    	text2.state = "1";
	    } 
	    else
	    {
	    	style2.display = "block";
	    	text2.innerHTML = valCol;
	    	text2.state = "0";	
	    }

	}
	else if (document.all)
	{
	// this is the way old msie versions work
	    var style2 = document.all[whichLayer].style;
	    var text2  = document.all[whichLayer+'txt'];
	    if (text2.state == "0") 
	    {
	    	style2.display = "";
	    	text2.innerHTML = valExp;
	    	text2.state = "1";
	    } 
	    else
	    {
	    	style2.display = "block";
	    	text2.innerHTML = valCol;
	    	text2.state = "0";	
	    }
	}
	else if (document.layers)
	{
	// this is the way nn4 works
	    var style2 = document.layers[whichLayer].style;
	    var text2  = document.layers[whichLayer+'txt'];
	    if (text2.state == "0") 
	    {
	    	style2.display = "";
	    	text2.innerHTML = valExp;
	    	text2.state = "1";
	    } 
	    else
	    {
	    	style2.display = "block";
	    	text2.innerHTML = valCol;
	    	text2.state = "0";	
	    }
	}
}

function hideDiv(divName)
{
	if (document.getElementById)
	{
	// this is the way the standards work
	    var divStyle = document.getElementById(divName).style;
	    divStyle.display = "none";

	}
	else if (document.all)
	{
	// this is the way old msie versions work
	    var divStyle = document.all[divName].style;
	    divStyle.display = "none";
	}
	else if (document.layers)
	{
	// this is the way nn4 works
	    var divStyle = document.layers[divName].style;
	    divStyle.display = "none";
	}
}



function sprintf()
{
	if (!arguments || arguments.length < 1 || !RegExp)
	{
		return;
	}
	var str = arguments[0];
	var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
	var a = b = [], numSubstitutions = 0, numMatches = 0;
	while (a = re.exec(str))
	{
		var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4];
		var pPrecision = a[5], pType = a[6], rightPart = a[7];
		
		//alert(a + '\n' + [a[0], leftpart, pPad, pJustify, pMinLength, pPrecision);

		numMatches++;
		if (pType == '%')
		{
			subst = '%';
		}
		else
		{
			numSubstitutions++;
			if (numSubstitutions >= arguments.length)
			{
				alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).');
			}
			var param = arguments[numSubstitutions];
			var pad = '';
			       if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1);
			  else if (pPad) pad = pPad;
			var justifyRight = true;
			       if (pJustify && pJustify === "-") justifyRight = false;
			var minLength = -1;
			       if (pMinLength) minLength = parseInt(pMinLength);
			var precision = -1;
			       if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1));
			var subst = param;
			       if (pType == 'b') subst = parseInt(param).toString(2);
			  else if (pType == 'c') subst = String.fromCharCode(parseInt(param));
			  else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0;
			  else if (pType == 'u') subst = Math.abs(param);
			  else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param);
			  else if (pType == 'o') subst = parseInt(param).toString(8);
			  else if (pType == 's') subst = param;
			  else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase();
			  else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase();
		}
		str = leftpart + subst + rightPart;
	}
	return str;
}

function DrawRate(element)
{
	/*
	var elName 	= 'vote_' + String(element);
	var elObj	= document.getElementById(elName);
	var imgEl	= eval('rate' + (element < 0 ? 'm' + String((element*-1)) : String(element)));
	elObj.src = imgEl.src;
	*/
	var to = (element > 0 ? element : (element*-1));
	for (var i=1; i<= to; i++)
	{
		var elName 	= 'vote_' + String((element > 0 ? i : (i*-1)));
		var elObj	= document.getElementById(elName);
		var imgEl	= eval('rate' + String((element > 0 ? i : 'm' + String(i))));
		elObj.src = imgEl.src;
	}
	
}

function ClearRate()
{
	for (var i=-5; i<= 5; i++)
	{
		if (i != 0)
		{
			var elName 	= 'vote_' + String(i);
			var elObj	= document.getElementById(elName);
			elObj.src = rate0.src;
		}
	}
}

function changeStyle(cell, style) {
	if (obj = (document.getElementById(cell))) 
	{
		if (style == 'error') obj.style.color = '#FF0000';
		else obj.style.color = '';
	}
}

function keepTop( id ) {
	//firefox
	if (document.getElementById && !document.all) {
		var scroll = (window.pageYOffset);
	} else {
		var scroll = (window.body.scrollTop);
	}
	
	if (obj = document.getElementById(id))
	{
		obj.style.top = (scroll+150) + 'px';
	}
}


function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    } else {
        var expires = "";
    }
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function getScroll() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

/*
var lastScrollPos = readCookie('lastScrollPosition');
	
	if ( lastScrollPos > 0 ) {
		parent.window.scrollTo( 0, lastScrollPos );
	}
	
*/

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


function checkNEmail(form) {
	if (isBlank(form.email.value) || isBlank(form.name.value) || !isEmailValid(form.email.value) ) 
	{
		alert("Please enter a valid Name and  Email Address .\nThe email or name you have typed in does not appear to be valid.");
		form.email.focus();
		return false;
	}
	}

function checkEmail(form) {
	if (isBlank(form.email.value) || !isEmailValid(form.email.value) ) {
		alert("Please enter a valid Email Address.\nThe email you have typed in does not appear to be valid.");
		form.email.focus();
		return false;
	}
return true;

}

function isBlank(fieldValue) {
	var blankSpaces = / /g;
	fieldValue = fieldValue.replace(blankSpaces, "");
	return (fieldValue == "") ? true : false;
}

function isEmailValid(fieldValue) {
	var emailFilter = /^.+@.+\..{2,4}$/;
	var atSignFound = 0;
	for (var i = 0; i <= fieldValue.length; i++)
		if ( fieldValue.charAt(i) == "@" )
			atSignFound++;
	if ( atSignFound > 1 )
		return false;
	else
		return ( emailFilter.test(fieldValue) && !doesEmailHaveInvalidChar(fieldValue) ) ? true : false;
}

function doesEmailHaveInvalidChar(fieldValue) {
	var illegalChars = /[\(\)\<\>\,\;\:\\\/\"\[\] ]/;
	return ( illegalChars.test(fieldValue) ) ? true : false;
}
