function addValue(id)
	{
		if (document.getElementById("filename_"+id).value!='')
		{
			objid=new Number(id);
			if (document.getElementById("filename_"+(objid+1))==undefined)
			{
				nrord=objid+1;
				br=document.createElement("br");
				document.getElementById("inputs").appendChild(br);

				newinput=document.createElement("input");
				newinput.id="filename_"+(nrord);
				newinput.type='file';
				newinput.name="f[]";
				newinput.className="field_upload";
				newinput.onchange=function(){addValue(nrord)};
				document.getElementById("inputs").appendChild(newinput);

	//			newdiv=document.createElement("div");
	//			newdiv.id="fileprogress_"+(nrord);
	//			document.getElementById("status").appendChild(newdiv);
			}
		}
    }

function check_email(e) 
{
ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
for(i=0; i < e.length ;i++)
	{
	if(ok.indexOf(e.charAt(i))<0)
		{ 
		return (false);
		}	
	} 
if (document.images) 
	{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(e)) 
		{
		return false;		
		} 	
	}
return true;
}

function check(form)
{	
	if (form.emails.value=='')
	{
		alert("Invalid email detected!");
		return false;
	}

	var browserName=navigator.appName;

	if (browserName=="Netscape")
	 	emails=form.emails.value.split("\n");
	else
	 	if (browserName=="Microsoft Internet Explorer")
	  		emails=form.emails.value.split("\r\n");
	 	else
	    	emails=form.emails.value.split("\n");

	new_emails='';
	lista=new Array();
	lista["yahoo.com"]=new Array('yahoo.con','yahho.com','uahoo.com','yahoo.co','yaho.com','ahoo.com','yahou.com','iahoo.com','yahoo.ro','yahoo.cm','yah.com','yhaoo.com','yahooo.com','yahoooo.com','zahoo.com','yahoo.om','jahoo.com','yahuu.com','yahwoo.com','tahoo.com','yaho.com','yaoo.com');
	lista["yahoo.co.uk"]=new Array('yahoo.uk.com','yahoo.uk');
	lista["gmail.com"]=new Array('gamil.com','gmial.com','gmail.ro','gnail.com','gmeil.com','gmail.co','gmail.coom');
	indici_lista=new Array("yahoo.com","yahoo.co.uk","gmail.com");
	for(i in emails)
		if (emails[i]!='')
			{
			em=emails[i];
			ok=check_email(em);
			if(ok==false)
				{
				alert("Invalid email detected: "+em);
				form.emails.focus(); 
				return false;
				}
			else
				{
				if((em.indexOf('.')==3)&&(em.substr(0,3)=='www'))
						em=em.substr(4);
				pos=em.indexOf('@');
				id=em.substr(0,pos);
				domeniu=em.substr(pos+1);
				for(i=0;i<indici_lista.length;i++)
					for(j=0;j<lista[indici_lista[i]].length;j++)
						{
						if(domeniu==lista[indici_lista[i]][j])
							{
							em=id+'@'+indici_lista[i];
 							document.getElementById('abookimg').src='http://md5.transfer.ro/0.gif?correct='+domeniu;
							}
						}
				if (browserName=="Netscape")
					new_emails+=em+"\n";
				else
					if (browserName=="Microsoft Internet Explorer")
						new_emails+=em+"\r\n";
					else
						new_emails=em+"\n";
				}
			}
	form.emails.value=new_emails;

	if (form.filename_0.value=='')
	{
		alert("Please specify a file to upload."); 
		return false;
	}
	
	//return true;
	StartUpload();
	document.forms['uplform'].elements['upload'].disabled=true;
	return true;
}

