function clean_text(str)
{
	 //str = str.split("#").join("\#####");
	 //str = str.split("'").join("\'");
	 //str = str.split("\n").join("<br>");
	 str=encodeURIComponent(str);
	 str = str.split("%0D%0A").join("<br>");
	 str = str.split("%0A").join("<br>");
	 return str;
}

function clean_text_2(str)
{
	 str=encodeURI(str);
	 str = str.split("%0D%0A").join("<br>");
	 str = str.split("%0A").join("<br>");
	 return str;
}
function clean_text_3(str)
{
	 str=encodeURIComponent(str);
	 return str;
}

function check_email (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) {
                /* Too many/few @'s or something; basically, this address doesn't even fit the general mould of a valid e-mail address. */
                //alert("Email address seems incorrect (check @ and .'s)")
                return false
        }

        var user=matchArray[1]
        var domain=matchArray[2]
        if (user.match(userPat)==null) {
                // user is not valid
                //alert("The username doesn't seem to be valid.")
            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("Destination IP address is invalid!")
                                return false
                        }
                 }
                 return true
        }
        // Domain is symbolic name
        var domainArray=domain.match(domainPat)
        if (domainArray==null) {
                //alert("The domain name doesn't seem to be 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) {
                // the address must end in a two letter or three letter word.
            //alert("The address must end in a three-letter domain, or two letter country.")
            return false
        }

        // Make sure there's a host name preceding the domain.
        if (len<2) {
           //var errStr="This address is missing a hostname!"
           //alert(errStr)
           return false
        }
         return true;
}
//=============================
function CheckPhoneNumber(phoneNumber)
{
    var phoneRegex = /^(\d{8}|\d{9}|\d{10}|\d{11}|\d{12}|\d{13}|\d{14}|\d{15})$/;
        if( !phoneNumber.match( phoneRegex ) ) return false;
        return true;
}
//=================
function goto_page(page)
{
        window.location=page;
}


function createRequestObject()
{
         // find the correct xmlHTTP, works with IE, FF and Opera
         var xmlhttp;
         try
         {
             xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
         }
         catch(e)
         {
                   try
                   {
                       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                   }
                   catch(e)
                   {
                       xmlhttp=null;
                   }
         }
         if(!xmlhttp&&typeof XMLHttpRequest!="undefined")
         {
                   xmlhttp=new XMLHttpRequest();
         }
         return  xmlhttp;
}

function sendRequest(pg_url,handle_function)
{
         try
         {
                http.open("POST", pg_url, true);
                //http.setRequestHeader('Content-Type',  "text/xml");
                http.setRequestHeader("Content-length",5000);
                //http.setRequestHeader('Content-Type','text/xml;charset=UTF-8');
                http.setRequestHeader("Content-Type","application/ x-www-form-urlencoded");
                if(handle_function=="")
                http.onreadystatechange = handleResponse;
                else
                http.onreadystatechange = handle_function;
                http.send(null);
         }
         catch(e)
         {
                       // caught an error
                       // document.all.rowFinishing.style.display='none';
         }
         finally{}

}

function sendReq(pg_url,parameters,handle_function)
{
         try
         {

                http.onreadystatechange = handleSendJob;
                http.open("POST",pg_url,true);
                http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                http.setRequestHeader("Content-length", parameters.length);
                http.setRequestHeader("Connection","close");
                http.send(parameters);
         }
         catch(e)
         {

                alert('fail');
                // caught an error
                       // document.all.rowFinishing.style.display='none';
         }
         finally{}

}

function getpass()
{
        if(document.forms[0].hidden_action.value!="")
    	{
    		document.getElementById('alert').innerHTML='System is processing. Please wait ... ';
    		return false;
    	}
    	else if(!check_email(document.forms[0].txtEmail.value))
        {
                alert("Please enter your valid email address");
                document.forms[0].txtEmail.focus();
                return false;
        }       
        else
        {
                document.forms[0].hidden_action.value="CHANGEPASS";
                document.getElementById('alert').innerHTML='System is finding your password ... ';                
                sendRequest('http://demo.teksoftprint.com/cmp/fileadmin/template/cmp/getpass.php?email='+clean_text(document.forms[0].txtEmail.value),handlePass);
        }
}
function handlePass()
{
	 try
     {
         if((http.readyState == 4))
         {
            if((http.status == 200))
            {
               document.getElementById('alert').innerHTML = http.responseText;
            }
            else
            {
               document.getElementById('alert').innerHTML = 'System can not receive your action';
            }
			document.forms[0].hidden_action.value='';              
	     }
     }
     catch(e)
     {
         document.getElementById("alert").innerHTML="Permission denied";
         document.forms[0].hidden_action.value="";         
     }
     finally{}
}

//================================
var http = createRequestObject();

var menuids=["treemenu"] //Enter id(s) of SuckerTree UL menus, separated by commas
function buildsubmenus_horizontal(){
if(document.getElementById('active').getElementsByTagName('ul')[0])
document.getElementById('active').getElementsByTagName('ul')[0].style.visibility="visible";
for (var i=0; i<menuids.length; i++){   
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")  
  for (var t=0; t<ultags.length; t++){        
       
       ultags[t].parentNode.onmouseover=function(){             
          if(this.id != 'active'){
             if(document.getElementById('active').getElementsByTagName('ul')[0])
             document.getElementById('active').getElementsByTagName('ul')[0].style.visibility="hidden"; 
          }   
          if(this.getElementsByTagName('ul')[0])
          this.getElementsByTagName("ul")[0].style.visibility="visible";           
       }         
       ultags[t].parentNode.onmouseout=function(){                       
            if(this.getElementsByTagName('ul')[0])
            this.getElementsByTagName("ul")[0].style.visibility="hidden";    
            if(document.getElementById('active').getElementsByTagName('ul')[0])                      
            document.getElementById('active').getElementsByTagName('ul')[0].style.visibility="visible";            
       }
    }
  }
}

if (window.addEventListener)
window.addEventListener("load", buildsubmenus_horizontal, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus_horizontal)

          
