function trim(str)
  {		
	var i,j;
	i = 0;
    j=str.length-1;
	str = str.split("");
	while(i < str.length)
	{
	  if(str[i]==" ")
		str[i] = ""	
	  else	  
		break;
	  
	  i++;
	}
	while(j > 0)
	{
	  if(str[j]== " ")	  
		str[j]=""	  
	  else	  
		break;	  
	  
	  j--;
	}
    return str.join("")
  }
  
  function checkEmptyField(textBox)
  {
	if(trim(textBox.value) == '')
	{
	  var controlName=textBox.name;	  
	  //alert("The Field ' "+controlName+" ' cannot be empty");	 
	  alert('All fields are required');
	}	
  }

  function passwordAlert()
  {    	   
	alert("Passwords do not match");	 		
  }
  
  function policyAlert()
  {    	   
	alert("you must accept the privacy policy signature");	 		
  }
 
 /* function checkEmptySelection(form)
  {
    var empty=false;
	for(i = 0; i < form.elements.length; i++)
	{
	  e = form.elements[i];
	  if(e.onblur != null)
	  {  
	    if(trim(e.value)=="")
		  empty=true;
	    e.onblur();
	  }
	}
    if(empty==true)
	{	  
      return false;
      exit;
	}       
    return true;	
  }  */

  function checkEmptySelection(form)
  {
    var empty=false;	
	for(i = 0; i < form.elements.length; i++)
	{
	  e = form.elements[i];	
	  if(e.onvalidate!= null)	  
	  {      		
		if(trim(e.value)=="")
		{ 	
		  empty=true;
		  if(e.onvalidate!= null) 
		  {
		    checkEmptyField(e);		  
			break;
		  }
		}
	  }
	  if(e.onconfirmvalidate!= null)
	  {
        var password=document.getElementById('Password');
		var confirmPassword=document.getElementById('confirmPassword');
		if(password==null)
		{
		  password=document.getElementById('wk_password');
		  if( (password.value != "") && (password.value != trim(confirmPassword.value)) ) 
		  {
		    passwordAlert();
		    return false;
		    exit;
		  }
	    }

	  }

	  if(e.onvalidatepolicy!= null)
	  { 
        if(signUpForm.Policy.checked==false) 		
		{
          policyAlert();
          return false;
          exit;
		}
      }		
	  
	  if(e.onvalidateUpload!= null)
	  {
		  var uploadedFile=document.getElementById('UploadedFile');
		  var URL=document.getElementById('URL');		  
		  if(uploadedFile!=null && URL!=null)
		  {//alert(uploadedFile.value); alert(URL.value);
			if( (uploadedFile.value!="" &&  URL.value!="") || (uploadedFile.value=="" &&  URL.value=="") )
			{  
			  alert("you must fill either the URL field or the File one");
			  return false;
			  exit;
			}
		  }		
	  }

	}
    if(empty==true)
	{       
      return false;
      exit;
	}       
    return true;	
  }  
  
  function isDigit(num) 
  {
    if (num.length>1)
      return false;
	
	var string="123456789";
	if (string.indexOf(num)!=-1)
	  return true;	
	
	return false;
  }

  function isBlank(val)
  {
	if(val==null)
	  return true;
	
	for(var i=0;i<val.length;i++) 
	{  
	  if((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r"))
	    return false;	  
    }	
	return true;
  }
  
  function isInteger(val)
  {
    if(isBlank(val))
	  return false;

	for(var i=0;i<val.length;i++)
	{
	  if(!isDigit(val.charAt(i)))
 	    return false;
    }
	return true;
  }  

 
  function popUpWindow(msg)
  {
	alert(msg);
  }