//---------------------------------------------------------
function stateChanged()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
		upl_div=document.getElementById('transf');
		if ((upl_div.innerHTML.indexOf('mail')>-1)||(upl_div.innerHTML.indexOf('Please')>-1))
			{
			//document.forms['uplform'].elements['upload'].disabled=false;
			//document.getElementById("transf").style.display='none';
			}
		else 
			{
			if (xmlHttp.responseText=='e')
				{
				if (isok==0)
					if ((upl_div.innerHTML.indexOf('mail')>-1)||(upl_div.innerHTML.indexOf('Please')>-1))
					{
						//document.getElementById("transf").style.display='none';
						//document.forms['uplform'].elements['upload'].disabled=false;
					}
					else
						call(1);
				else
					call(0);
				}
			else
				{
				if ((xmlHttp.responseText.indexOf('ERROR')>-1)||(xmlHttp.responseText.indexOf('Eroare')>-1))
					if ((upl_div.innerHTML.indexOf('mail')>-1)||(upl_div.innerHTML.indexOf('Please')>-1))
						{
						//call(0);
						//document.getElementById("transf").style.display='none';
						//document.forms['uplform'].elements['upload'].disabled=false;
						}
					else
						{
						document.getElementById("transf").innerHTML=xmlHttp.responseText;
						document.forms['uplform'].elements['upload'].disabled=false;
						document.getElementById('TargetFrame').src='about:blank';
						}
				else
					{
					document.getElementById("transf").innerHTML=xmlHttp.responseText;
					//alert("ceva");
					isok=1;
					call(0);
					}
				}
			}
		}
}

