var marked_row = new Array;

function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    }
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    }
    if (newColor) {
        var c = null;
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            }
        }
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    }
    return true;
}

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) {

                //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 delete_acticle(msg)
{
		if(confirm("Are you sure you want to delete this "+msg)){
		   document.forms[0].hidden_action.value="DELETE";
		   document.forms[0].submit();
		}
}
//=================
function cbx_select(str,dr_name)
{

    for (i=0;i<eval("document.forms[0]." + dr_name + ".length");i++)
    {
      if (eval("document.forms[0]." + dr_name + ".options["+i+"].value")==str)
      {
         eval("document.forms[0]." + dr_name + ".options["+i+"].selected=true");
      }
   }
}
//===============
function radio_select(str_value,radio_name)
{
        for (i=0;i<eval("document.forms[0]." + radio_name + ".length");i++)
        {
        if (eval("document.forms[0]." + radio_name + "["+i+"].value")==str_value)
        {
            eval("document.forms[0]." + radio_name + "["+i+"].checked=true");
        }
    }
}
//===============
function chx_select(chx_name,vl)
{
    eval("document.forms[0]." + chx_name + ".checked="+vl);
}

function check_all(checkbox_name)
{
        if (document.forms[0].checkall.value==""){
                for(i=0;i<eval('document.forms[0].'+checkbox_name+'.length');i++)
                {
                        eval('document.forms[0].'+checkbox_name+'['+i+'].checked=true');
                }
                document.forms[0].checkall.value="OK";
        }
        else
        {
                for(i=0;i<eval('document.forms[0].'+checkbox_name+'.length');i++)
                {
                        eval('document.forms[0].'+checkbox_name+'['+i+'].checked=false');
                }
                document.forms[0].checkall.value="";
        }
}
//==============

function show_all()
{
        if(document.forms[0].hidden_action.value!=""){
    		alert("System is processing. Please wait ... ");
    		return false;
    	}
        else{
            document.forms[0].hidden_action.value="SHOWALL";
        	document.forms[0].submit();
        }
}
//================

function change_stat(formname,note)
{
    if(document.forms[0].hidden_action.value!=""){
    	alert("System is processing. Please wait ... ");
    	return false;
    }
    else if(test_checkbox(formname)==false){
        alert(note);
        return false;
    }
    if(document.forms[0].slcStatus.value==""){
        alert("Please select a status");
        document.forms[0].slcStatus.focus();
        return false;
    }
    else if(confirm("Are you sure you want to change status?")){

        document.forms[0].hidden_action.value="CHANGESTATUS";
        document.forms[0].submit();
    }
}

//==================

function test_checkbox(checkbox_name)
{
    for(i=0;i<eval('document.forms[0].'+checkbox_name+'.length');i++){
                 if(eval('document.forms[0].'+checkbox_name+'['+i+'].checked')==true){
                     return true;
                 }
    }
    return false;
}
function get_checkbox(checkbox_name)
{
    var str="";
    for(i=0;i<eval('document.forms[0].'+checkbox_name+'.length');i++){
                 if(eval('document.forms[0].'+checkbox_name+'['+i+'].checked')==true){
                     if(str!="")
                     str+=",";
                     str+=eval('document.forms[0].'+checkbox_name+'['+i+'].value');
                 }
    }
    return str;
}

function show_element(f)
{
        if(f!="")
        eval("document.getElementById('"+f+"').style.display=''");
}

function show_hide(f1,f2)
{
        if(f1!="")
        eval("document.getElementById('"+f1+"').style.display=''");
        if(f2!="")
        eval("document.getElementById('"+f2+"').style.display='none'");
}
function show_hide_parent(f1,f2)
{
        if(f1!="")
        eval("window.parent.document.getElementById('"+f1+"').style.display=''");
        if(f2!="")
        eval("window.parent.document.getElementById('"+f2+"').style.display='none'");
}

function check_show_hide(ch,ly)
{

		if(eval("document.forms[0]."+ch+".checked")==true)
		eval("document.all."+ly+".style.display='';");
		else
		eval("document.all."+ly+".style.display='none';");

}
function disable(f,vl)
{
        if(f!="")
        eval("document.forms[0]."+f+".disabled="+vl+";");
}
function getfocus(f)
{
        if(f!="")
        eval("document.forms[0]."+f+".focus();");
}


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("GET", 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 go_to()
{
        if(isNaN(document.forms[0].txtPage.value) || document.forms[0].txtPage.value==""){
                alert("Please enter page muner");
                document.forms[0].txtPage.focus();
        }
        else{
                var pg=document.forms[0].txtPage.value - 1;
                var gr=(pg-(pg%15))/15;

                goto_page("list_customers.php?pg="+pg+"&gr="+gr);
        }
}

function ShowLayer(layername,frname) {
        // show layer
        var layer = document.getElementById(layername);
        layer.style.display = '';
        // show IFRAME
        var iframe = document.getElementById(frname);
        iframe.style.display = '';
        iframe.style.width = layer.offsetWidth;
        iframe.style.height = layer.offsetHeight;
        iframe.style.left = layer.offsetLeft;
        iframe.style.top = layer.offsetTop;
    }
    function HideLayer(layername,frname) {
        // hide IFRAME
        var iframe = document.getElementById(frname);
        iframe.style.display = 'none';
        // hide layer
        var layer = document.getElementById(layername);
        layer.style.display = 'none';
    }


function put_title(title,layer,parent)
{
	if(parent==false)
	eval("window.document.all."+layer+".innerHTML='"+title+"';");
	else
	eval("window.parent.document.all."+layer+".innerHTML='"+title+"';");
}

function open_popup(ad,w,h)
{
   	window.open (ad, "", "height="+h+", width="+w+", toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, directories=no, status=no");
}

function print_it()
{
	window.print();
	window.close();
}


function send_email_address()
{
	if(document.forms[0].hidden_action.value!=""){
       alert("System is seding your email address. 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();
	}
	else{

		document.forms[0].hidden_action.value="SENDING";
		document.getElementById('process').innerHTML ='<table><tr><td><img src="images/processing.gif"></td><td>Sending ...</td></tr></table>';
		document.getElementById('process').style.display='';
		sendRequest(window.location.href + '/behind.php?e_a='+document.forms[0].txtEmail.value,handleSendEmail);
	}
}

function handleSendEmail()
{
	try
     {
         if((http.readyState == 4))
         {
              var response = http.responseXML.documentElement;
              document.getElementById('process').innerHTML =response.getElementsByTagName('send_alert')[0].firstChild.nodeValue;
              document.forms[0].hidden_action.value="";
              document.forms[0].txtEmail.value="";
	     }
     }
     catch(e)
     {
         document.getElementById('process').innerHTML ="Can not send !";
         document.forms[0].hidden_action.value="";
     }
     finally{}
}



var http = createRequestObject();

