
var legal="01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";


function sc_add(obj)
{
	f=document.mainform;
	var spalten=obj.childNodes.length;
	var i,article_complete="",sc="",sc_add_article="",sc_add_descr="",sc_add_price="",sc_add_sc="";
	for(i=0;i<spalten;i++)
	{
		if(obj.childNodes.item(i).childNodes.length)
		{
			var cellobj=obj.childNodes.item(i);

			if(i==0)
			{
				sc_add_sc=cellobj.getAttribute("sc");
				sc_add_article=cellobj.childNodes.item(0).nodeValue;
			}
			else if(i==1)
			{
				sc_add_descr=cellobj.childNodes.item(0).nodeValue;
			}
			else if(i==2)
			{
				sc_add_price=cellobj.childNodes.item(0).nodeValue;
			}

			if(article_complete) article_complete+="-";
			article_complete+=cellobj.childNodes.item(0).nodeValue;
		}
	}
	if(article_complete)
	{
		var sessionid=document.forms['mainform'].elements['sessionid'].value;
		var newurl="fibra_test.cgi?command=QuantityWindow&sessionid="+sessionid+"&article="+encodeURI(article_complete);
		newurl+="&sc_add_price="+encodeURI(sc_add_price);
		newurl+="&sc_add_descr="+encodeURI(sc_add_descr);
		newurl+="&sc_add_article="+encodeURI(sc_add_article);
		newurl+="&sc_add_sc="+encodeURI(sc_add_sc);
		
		var newwin=window.open(newurl,'','dependent=yes,resizable=no,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,copyhistory=0,width=500,height=70');
	}
}

function do_search()
{
	f=document.mainform;
	f.command.value="Search";
	f.submit();
}

function do_login()
{
	f=document.mainform;
	f.command.value="Login";
	f.submit();
	return false;
}

function do_logout()
{
	f=document.mainform;
	f.command.value="Logout";
	f.submit();
	return false;
}

function do_edit_profile()
{
	document.mainform.command.value="EditProfile";
	document.mainform.submit();
	return false;
}


function command_exec_ef(com)
{
	empty_from();
	command_exec(com);
}


function command_exec(com)
{
	f=document.mainform;
	f.command.value=com;
	f.submit();
}

function sub_command_exec(com)
{
	f=document.mainform;
	f.sub_command.value=com;
	f.submit();
}

function tr_on(obj)
{
	var spalten=obj.childNodes.length;
	var i;
	for(i=0;i<spalten;i++)
	{
		obj.childNodes.item(i).style.backgroundColor="$fibrablauhell";
	}
}

function tr_off(obj)
{
	var spalten=obj.childNodes.length;
	var i;
	for(i=0;i<spalten;i++)
	{
		obj.childNodes.item(i).style.backgroundColor="$fibratablebg";
	}
}

function refresh_site()
{
	command_exec(document.forms['mainform'].elements['last_command'].value);
	return true;
}

function empty_from()
{
	if(document.forms['mainform'].elements['from']!=null)
		document.forms['mainform'].elements['from'].value="";
}

function open_paypal()
{
	var paypal_url="https://www.paypal.com/xclick/business=contact%40fibra-brandt.com&no_note=1&currency_code=EUR&bank_account_country_code=US";
	var newwin=window.open(paypal_url,'PayPal','dependent=yes,resizable=yes,toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,copyhistory=0,width=640,height=480');
}

function checkEnter(obj)
{
	if(window.event.keyCode != 13)	{
		return false;
	}
	else {
		return true;
	}
}


function empty_inquiries()
{
	f=document.mainform;
	f.inquiries.value="";
	f.sub_command.value="ScEmpty";
	return false;
}


function send_inquiries()
{
	f=document.mainform;
	f.command.value="SendInquiries";
	f.submit();
	//return true;
}


function emailcheck(x)
{
	var legal="01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_\@.";
	var i,laenge,c;
	laenge=x.length;


	if ((x.indexOf('\@') == -1) || (x.indexOf('.') == -1) || (laenge<6) || (x.indexOf('\@') < 1) || (x.indexOf('\@')==laenge-1 || (x.indexOf('.')==laenge-1)))
	{
		return 0;
	}
	
	for(i=0; i < laenge; i++)
	{
		c=x.charAt(i);
		if ( legal.indexOf(c) == -1 )
		{
			return 0;
		}
	}
	return 1;
}

function chkForm()
{
	f=document.mainform;
	if (!f.EMail.value || !emailcheck(f.EMail.value)) { alert("Wrong email adress!"); return false; }
	if (!f.msg.value) { alert("Empty Message!"); return false; }
	f.command.value="SendMessage";
	f.submit();
}


function SignUpCheck()
{
	f=document.mainform;
	if (!f.EMail.value || !emailcheck(f.EMail.value)) { alert("Wrong email adress!"); return false; }
	if (!f.user_name.value) { alert("wrong user name!"); return false; }
	if ( f.password.value != f.password_again.value || !f.password.value) { alert("wrong password!"); return false; }
	f.command.value="SignUpSubmit";
	f.submit();
}


function ChangeProfileCheck()
{
	f=document.mainform;
	if (!f.EMail.value || !emailcheck(f.EMail.value)) { alert("Wrong email adress!"); return false; }
	if ( f.password.value != f.password_again.value) { alert("wrong password!"); return false; }
	f.command.value="ChangeProfileSubmit";
	f.submit();
}