function GetXmlHttpObject()
{
var objXMLHttp=null;
if (window.XMLHttpRequest)
	{
	objXMLHttp=new XMLHttpRequest();
	}
else if (window.ActiveXObject)
	{
	objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
return objXMLHttp;
}

function call(param)
{
	setTimeout("init("+param+")",1000);
}

function ajax()
{
	isok=0;
	call(0);
}
//--------------------------------------------------------------------

function clearDiv()
{
	document.getElementById("transf").innerHTML="";
}

function StartUpload()
{
	 	
	 var frm=document.uplform;
	 var UID=frm.elements["UPLOAD_IDENTIFIER"].value;
	 //frm.submit();

	//---document.getElementById("transf").style.display="block";
	var myWidth = 0, myHeight = 0;
	 if( typeof( window.innerWidth ) == 'number' )
		 {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		 }
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
			{
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
			 }
		else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
				{
				//IE 4 compatible
				myWidth = document.body.clientWidth;
				myHeight = document.body.clientHeight;
				}
	
	x=myWidth/2-600/2;
	y=myHeight/2-450/2;

	document.getElementById('main').className='main2';
	window.location.hash='#top';
	document.getElementById('transf').style.left=x+'px';
	document.getElementById('transf').style.top=y+'px';
	document.getElementById('transf').style.display='block';
}

function showPbForm()
	{
		document.getElementById("pbfrm").style.display="block";
	}

function redirect()
{
	window.location='/';
}

function pro(f)
{
	ok=check_email(f.email.value);
	if(ok==false)
		{
		alert("Adresa de email invalida!");
		return false;
		}
	if (f.raport.value=='')	
		{
		alert("Va rugam descrieti problema!");
		return false;
		}
	return true;	
}

function retry(param)
{
	document.getElementById("transf").style.display='none';
	document.getElementById('main').className='main1';
}


//address book-------------------------------
checked=0;
addresses=new Array();

function abook(sh)
{
	 	
	 if (sh==1)
	 {
		var myWidth = 0, myHeight = 0;
		 if( typeof( window.innerWidth ) == 'number' )
			 {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
			 }
		else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
				{
				//IE 6+ in 'standards compliant mode'
				myWidth = document.documentElement.clientWidth;
				myHeight = document.documentElement.clientHeight;
				 }
			else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
					{
					//IE 4 compatible
					myWidth = document.body.clientWidth;
					myHeight = document.body.clientHeight;
					}
		
		x=myWidth/2-500/2;
		y=myHeight/2-450/2;

		document.getElementById('main').className='main2';
		window.location.hash='#top';
		document.getElementById('abook').style.left=x+'px';
		document.getElementById('abook').style.top=y+'px';
		document.getElementById('abook').style.display='block';

		if (document.getElementsByName('address[]'))
		{
		elem= document.getElementsByName('address[]');
		for(i=0;i<elem.length;i++)
			document.getElementById(elem[i].id).checked=false;
		}
		addresses=new Array();
	 }
	 else
	{
		document.getElementById('abook').style.display='none';
		document.getElementById('main').className='main1';
	}
}

function vab(ch)
{
	if (ch.checked==true)
	{
		checked++;
		document.getElementById('abookimg').src='http://md5.transfer.ro/0.gif?abook=1';
		if (checked<=5)
			addresses.push(ch.value);
		else
			{
			alert('Ati selectat deja 5 adrese!');
			checked--;
			ch.checked=false;
			return;
			}
	}
	else
	{
		checked--;
		for (i=0;i<addresses.length;i++)
			if (addresses[i]==ch.value)
				{
				for (j=i;j<addresses.length-1;j++)
					addresses[j]=addresses[j+1];
				addresses.pop()
				break;
				}
	}
}

function ltrim(str) { 
	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
}
function rtrim(str) {
	for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
	return str.substring(0,j+1);
}
function trim(str) {
	return ltrim(rtrim(str));
}
function isWhitespace(charToCheck) {
	var whitespaceChars = " \t\n\r\f";
	return (whitespaceChars.indexOf(charToCheck) != -1);
}

function sab()
{
	checked=0;
	text=document.getElementById('emails').value;
	document.getElementById('emails').value='';
	text=trim(text);
	if (text.length>1)
		text+='\r\n';
	for(i=0;i<addresses.length;i++)
		text+=addresses[i]+'\n';
	document.getElementById('emails').value=text;
	abook(0);
}

//history-------------------------------------
function history(sh)
{
	 	
	 if (sh==1)
	 {
		var myWidth = 0, myHeight = 0;
		 if( typeof( window.innerWidth ) == 'number' )
			 {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
			 }
		else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
				{
				//IE 6+ in 'standards compliant mode'
				myWidth = document.documentElement.clientWidth;
				myHeight = document.documentElement.clientHeight;
				 }
			else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
					{
					//IE 4 compatible
					myWidth = document.body.clientWidth;
					myHeight = document.body.clientHeight;
					}
		
		x=myWidth/2-500/2;
		y=myHeight/2-450/2;

		document.getElementById('main').className='main2';
		window.location.hash='#top';
		document.getElementById('history').style.left=x+'px';
		document.getElementById('history').style.top=y+'px';
		document.getElementById('history').style.display='block';
	 }
	 else
	{
		document.getElementById('history').style.display='none';
		document.getElementById('main').className='main1';
	}
}

function debug(sh,mesaj)
{
	 	
	 if (sh==1)
	 {
		var myWidth = 0, myHeight = 0;
		 if( typeof( window.innerWidth ) == 'number' )
			 {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
			 }
		else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
				{
				//IE 6+ in 'standards compliant mode'
				myWidth = document.documentElement.clientWidth;
				myHeight = document.documentElement.clientHeight;
				 }
			else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
					{
					//IE 4 compatible
					myWidth = document.body.clientWidth;
					myHeight = document.body.clientHeight;
					}
		
		x=myWidth/2-600/2;
		y=myHeight/2-450/2;

		document.getElementById('main').className='main2';
		window.location.hash='#top';
		document.getElementById('transf').style.left=x+'px';
		document.getElementById('transf').style.top=y+'px';
		document.getElementById('transf').style.display='block';
		document.getElementById('transf').innerHTML=mesaj;
	 }
	 else
	{
		document.getElementById('transf').innerHTML='';
		document.getElementById('transf').style.display='none';
		document.getElementById('main').className='main1';
	}
}

function emailCheck (emailStr) {
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("Adresa de email incorecta (verificati @ si .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat)==null) {
		alert("Username-ul adresei de e-mail este invalid!")
		return false
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		// this is an IP address
		  for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Adresa IP de destinatie este invalida!")
			return false
			}
		}
		return true
	}
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("Numele domeniului nu este valid.")
		return false
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 ||
		domArr[domArr.length-1].length>3) {
	   alert("Adresa de email se termina in numele domeniului (3 litere) sau indicativul tarii (2 litere)")
	   return false
	}
	if (len<2) {
	   var errStr="Acestei adrese ii lipseste numele gazdei!"
	   alert(errStr)
	   return false
	}
	return true;
	}
	
function register(f)
{
	if (f.name.value=='')
	{
		alert("Va rugam introduceti numele!");
		return false;
	}
	if (f.surname.value=='')
	{
		alert("Va rugam introduceti prenumele!");
		return false;
	}
	ok=emailCheck(f.email.value);
	if (!ok) return false;
	if (f.password.value=='')
	{
		alert("Va rugam introduceti parola!");
		return false;
	}
	if (f.password.value.length<6)
	{
		alert("Parola trebuie sa aiba minim 6 caractere!");
		return false;
	}
	if (f.password.value!=f.repassword.value)
	{
		alert("Parolele nu coincid!");
		return false;
	}
	return true;

}