function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

function set_text(text,elm)
{
	document.getElementById(elm).value=text;
	//alert (text);
	//document.f4.MobilePhone.value=document.f4.Country.options(document.f4.Country.selectedIndex).code
}

function mobile_check(str) {
	
	var a0="0"
	var a1="1"
	var a2="2"
	var a3="3"
	var a4="4"
	var a5="5"
	var a6="6"
	var a7="7"
	var a8="8"
	var lat=str.indexOf(a0)
	var lat=str.indexOf(a1)
	var lat=str.indexOf(a2)
	var lat=str.indexOf(a3)
	var lat=str.indexOf(a4)
	var lat=str.indexOf(a5)
	var lat=str.indexOf(a6)
	var lat=str.indexOf(a7)
	var lat=str.indexOf(a8)
	var lstr=str.length
	if (str.indexOf(a0)==0){
	   return false
	}
	if (str.indexOf(a1)==0){
	   return false
	}
	if (str.indexOf(a3)==0){
	   return false
	}
	if (str.indexOf(a4)==0){
	   return false
	}
	if (str.indexOf(a5)==0){
	   return false
	}
	if (str.indexOf(a6)==0){
	   return false
	}
	if (str.indexOf(a7)==0){
	   return false
	}
	if (str.indexOf(a8)==0){
	   return false
	}
	if (str.indexOf(a2)==0){
	   return false
	}
	return true					
}

function mobile_check2(str) {
	
	var at="0"
	var lat=str.indexOf(at)
	var lstr=str.length
	if (str.indexOf(at)==0){
	   //alert("Invalid E-mail ID")
	   return false
	}
	
	 return true					
	}

function veri_mobile(word){
	var iChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZY!@#$%^&*()+=-[]\\\';,./{}|\":<>? ";

  for (var i = 0; i < word.length; i++) {
  	if (iChars.indexOf(word.charAt(i)) != -1) {
  	return false;
  	}
  }
  return true;
	
}


function email_check(str) {
	
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   //alert("Invalid E-mail ID")
	   return false
	}
	
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   //alert("Invalid E-mail ID")
	   return false
	}
	
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    //alert("Invalid E-mail ID")
	    return false
	}
	
	 if (str.indexOf(at,(lat+1))!=-1){
	    //alert("Invalid E-mail ID")
	    return false
	 }
	
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    //alert("Invalid E-mail ID")
	    return false
	 }
	
	 if (str.indexOf(dot,(lat+2))==-1){
	    //alert("Invalid E-mail ID")
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    //alert("Invalid E-mail ID")
	    return false
	 }
	
	 return true					
	}
	
function veri_string(word){
	var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>? ";

  for (var i = 0; i < word.length; i++) {
  	if (iChars.indexOf(word.charAt(i)) != -1) {
  	return false;
  	}
  }
  return true;
	
}

function verify(form) {
	
    var username=form['username'].value;
		var pass=form['password'].value;
		var retype=form['confirm'].value;
		var email=form['email'].value;
		var mobile2=form['mobile2'].value;
		var mobile=form['mobile'].value;
		var bday=form['day'].value;
		var bmonth=form['month'].value;
		var byr=form['year'].value;
		var country_no=form['country'].value;
		
		var accept=form['accept'].checked	;
    
    
    if(username.length<3 )
    {
      document.getElementById('alert').innerHTML='<b>USERNAME</b> must have more than 3 characters.';
      return false;
    }
    
    if(!veri_string(username))
    {
     document.getElementById('alert').innerHTML='<b>Txtmate ID</b> must contain only alphabet,<br>numbers and underscore "_".<br>Special characters or spaces, are not allowed.';
      return false;
    }
    
    if(pass.length<3)
	  {
      document.getElementById('alert').innerHTML='<b>PASSWORD</b> must have more than 3 characters.';
      return false;
    }
    
    if(pass.toLowerCase()!=retype.toLowerCase())
	  {
      document.getElementById('alert').innerHTML='Please retype your password correctly.';
      return false;
    }
    
    if(mobile2.length<8 )
	  {
      document.getElementById('alert').innerHTML='<b>Mobile Number</b> must have more than 8 characters.';
      return false;
    }
    
    if(!veri_mobile(mobile2))
    {
     document.getElementById('alert').innerHTML='Please enter a valid <b>Mobile Number</b>.';
      return false;
    }
		       
    if(!veri_mobile(mobile))
    {
     document.getElementById('alert').innerHTML='Please enter a valid <b>Mobile Number</b>.';
      return false;
    }
    
    if(!mobile_check2(mobile2))
    {
    	document.getElementById('alert').innerHTML='<b>Mobile Number</b> must not start with zero.';
      return false;
    }
    
    if(mobile=="63"){
      if(!mobile_check(mobile2))
      {
       	document.getElementById('alert').innerHTML='Philippines <b>Mobile Number</b> must start with nine(9).';
      return false;
      }
    }
	
    if(!email_check(email))
    {
    	document.getElementById('alert').innerHTML='Please enter a valid <b>Email Address</b>.';
      return false;
    }
    if(bday.length==0)
    {
      document.getElementById('alert').innerHTML='Please complete your <b>Date of Birth</b>.';
      return false;
    }
    if(bmonth.length==0)
    {
      document.getElementById('alert').innerHTML='Please complete your <b>Date of Birth</b>.';
      return false;
    }
    if(byr.length==0)
    {
      document.getElementById('alert').innerHTML='Please complete your <b>Date of Birth</b>.';
      return false;
    }
    if (accept==0) 
    {
    		document.getElementById('alert').innerHTML='Do you agree to the <b>Terms and Conditions</b>?';
      return false;
    }
    
    
    return true;
 }
 
 function hijack(module)
 {
 	window.open('index.php?mod=' + module,'_self');
 }
function popup(link,h,w)
{ 
 window.open(link,null,
    "height="+h+",width="+w+",status=no,toolbar=no,menubar=no,location=no,resizeable=yes");
}


function validate()
{
	var message = ('These Field(s) Cannot be Empty:\n\n');	
	flag = 0;

	if (document.forms['frm_experience'].elements["descrip"].value == '')
	{	message = (message + 'Title\n');
		flag = 1;
	}	
	if (document.forms['frm_experience'].elements["experience"].value == '')
	{	message = (message + 'Content\n');
		flag = 1;
	}	
				
	if (flag == 1)
	{	
		alert(message);
		return false;
	}else{
		return true;				
	}		
}




