var win = null;
var scrollspeed = cache = 1;

function initializess() {
   marqueeheight = document.all ? parent.document.all.datamain.height 
                                : parent.document.getElementById("datamain").getAttribute("height");
   dataobj = document.all ? document.all.datacontainer 
                          : document.getElementById("datacontainer");
   dataobj.style.top = 5;
   thelength = dataobj.offsetHeight;
   scrolltest();
}

function scrolltest() {
   dataobj.style.top = parseInt(dataobj.style.top) - scrollspeed;
   if (parseInt(dataobj.style.top) < thelength*(-1)) dataobj.style.top = 5;
   setTimeout("scrolltest()",100);
}


function disabledForm(form)
{
	for(i=0; i<form.length; i++)
	{
		form.elements[i].disabled = true;
	}	
}

function openTass(oid, aid) 
{
	var newWindow = window.open("./orders/modifydate.html?oid=" + oid + "&aid=" + aid,"openTass","height=200,width=400,toolbar=yes,status=no,menubar=no,resizable=yes,scrollbars=yes");
}

function openBankDetails(oid, cid) 
{
	var newWindow = window.open("./orders/modifybankdetails.html?oid=" + oid + "&cid=" + cid,"openBnkDls","height=280,width=450,toolbar=yes,status=no,menubar=no,resizable=yes,scrollbars=yes");
}

function openHelp(section, referel) 
{
	var newWindow = window.open("./help/index.html?act=" + section,"HelpPop","height=600,width=680,toolbar=yes,status=no,menubar=no,resizable=yes,scrollbars=yes");
}

function openHelpFirst(section, referel) 
{
	var newWindow = window.open("./help/first.html?act=" + section,"HelpPop","height=600,width=680,toolbar=yes,status=no,menubar=no,resizable=yes,scrollbars=yes");
}

function checkFirstLogin()
{
	var msg = '';
	if(document.forms['login'].elements['usernameorig'].value.toUpperCase() == document.forms['login'].elements['password'].value.toUpperCase())
	{
		msg = ' - La tua password deve essere differente dal tuo username\n';
		highLightButton('password');
		highLightButton('password2');
		
	}
	if(document.forms['login'].elements['password'].value.length < 6)
	{
		msg = msg + ' - La tua password deve essere di almeno 6 caratteri alfa-numerici\n'
		highLightButton('password');
		highLightButton('password2');
	}
	if(document.forms['login'].elements['password'].value == '')
	{
		msg = msg + ' - Inserisci la nuova password\n';
		highLightButton('password');
		highLightButton('password2');
		
	}
	if(document.forms['login'].elements['password'].value != document.forms['login'].elements['password2'].value)
	{
		msg = msg + ' - Le due password sono differenti\n';
		highLightButton('password');
		highLightButton('password2');
		
	}
	/*
	if(document.forms['login'].elements['email'].value == '')
	{
		msg = msg + ' - Inserisci un valido indirizzo e-mail\n';
		highLightButton('email');
		
	}
	*/
	
	if(msg)
	{
		alert('Le seguenti informazioni sono mancanti o incorrette:\n\n' + msg);
		return false;
	}
	else
	{
		return true;	
	}
}

function checkNumeric(field, origvalue)
{
	pattern = /^[0-9]*$/;
	if(pattern.test(field.value)==false)
	{
		//alert("Not numeric in " + field.name);
		field.value = origvalue;
	}
}

function checkNumericAlert(field, origvalue, msg)
{
	pattern = /^[0-9]*$/;
	if(pattern.test(field.value)==false)
	{
		alert(msg);
		field.value = origvalue;
	}
}

function checkLength(field, lenvalue, msg)
{
	if(field.value.length < lenvalue && field.value.length > 0)
	{
		zeros = 0;
		alert(msg);
		for(i=1; i<(lenvalue-field.value.length); i++)
		{
			zeros = zeros + '0';
		}
		field.value = zeros + field.value;
	}
}

function copyAddress()
{
	document.clients.name_address.value = document.clients.name.value;
	document.clients.address1_address.value = document.clients.address1.value;
	document.clients.town_address.value = document.clients.town.value;
	document.clients.postcode_address.value = document.clients.postcode.value;
	document.clients.county_address.value = document.clients.county.value;
	document.clients.telephone_address.value = document.clients.telephone.value;
}

function highLightButton(field)
{
	document.getElementById(field).style.background = '#FFF200';
	document.getElementById(field).style.color = '#336699';
}

function highLightButton(field)
{
	document.getElementById(field).style.background = '#FFF200';
	document.getElementById(field).style.color = '#336699';
}

function colourGeneric(id,type,color)
{
	id.bgColor = color;
}
function deleteRec (msg)
{
	var conferma=null;
	conferma=confirm (msg + '?\n');
	if (conferma==false) 
	{
		return (false);
	}
}

function deleteRecGoto (msg, url)
{
	var conferma=null;
	conferma=confirm (msg + '?\n');
	if (conferma==false) 
	{
		return (false);
	}
	else
	{
		document.location.href = url;
	}
}

function deleteRecGotoNoMark (msg, url)
{
	var conferma=null;
	conferma=confirm (msg + '\n');
	if (conferma==false) 
	{
		return (false);
	}
	else
	{
		document.location.href = url;
	}
}

function ColorBg(id,clr) 
{
	id.bgColor = clr;
}

function printOrder(oid, cid, values, promoModules, masterproductid, facol) 
{
	var newWindow = window.open("./fatture/print.html?oid=" + oid + "&cid=" + cid + "&values=" + values + "&prm=" + promoModules + "&masterp=" + masterproductid + "&f=" + facol,"PrintOrder","height=700,width=740,toolbar=no,status=yes,menubar=yes,resizable=yes,scrollbars=yes");
}

function openDescMio(lang) 
{
	var newWindow = window.open("./html/mioclubart_desc.html?lang=" + lang,"MioClubART","height=200,width=250,toolbar=no,status=no,menubar=no,resizable=yes,scrollbars=no");
}


function validate(form) {
	//alert(form);
	var j = 0;
	msg = "";
	for(var i = 0;i < ele.length;i++) {
		if(isBlank(form, ele[i])) {
			invalid(form, ele[i]);
			msg = msg + msgs[i] +"\n";
			j = j +1;
		}
	}
	if(j == 0) {
		return true;
	}
	else {
		alert(alertMsg + "\n"+ msg);
		return false;
	}
}
function invalid(form, ele) {
	if(!document.layers) {
		document.forms[form].elements[ele].style.borderColor = '#000000';
		document.forms[form].elements[ele].style.background = '#ffc000';
		}
	return msg;
}

function isBlank(form,ele) {
	str = document.forms[form].elements[ele].value;
	if(str == "") {
		return true;
	}
	else {
		return false;
	}

}

function popUp(page, width, height) 
{
	var newWindow = window.open(page,"GenericPage","height=" + height + ",width=" + width + ",toolbar=no,status=no,menubar=no,resizable=yes,scrollbars=yes");
}

function deletettrm (msg)
{
	var conferma=null;
	conferma=confirm (msg + '\n');
	if (conferma==false)
	{
		return (false);
	}
}

function popUp(page, width, height, lang) 
{
 var newWindow = window.open(page,"GenericPage","height=" + height + ",width=" + width + ",toolbar=no,status=no,menubar=no,resizable=yes,scrollbars=yes");
}



