function pressenterkey(evt,id)
{

    var key = (evt.which) ? evt.which : event.keyCode
    if(key==13)
    {
        if(document.getElementById(id)!=null)
            document.getElementById(id).focus();
    }
}


function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {
        xmlHttp=new XMLHttpRequest();
    }
    catch(e)
    {
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}
/*********** Ajax Loader New *************/
function ProcessLoader()
{
    document.getElementById('dvprocessing').style.display = '';
}
/****************************************/
function CalculateTop(Height)
{
    var ScrollTop=document.body.scrollTop;
    if(ScrollTop==0)
    {
        if(window.pageYOffset)
            ScrollTop=window.pageYOffset;
        else
            ScrollTop=(document.body.parentElement)?document.body.parentElement.scrollTop:0;
    }

    var BodyHeight=document.body.clientHeight;

    if(BodyHeight==0)
    {
        BodyHeight=window.innerHeight;
    }
    if(BodyHeight==0)
    {
        BodyHeight=document.documentElement.clientHeight
    }

    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;
    }
    var FinalTop=((myHeight-Height)/2)+ScrollTop;
    return FinalTop;
}
function CalculateLeft(Weight)
{
    var ScrollLeft=document.body.scrollLeft;

    if(ScrollLeft==0)
    {
        if(window.pageXOffset)
            ScrollLeft=window.pageXOffset;
        else
            ScrollLeft=(document.body.parentElement)?document.body.parentElement.scrollLeft:0;
    }

    var BodyWeight=document.documentElement.clientWidth;

    if(BodyWeight==0)
    {
        BodyWeight=document.body.clientWidth;
    }

    var FinalLeft=(BodyWeight+ScrollLeft-Weight)/2;

    return FinalLeft;
}

/***************** Setting the Dimmer while loading *********************/

function styledPopupClose()
{
    //document.getElementById("fadeboxiframe").value = "";
    document.getElementById("dvregisterfrm").style.innerHTML = "";
    document.getElementById("dvregisterfrm").style.display = "none";
    document.getElementById('dimmer').style.visibility = 'hidden';
    hideIframe();
  
}

function hideIframe()
{
	
    if(ie)
    {
        var theIframe=document.getElementById("fadeboxiframe")
		
        if(theIframe!=null)
        {
            theIframe.style.display="none";
        }
    }
}

function SetBackground()
{
    document.getElementById('dvprocessing').style.display = '';
//	document.getElementById('dimmer').style.width=GetBodyWidth();
//	document.getElementById('dimmer').style.height=GetBodyHeight();
//	document.getElementById('dimmer').style.visibility="visible";
}
function UnsetBackground()
{
    document.getElementById('dimmer').style.width=0;
    document.getElementById('dimmer').style.height=0;
    document.getElementById('dimmer').style.visibility="";
    document.getElementById('dvprocessing').style.display = 'none';
//document.getElementById('dvprocessing').style.display = 'none';
//unhideIframe();
}

function unhideIframe()
{
    if(ie)
    {
        var theIframe=document.getElementById("fadeboxiframe")
        var theDiv=document.getElementById("dvregisterfrm");
        theIframe.style.width=theDiv.offsetWidth+'px';
        theIframe.style.height=theDiv.offsetHeight+'px';
        theIframe.style.top=theDiv.offsetTop+'px';
        theIframe.style.left=theDiv.offsetLeft+'px';
        theIframe.style.display='';
    }
}

/***********************************************************************/

function GetBodyWidth()
{
    var theWidth=0;
    if(document.body)
    {
        theWidth=document.body.clientWidth;
    }
    else if(document.documentElement&&document.documentElement.clientWidth)
    {
        theWidth=document.documentElement.clientWidth;
    }
    else if(window.innerWidth)
    {
        theWidth=window.innerWidth;
    }

    theWidth=theWidth-80;

    return theWidth+ "px";
}

function GetBodyHeight()
{		
    var theHeight1=0;
    var theHeight2=0;
    var theHeight3=0;
	
    //alert(window.innerHeight);
    if(window.innerHeight)
    {
        theHeight1=window.innerHeight;
    }
	
    if(document.documentElement&&document.documentElement.clientHeight)
    {
        //alert(document.documentElement.clientHeight);
        theHeight2 = document.documentElement.clientHeight;
    }
    /*if(document.body)
	 {
       theHeight3=document.body.clientHeight;
		if(isMozilla)
		{   
		  var theHeight4 = 0;
		}
		else
		{
			theHeight4=document.body.scrollHeight;
		}
	}*/
    FinalHeight=Math.max(theHeight1,theHeight2,theHeight3);
    FinalHeight=FinalHeight-70;
    return FinalHeight+ "px";
	
}

function rem_special_char_js(var_string)
{
    //alert("==>"+var_string);
    var iChars =/\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g;
    //var_string
    //alert(var_string.replace(iChars, ""));
    var_string=var_string.replace(iChars, "");
    //$var_string = var_string.replace("'", "\'", $searchtxt);
    return var_string;
}

function rem_special_chars_js($string)
{
    $string = eregi_replace("'","&#092;'",$string);
    $string = eregi_replace('"','&quot;',$string);
    return $string;
}
// Bind the Grid On Action of Paging,Searching,Sorting - Atul 03042010
function SendGridBindRequest(url,targetdiv,action,chkidfordelete,flgdisorder)
{

    xmlHttp = GetXmlHttpObject();
    if(xmlHttp != null)
    {
        //alert(xmlHttp.readyState);
        xmlHttp.onreadystatechange = function()
        {
            if(xmlHttp.readyState==1)
            {
                // ProcessLoader();
                SetBackground();
            }
			
            if((xmlHttp.readyState==4||xmlHttp.readyState=="complete")&&(xmlHttp.status==200))
            {
				
                var str =  trim(xmlHttp.responseText);
			
                document.getElementById(targetdiv).innerHTML = '';
                document.getElementById(targetdiv).innerHTML = str;
				
                UnsetBackground();
				
                switch(action)
                {
                    case 'S': // to set the focus on the search text field
                        document.getElementById('searchtxt1').focus();
                        break;
                    case 'Gtop': // to set the focus on the go to page text field on top
                        document.getElementById('txtgotopagetop').focus();
                        break;
                    case 'Gbottom': // to set the focus on the go to page text field on bottom
                        document.getElementById('txtgotopagebottom').focus();
                        break;
                    case 'D': // This is when the delete button is clicked
                        alert("Records deleted successfully.");
                        break;
                    case 'none': // This is for delete ids directly passed
                        alert("No Records deleted .");
                        break;
                    case 'PS': //This is for for focusing display select box
                        var position = trim(document.getElementById('position').value);
                        document.getElementById('cmbdisplay'+position).focus();
                        break;
                    case 'FT':
                        document.getElementById('filterbytop').focus();
                    case 'FB':
                        document.getElementById('filterbybottom').focus();
                    case 'MT':
						 
                        document.getElementById('cmbmodulestop').focus();
                        break;

                    case 'MB':
                        document.getElementById('cmbmodulesbottom').focus();
                    case 'CAT':
                        document.getElementById('cmbcattop').focus();
						
                        break;
                }
            }
        };
		
        var appendurl = '';
        
        switch(action)

               
        {
            case 'PStop':
                //var position = trim(document.getElementById('position').value);
				 
                var pagesize = trim(document.getElementById('cmbdisplaytop').value);
				 
                appendurl = '&pagesize='+pagesize;
                if (chkObjects('cmbmodulestop'))
                {
                    var filterby = trim(document.getElementById('cmbmodulestop').value);
                    appendurl = '&pagesize='+pagesize+'&view='+filterby;
                }
				 
                break;
            case 'PSbottom':
                // var position = trim(document.getElementById('position').value);

                var pagesize = trim(document.getElementById('cmbdisplaybottom').value);

                appendurl = '&pagesize='+pagesize;
				 
                if (chkObjects('cmbmodulesbottom'))
                {
                    var filterby = trim(document.getElementById('cmbmodulesbottom').value);
                    appendurl = '&pagesize='+pagesize+'&view='+filterby;
                }

                break;
			
            case 'S': // This is for search
                var searchtxt = trim(document.getElementById('searchtxt1').value);
                            
                var searchby = document.getElementById('searchby').value;
                appendurl = '&searchby='+searchby+'&searchtxt='+searchtxt;
			
                break;
				
            case 'FT': // This is for filter
				
                var filterby = trim(document.getElementById('filterbytop').value);
                appendurl = '&filterby='+filterby;

                break;
				
            case 'FB': // This is for filter
				
                var filterby = trim(document.getElementById('filterbybottom').value);
                appendurl = '&filterby='+filterby;

                break;
				
            case 'MT': // This is for filter by modules in trash manager

                var filterby = trim(document.getElementById('cmbmodulestop').value);
                var tid = document.getElementById('h_view').value;
                document.getElementById('trname').value=document.getElementById('cmbmodulestop').value;
					
                var pagesize = trim(document.getElementById('cmbdisplaytop').value);
                //					alert(document.getElementById('trname').value)


                $(function() {

                                                        
                    var view=document.getElementById('trname').value;
							
                    var flagChange = false;
                    $("#searchby").change(function() {
                        flagChange = true;
                        var changeVal = $("#searchby option:selected").val();
                        $("#searchtxt1").autocomplete({
														  
                            source: "index.php?auto=searchval&module=trashmanager&searchbyVal="+changeVal+"&view="+view,
                            term:'term',
                            minLength: 2,
                            select: function(event, ui) {
                                $('#searchtxt1').val(ui.item.id);
                            }
                        });
                    });
                    if(flagChange == false)
                    {
                        $('#searchtxt1').live('keypress', function() {
                            $(this).autocomplete({
                                source: "index.php?auto=searchval&module=trashmanager&searchbyVal="+$("#searchby option:selected").val()+"&view="+view,
                                term:'term',
                                minLength: 2,
                                select: function(event, ui) {
                                    $('#searchtxt1').val(ui.item.id);
                                }
                            });
                        });
                    }
                });
 
                appendurl = '&view='+filterby + '&pagesize='+pagesize;
                //appendurl = '&pagesize='+pagesize;
                break;
				
            case 'MB': // This is for filter by module
				
                var filterby = trim(document.getElementById('cmbmodulesbottom').value);
                // appendurl = '&view='+filterby;
			   
                var pagesize = trim(document.getElementById('cmbdisplaybottom').value);
				 
                appendurl = '&view='+filterby + '&pagesize='+pagesize;
				
                break;	
			
            case 'CAT': // This is for filter by modules in trash manager

                var filterby = trim(document.getElementById('cmbcattop').value);

                var tid = document.getElementById('h_view').value;
                document.getElementById('trname').value=document.getElementById('cmbcattop').value;
					
                var pagesize = trim(document.getElementById('cmbdisplaytop').value);
                //					alert(document.getElementById('trname').value)
					
                appendurl = '&view='+filterby + '&pagesize='+pagesize;
                // alert(appendurl)
                //appendurl = '&pagesize='+pagesize;
                break;
				
            case 'COTRCT': // This is for filter by modules in trash manager

                var filterby = trim(document.getElementById('cmbconttop').value);

                var tid = document.getElementById('h_view1').value;
                document.getElementById('trname').value=document.getElementById('cmbconttop').value;
					
                var pagesize = trim(document.getElementById('cmbdisplaytop').value);
                //					alert(document.getElementById('trname').value)
					
                appendurl = '&view1='+filterby + '&pagesize='+pagesize;
                // alert(appendurl)
                //appendurl = '&pagesize='+pagesize;
                break;	
			
            case 'Gtop': // This is for go to page text field top
                
                var noofpages = trim(document.getElementById('hdnnoofpages').value);
                var enteredpageno = trim(document.getElementById('txtgotopagetop').value);
                if(enteredpageno == '' || enteredpageno == 0)
                {
                    alert("Please enter page number.");
                    document.getElementById('txtgotopagetop').focus();
                    return false;
                }
                else if(parseInt(enteredpageno) > parseInt(noofpages))
                {
                    alert("Please enter proper page number.");
                    document.getElementById('txtgotopagetop').focus();
                    return false;
                }
                appendurl = '&pagenumber='+enteredpageno;
                break;
				
            case 'Gbottom': // This is for go to page text field bottom
              
                var noofpages_2 = trim(document.getElementById('hdnnoofpages').value);
                var enteredpageno_2 = trim(document.getElementById('txtgotopagebottom').value);
                if(enteredpageno_2 == '' || enteredpageno_2 == 0)
                {
                    alert("Please enter page number.");
                    document.getElementById('txtgotopagebottom').focus();
                    return false;
                }
                else if(parseInt(enteredpageno_2) > parseInt(noofpages_2))
                {
                    alert("Please enter proper page number.");
                    document.getElementById('txtgotopagebottom').focus();
                    return false;
                }
                appendurl = '&pagenumber='+enteredpageno_2;
                break;
				
            case 'D': // This is for delete
			       
	             
                var chkelements = document.getElementsByName(chkidfordelete);
                var ids = "";
                var countChecked = 0;
                for(var i = 0; i < chkelements.length; i++)
                {
                    if(chkelements.item(i).checked == true)
                    {
                        countChecked++;
                        if(ids != "")
                            ids += ",";
                        ids += chkelements.item(i).value;
                    }
                }
                if(countChecked == 0)
                {
                    alert(" Please select atleast one record for delete.");
                    return false;
                }
                if(!confirm('This will delete the selected records.Are you sure you want to continue?'))
                {
                    return false;
                }
                //alert(ids);
                var totalpagerecords = document.getElementById('ptrecords').value;
				
                appendurl = '&action=delete&ptotalr='+totalpagerecords+'&dids='+ids;
				
                break;
				
            case 'Delids': // This is for delete ids directly passed
			       
                var ids=chkidfordelete;
                var totalpagerecords = document.getElementById('ptrecords').value;
             	
                appendurl = '&action=delete&ptotalr='+totalpagerecords+'&dids='+ids;
				
                break;


                       

            // END Export file
                        
            case 'Delids': // This is for delete ids directly passed

                var ids=chkidfordelete;
                var totalpagerecords = document.getElementById('ptrecords').value;

                appendurl = '&action=delete&ptotalr='+totalpagerecords+'&dids='+ids;

                break;


            case 'AP': // This is for approve in grid
                appendurl = '&QT=4';
                break;
			
            case 'DISP': // This is for display in grid
                appendurl = '&action=display&QT=5';
                break;
			
            case 'CACHE': // This is for display in grid
                appendurl = '&action=cache&QT=5';
                break;
			
            case 'DEFAULT': // This is for display in grid
                appendurl = '&action=setdefault&QT=5';
                break;
			
            case 'QEDIT': // This is for quick edit in grid
                var quickfields = new Array();
                var varname = new Array();
                quickfields = chkidfordelete.split(',');
                for(i=0;i<quickfields.length;i++)
                {
                    varname[i] = document.getElementById(quickfields[i]).value;
                }
                appendurl = '&QT=6&varname='+varname+'';
                break;
			
            case 'APR': // This is for approve rating in grid
                appendurl = '&QT=7';
                break;
			
            case 'DO': // This is for bulk display order in grid
                var totalrows = document.getElementById('ptrecords').value;
                var ids = "";
                var values = "";
                var oldvalues = "";
                var commonglcode = "";
					
                var elementforid = "";
                var elementforvalues = "";
                var elementforoldvalues = "";
                var elementforcommonglcodes = "";
					
                for(var i = 0; i < totalrows; i++)
                {
                    if(ids != "")
                        ids += ",";
							
                    if(values != "")
                        values += ",";
							
                    if(oldvalues != "")
                        oldvalues += ",";
						
                    elementforid = "hdnintglcode" + i;
                    elementforvalues = "displayorder" + i;
                    elementforoldvalues = "hdndisplayorder" + i;
						
                    if(trim(document.getElementById(elementforvalues).value) == "")
                    {
                        alert("Field(s) cannot be left blank.");
                        document.getElementById(elementforvalues).value='';
                        document.getElementById(elementforvalues).focus();
                        return;
                    }
                    if(document.getElementById(elementforvalues).value == "0")
                    {
                        alert("Display order cannot be zero");
                        document.getElementById(elementforvalues).value='';
                        document.getElementById(elementforvalues).focus();
                        return;
                    }
						
                    ids += document.getElementById(elementforid).value;
                    values += document.getElementById(elementforvalues).value;
                    oldvalues += document.getElementById(elementforoldvalues).value;

                    if(flgdisorder)
                    {
                        if(commonglcode != "")
                            commonglcode += ",";
						 
                        elementforcommonglcodes = "hdncommonglcode" + i;
                        commonglcode += document.getElementById(elementforcommonglcodes).value;
							
                    }
                }
                appendurl = '&task=orderupdate&uids='+ids+'&uvals='+values+'&uoldvals='+oldvalues+'&cmnglcode='+commonglcode;
					
                break;
            case 'MUS': // This is for music in event category grid
                appendurl = '&QT=9';
					 
                break;
            case 'ORDSTATUS': // This is for Order Status Combo
                appendurl = '&QT=10&ordstatusglcode='+chkidfordelete;
                //alert(appendurl);
					 
                break;
            case 'RECMD': // This is for Pinstripe Recommended Combo
                appendurl = '&QT=11';
					 
                break;
            case 'NEWSLET': // This is for Newsletter
                appendurl = '&QT=12';
                break;
			
        }
        //alert(url + '&ajax=Y'+appendurl);
        xmlHttp.open('GET', url + '&ajax=Y'+appendurl, true);
        xmlHttp.send(null);
    }
    else
    {
        alert("Your browser does not support HTTP Request");
    }
    return true;
}
// End Of Bind the Grid - Atul 03042010





//Check delete bus in use or not!!
function checkDeleteExist(url,targetdiv,action,chkidfordelete,flgdisorder)
{
    xmlHttp = GetXmlHttpObject();
    if(xmlHttp != null)
    {
        xmlHttp.onreadystatechange = function()
        {
            if(xmlHttp.readyState==1)
            {
                ProcessLoader();
            }
            if((xmlHttp.readyState==4||xmlHttp.readyState=="complete")&&(xmlHttp.status==200))
            {
				
                var str =  trim(xmlHttp.responseText);
				
                document.getElementById(targetdiv).innerHTML = '';
                document.getElementById(targetdiv).innerHTML = str;
                document.getElementById('dimmer').style.width=0;
                document.getElementById('dimmer').style.height=0;
                document.getElementById('dimmer').style.visibility="";
                document.getElementById('dvprocessing').style.display = 'none';
				
                alert("Records deleted successfully.");
					
            }
        };
        var appendurl = '';
	   
        var chkelements = document.getElementsByName(chkidfordelete);
        var ids = "";
        var countChecked = 0;
        for(var i = 0; i < chkelements.length; i++)
        {
            if(chkelements.item(i).checked == true)
            {
                countChecked++;
                if(ids != "")
                    ids += ",";
                ids += chkelements.item(i).value;
            }
        }
        if(countChecked == 0)
        {
            alert(" Please select atleast one record for delete.");
            return false;
        }
		
        var totalpagerecords = document.getElementById('ptrecords').value;
		
        appendurl = '&QT=3&ptotalr='+totalpagerecords+'&dids='+ids;
        //alert(url + '&ajax=Y'+appendurl);
		
        xmlHttp.open('GET', url + '&ajax=Y'+appendurl, true);
        xmlHttp.send(null);
    }
    else
    {
        alert("Your browser does not support HTTP Request");
    }
    return true;
}


// Common function for updating a star
function UpdateStar(tablename, fieldname,intglcode)
{
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null)
    {
        alert ("Your browser does not support XMLHTTP!");
        return;
    }
	
    var path=document.getElementById('star-'+intglcode).src;
    var file_a= path.substring(path.lastIndexOf("/")+1,path.length);
    var value;
    if(file_a == 'gstar.png')
    {
        value = 'N';
    }
    else if(file_a == 'gstar-disable.png')
    {
        value = 'Y';
    }
	
    var url = "index.php?ajax=Y&tablename="+tablename+"&fieldname="+fieldname+"&value="+value+"&id="+intglcode;
	
    //  var url = "commanajax.php?method=updatefield&tablename="+tablename+"&fieldname="+fieldname+"&value="+value+"&id="+intglcode;
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState==1)
        {
            //ProcessLoader();
            SetBackground();
        }
        if((xmlHttp.readyState==4||xmlHttp.readyState=="complete")&&(xmlHttp.status==200))
        {
            var result = xmlHttp.responseText;
			
            if(result == 1)
            {
                if(value == 'Y')
                {
                    document.getElementById('star-'+intglcode).src = 'html/images/gstar.png';
                //document.getElementById('star-'+intglcode).onclick = function(){UpdateStar('pst_restaurant','chrstar','N',intglcode);};
                }
                else
                {
                    document.getElementById('star-'+intglcode).src = 'html/images/gstar-disable.png';
                //document.getElementById('star-'+intglcode).onclick = function(){UpdateStar('pst_restaurant','chrstar','Y',intglcode);};
	
                }
            }
            else
            {
                alert("Sorry could not update...");
            }
			
            UnsetBackground();
        /*	document.getElementById('dimmer').style.width=0;
			document.getElementById('dimmer').style.height=0;
			document.getElementById('dimmer').style.visibility="";
			document.getElementById('dvprocessing').style.display = 'none';*/
        }
    };
	
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
// End Of Common function for updating star



// Common function for updating publish   //UpdateDefault
function UpdatePublish(tablename, fieldname,intglcode)

{

    xmlHttp = GetXmlHttpObject();

    if (xmlHttp == null)

    {

        alert ("Your browser does not support XMLHTTP!");

        return;

    }

	

    var path=document.getElementById('tick-'+intglcode).src;

    var file_a= path.substring(path.lastIndexOf("/")+1,path.length);

    var value;

    if(file_a == 'tick.png')

    {

        value = 'N';

    }

    else if(file_a == 'tick_cross.png')

    {

        value = 'Y';

    }

	

    var url = "index.php?ajax=Y&tablename="+tablename+"&fieldname="+fieldname+"&value="+value+"&id="+intglcode;

	

    //  var url = "commanajax.php?method=updatefield&tablename="+tablename+"&fieldname="+fieldname+"&value="+value+"&id="+intglcode;

    xmlHttp.onreadystatechange = function()

    {

        if(xmlHttp.readyState==1)

        {

            //ProcessLoader();

            SetBackground();

        }

        if((xmlHttp.readyState==4||xmlHttp.readyState=="complete")&&(xmlHttp.status==200))

        {

            var result = xmlHttp.responseText;

			

            //	alert(document.getElementById('tick-'+intglcode));

			

            if(result == 1)

            {

                if(value == 'Y')

                {

                    document.getElementById('tick-'+intglcode).src = 'html/images/tick.png';

                //document.getElementById('star-'+intglcode).onclick = function(){UpdateStar('pst_restaurant','chrstar','N',intglcode);};

                }

                else

                {

                    document.getElementById('tick-'+intglcode).src = 'html/images/tick_cross.png';

                //document.getElementById('star-'+intglcode).onclick = function(){UpdateStar('pst_restaurant','chrstar','Y',intglcode);};

                }

            }

            else

            {

                alert("Sorry could not update...");

            }

			

            UnsetBackground();

        /*	document.getElementById('dimmer').style.width=0;

			document.getElementById('dimmer').style.height=0;

			document.getElementById('dimmer').style.visibility="";

			document.getElementById('dvprocessing').style.display = 'none';*/

        }

    };

    xmlHttp.open("GET",url,true);

    xmlHttp.send(null);

}
// End Of Common function for updating publish

function updatetrashlist(cmbid,targetdiv)
{
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null)
    {
        alert ("Your browser does not support XMLHTTP!");
        return;
    }
	
   
    
    var value;
   
    var view= document.getElementById(cmbid).value;
    var module='trashmanager';
    //var url = "index.php?ajax=Y&tablename="+tablename+"&fieldname="+fieldname+"&value="+value+"&id="+intglcode+"&othertablename="+othertable;
	
    var url = "index.php?ajax=Y&module="+module+"&view="+view;

	
    //  var url = "commanajax.php?method=updatefield&tablename="+tablename+"&fieldname="+fieldname+"&value="+value+"&id="+intglcode;
    //alert(url);
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState==1)
        {
            //ProcessLoader();
            SetBackground();
        }
        if((xmlHttp.readyState==4||xmlHttp.readyState=="complete")&&(xmlHttp.status==200))
        {
            var result = xmlHttp.responseText;
            //alert(result);
			
            document.getElementById(targetdiv).innerHTML = '';
            document.getElementById(targetdiv).innerHTML = result;

			
            /*if(result == 1)
			{
				
			}
			else
			{
				alert("Sorry could not update...");
			}*/
			
            UnsetBackground();
        /*	document.getElementById('dimmer').style.width=0;
			document.getElementById('dimmer').style.height=0;
			document.getElementById('dimmer').style.visibility="";
			document.getElementById('dvprocessing').style.display = 'none';*/
        }
    };
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}



function updatereadstar(cmbid,tablename,chkidfordelete)
{
    if(document.getElementById(cmbid).value == '0')
        return false;
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null)
    {
        alert ("Your browser does not support XMLHTTP!");
        return;
    }
    var chkelements = document.getElementsByName(chkidfordelete);
    
    var ids = "";
    var countChecked = 0;
    for(var i = 0; i < chkelements.length; i++)
    {
        if(chkelements.item(i).checked == true)
        {
            countChecked++;
            if(ids != "")
                ids += ",";
            ids += chkelements.item(i).value;
        }
    }
    if(countChecked == 0)
    {
        alert(" Please select atleast one record for change.");
        document.getElementById('cmbmoreactiontop').value = '0';
        //document.getElementById('cmbmoreactionbottom').value = '0';
        return false;
    }
    
    var cmboption = document.getElementById(cmbid).value;
    var fieldname;
    var value;
    switch(cmboption)
    {
        case 'r': // To Mark As Read
            fieldname = 'chr_read';
            value = 'Y';
            break;
        case 'ur': // To Mark As UnRead
            fieldname = 'chr_read';
            value = 'N';
            break;
        case 'as': // Too Add Star
            fieldname = 'chr_star';
            value = 'Y';
            break;
        case 'rs': // Too Remove Star
            fieldname = 'chr_star';
            value = 'N';
            break;
        
    }
    var url = "index.php?ajax=Y&tablename="+tablename+"&fieldname="+fieldname+"&value="+value+"&id="+ids;
    //alert(url );
    xmlHttp.onreadystatechange = function(){
        if(xmlHttp.readyState==1)
        {
            //ProcessLoader();
            SetBackground();
        }
        if((xmlHttp.readyState==4||xmlHttp.readyState=="complete")&&(xmlHttp.status==200))
        {
            var result = xmlHttp.responseText;
            var idarray = ids.split(',');
            var classname ;
            var classarray ;
            var finalclassname;
            ///////////alert(result);
            if(result == 1)
            {
                if(value == 'Y' && fieldname == 'chr_star')
                {
                    for ( var i=0, len=idarray.length; i<len; ++i ){
					   
                        document.getElementById('star-'+idarray[i]).src = 'html/images/gstar.png';
                    }
                }
                else if(value == 'N' && fieldname == 'chr_star')
                {
                    for ( var i=0, len=idarray.length; i<len; ++i ){
					
                        document.getElementById('star-'+idarray[i]).src = 'html/images/gstar-disable.png';
                    }
                }
			
			
                if(value == 'Y' && fieldname == 'chr_read')
                {
                    for ( var i=0,len=idarray.length; i<len; ++i )
                    {
                        //classname= document.getElementById('gtr-'+idarray[i]).className;
                        //classarray = classname.split('_');
                        //finalclassname = classarray[0];
                        document.getElementById('gtr-'+idarray[i]).className = 'grid-list-inner-table-text';
                    }
                }
                if(value == 'N' && fieldname == 'chr_read')
                {
                    for ( var i=0, len=idarray.length; i<len; ++i ){
                        //classname= document.getElementById('gtr-'+idarray[i]).className;
                        //classarray = classname.split('_');
                        //finalclassname = classarray[0]+'_b' ;
                        document.getElementById('gtr-'+idarray[i]).className = 'grid-list-inner-table-text-active';
                    }
                }
			
                document.getElementById(cmbid).value = '0';
            }
            else
            {
                alert("Sorry could not update...");
            }
		
            UnsetBackground();
        /*document.getElementById('dimmer').style.width=0;
		document.getElementById('dimmer').style.height=0;
		document.getElementById('dimmer').style.visibility="";
		document.getElementById('dvprocessing').style.display = 'none';*/
        }
    };
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}


/*-------------------------------Javascrit basic functions start here--------------------------------------------*/



//for left and right panels
function showHidePanels(id)
{
    var idstr1 = id+1;
    var idstr2 = id+2;
	
    if(document.getElementById(id).style.display == '')
    {
		
        document.getElementById(id).style.display = 'none';
        document.getElementById(idstr1).style.display = 'none';
        //document.getElementById(idstr2).style.display = 'none';
		
		
        document.getElementById(id).setAttribute('width', 0);
        document.getElementById(idstr1).setAttribute('width', 0);
        document.getElementById(idstr2).setAttribute('width', 5);
    }
    else
    {
        document.getElementById(id).style.display = '';
        document.getElementById(idstr1).style.display = '';
        document.getElementById(idstr2).style.display = '';
		
        document.getElementById(id).setAttribute('width', 204);
        document.getElementById(idstr1).setAttribute('width', 204);
        document.getElementById(idstr2).setAttribute('width', 5);
    }
}
// For tree-table
function expandCollapse(id)
{
    var cid = "collapse" + id;
    if(document.getElementById(id).style.display == "")
    {
        document.getElementById(id).style.display = "none";
        document.getElementById(cid).innerHTML = "+";
    }
    else
    {
        document.getElementById(id).style.display = "";
        document.getElementById(cid).innerHTML = "-";
    }
}


function expandcollapsepanel(panelid)
{

    if(document.getElementById(panelid).style.display == '')
    {
        document.getElementById(panelid).style.display = 'none';
    }
    else
    {
        document.getElementById(panelid).style.display = '';
    }


}
function KeycheckWithDecimal(e)
{
    var _dom = 0;
    _dom=document.all?3:(document.getElementById?1:(document.layers?2:0));
    if(document.all) e=window.event; // for IE
    var ch='';
    var KeyID = '';
    if(_dom==2){                     // for NN4
        if(e.which>0) ch='('+String.fromCharCode(e.which)+')';
        KeyID=e.which;
    }
    else
    {
        if(_dom==3){                   // for IE
            KeyID = (window.event) ? event.keyCode : e.which;
        }
        else {                       // for Mozilla
            if(e.charCode>0) ch='('+String.fromCharCode(e.charCode)+')';
            KeyID=e.charCode;
        }
    }
    if(KeyID == 46)
    {
        return true;
    }
    if((KeyID >= 65 && KeyID <= 90) || (KeyID >= 97 && KeyID <= 122) || (KeyID >= 33 && KeyID <= 47) || (KeyID >= 58 && KeyID <= 64) || (KeyID >= 91 && KeyID <= 96) || (KeyID >= 123 && KeyID <= 126))
    {
        return false;
    }
    return true;
}
function KeycheckOnlyNumeric(e)
{
	
    var _dom = 0;
    _dom=document.all?3:(document.getElementById?1:(document.layers?2:0));
    if(document.all) e=window.event; // for IE
    var ch='';
    var KeyID = '';
    if(_dom==2){                     // for NN4
        if(e.which>0) ch='('+String.fromCharCode(e.which)+')';
        KeyID=e.which;
    }
    else
    {
        if(_dom==3){                   // for IE
            KeyID = (window.event) ? event.keyCode : e.which;
        }
        else {                       // for Mozilla
            if(e.charCode>0) ch='('+String.fromCharCode(e.charCode)+')';
            KeyID=e.charCode;
        }
    }
    if((KeyID >= 65 && KeyID <= 90) || (KeyID >= 97 && KeyID <= 122) || (KeyID >= 33 && KeyID <= 47) || (KeyID >= 58 && KeyID <= 64) || (KeyID >= 91 && KeyID <= 96) || (KeyID >= 123 && KeyID <= 126))
    {
        return false;
    }
    return true;
}

function KeycheckOnlyNumeric_WithEnterKey(e,action)
{
    var enter_pressed = 0;//assume enter not pressed

    var _dom = 0;
    _dom=document.all?3:(document.getElementById?1:(document.layers?2:0));
    if(document.all) e=window.event; // for IE
    var ch='';
    var KeyID = '';
    if(_dom==2){                     // for NN4
        if(e.which>0) ch='('+String.fromCharCode(e.which)+')';
        KeyID=e.which;
    }
    else
    {
        if(_dom==3){                   // for IE
            KeyID = (window.event) ? event.keyCode : e.which;
            if(KeyID==13)
            {
                enter_pressed = 1;
            }
        }
        else {                       // for Mozilla

            if(e.charCode>0) ch='('+String.fromCharCode(e.charCode)+')';
            KeyID=e.charCode;
            var key__for_mozilla =e.keyCode;
            // alert(key_try);

            if(key__for_mozilla==13)
            {
                enter_pressed = 1;
            }
        }

    }
    if(enter_pressed == 1)
    {
        window[action]();
        return false;
    }
    else
    {
        if((KeyID >= 65 && KeyID <= 90) || (KeyID >= 97 && KeyID <= 122) || (KeyID >= 33 && KeyID <= 47) || (KeyID >= 58 && KeyID <= 64) || (KeyID >= 91 && KeyID <= 96) || (KeyID >= 123 && KeyID <= 126))
        {
            return false;
        }
        return true;
    }
}
function KeycheckOnlychar(e)
{
    var _dom = 0;
    _dom=document.all?3:(document.getElementById?1:(document.layers?2:0));
    if(document.all) e=window.event; // for IE
    var ch='';
    var KeyID = '';
    //alert(_dom);
    if(_dom==2){                     // for NN4
        //alert(e.which);
        if(e.which>0) ch='('+String.fromCharCode(e.which)+')';
        KeyID=e.which;
    }
    else
    {
        if(_dom==3){                   // for IE
            KeyID = (window.event) ? event.keyCode : e.which;
        }
        else {                       // for Mozilla
            //alert('Mozilla:' + e.charCode);
            if(e.charCode>0) ch='('+String.fromCharCode(e.charCode)+')';
            KeyID=e.charCode;
        }
    }

    if((KeyID > 47 && KeyID <58) )
    {
        //alert("hello");
        return false;
    }

    return true;
}

/******** Only Numeric **********/
function KeycheckOnlyPhonenumber(e)
{
   
    var _dom = 0;
    _dom=document.all?3:(document.getElementById?1:(document.layers?2:0));
    if(document.all) e=window.event; // for IE
    var ch='';
    var KeyID = '';
    //alert(_dom);
    if(_dom==2){                     // for NN4
        //alert(e.which);
        if(e.which>0) ch='('+String.fromCharCode(e.which)+')';
        KeyID=e.which;
    }
    else
    {
        if(_dom==3){                   // for IE
            KeyID = (window.event) ? event.keyCode : e.which;
        }
        else {                       // for Mozilla
            //alert('Mozilla:' + e.charCode);
            if(e.charCode>0) ch='('+String.fromCharCode(e.charCode)+')';
            KeyID=e.charCode;
        }
    }

    if((KeyID >= 65 && KeyID <= 90) || (KeyID >= 97 && KeyID <= 122) || (KeyID >= 33 && KeyID <= 39) || (KeyID >= 42 && KeyID <= 44) || (KeyID >= 46 && KeyID <= 47) || (KeyID >= 58 && KeyID <= 64) || (KeyID >= 91 && KeyID <= 96) || (KeyID >= 123 && KeyID <= 126))
    {
        //alert("hello");
        return false;
    }
	
    return true;
}


function checkemail(str)
{
    var testresults;
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i

    if (filter.test(str))
        testresults=true
    else
        testresults=false

    return (testresults)
}


function checkall(id)
{
    if(document.getElementById('chkall').checked == true)
    {
        var chkelements = document.getElementsByName(id);

        for(var i = 0; i < chkelements.length; i++)
        {
            chkelements.item(i).checked = true;
        }
    }
    else
    {
        var chkelements = document.getElementsByName(id);

        for(var i = 0; i < chkelements.length; i++)
        {
            chkelements.item(i).checked = false;
        }
    }
}


function onkeydown_search(evt)
{
    var key = (evt.which) ? evt.which : event.keyCode
    if(key==13)
    {
        document.getElementById('search').focus();
    }
}
function onkeydown_go(evt)
{
    var key = (evt.which) ? evt.which : event.keyCode
    if(key==13)
    {
        document.getElementById('goto').focus();
    }
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


function inquiryreplypopup(id)
{
    xmlHttp=GetXmlHttpObject()
	
    if(xmlHttp==null)
    {
        alert("Browser does not support HTTP Request")
        return
    }
	
    // var url="pageposition.php?module=settings&view=modules&eid="+id;
   
    var url="index.php?module=settings&view=modules&task=popup&ajax=Y&eid="+id;


    xmlHttp.onreadystatechange= stateChangeloginpopup
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}

function stateChangeloginpopup()
{
    SetBackground();

    if(xmlHttp.readyState==1)
    {
        ProcessLoader();
    }

    if((xmlHttp.readyState==4||xmlHttp.readyState=="complete")&&(xmlHttp.status==200))
    {
        var popuph = 316;
        var popupw = 360;
        var popuph2 = popuph/2;
        var popupw2 = popupw/2;
        var winW = screen.width;
        var winH = screen.height;

        //alert(xmlHttp.responseText);

        if (parseInt(navigator.appVersion)>3) {

            if (navigator.appName=="Netscape") {
                winW = document.body.offsetWidth;
                winH = document.body.offsetHeight;
            }

            if (navigator.appName.indexOf("Microsoft")!=-1) {
                winW = document.body.clientWidth;
                winH = document.body.offsetHeight;
            }
        }

        var sh = winH;
        var sw = winW;
        var sh2 = sh/2;
        var sw2 = sw/2;
        var topf1 = sh2 - popuph;
        var leftf1 = sw2 - popupw2;

        document.getElementById('dvprocessing').style.display='none';
        document.getElementById('dvregisterfrm').style.display='';
        document.getElementById('dvregisterfrm').style.top=CalculateTop('211')+ "px";
        document.getElementById('dvregisterfrm').style.left=leftf1 + "px";
        document.getElementById("dvregisterfrm").innerHTML=xmlHttp.responseText;
		
    //unhideIframe();
    }
    

}
function UpdateDefault(positionId,tablename, fieldname,intglcode,othertable)
{  
    /*alert(positionId+"PositionId");
  alert(tablename+"tablename");
  alert(fieldname+"fieldname");
  alert(intglcode+"intglcode"); */
  
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null)
    {
        alert ("Your browser does not support XMLHTTP!");
        return;
    }
	
    var path=document.getElementById('tick-'+intglcode).src;
    var file_a= path.substring(path.lastIndexOf("/")+1,path.length);
    var value;
    if(file_a == 'tick.png')
    {
        value = 'N';
    }
    else if(file_a == 'tick_cross.png')
    {
        value = 'Y';
    }
    if(othertable == '')
        var url = "index.php?ajax=Y&positioid="+positionId+"&tablename="+tablename+"&fieldname="+fieldname+"&value="+value+"&id="+intglcode;
    else
        var url = "index.php?ajax=Y&tablename="+tablename+"&fieldname="+fieldname+"&value="+value+"&id="+intglcode+"&othertablename="+othertable;
	
    //  var url = "commanajax.php?method=updatefield&tablename="+tablename+"&fieldname="+fieldname+"&value="+value+"&id="+intglcode;
    //alert(url);
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState==1)
        {
            //ProcessLoader();
            SetBackground();
        }
        if((xmlHttp.readyState==4||xmlHttp.readyState=="complete")&&(xmlHttp.status==200))
        {
            var result = xmlHttp.responseText;
			
            //	alert(document.getElementById('tick-'+intglcode));
			
            if(result == 1)
            {
                if(value == 'Y')
                {
                    document.getElementById('tick-'+positionId).src = 'html/images/tick.png';
                //document.getElementById('star-'+intglcode).onclick = function(){UpdateStar('pst_restaurant','chrstar','N',intglcode);};
                }
                else
                {
                    document.getElementById('tick-'+positionId).src = 'html/images/tick_cross.png';
                //document.getElementById('star-'+intglcode).onclick = function(){UpdateStar('pst_restaurant','chrstar','Y',intglcode);};
                }
            }
            else
            {
                alert("Sorry could not update...");
            }
			
            UnsetBackground();
        /*	document.getElementById('dimmer').style.width=0;
			document.getElementById('dimmer').style.height=0;
			document.getElementById('dimmer').style.visibility="";
			document.getElementById('dvprocessing').style.display = 'none';*/
        }
    };
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function showDiv(e, id1) {
    isMozilla = (document.all) ? 0 : 1;

    obj_float_div = document.getElementById(id1);
    /*if (!isMozilla) {
        obj_float_div_iframe = document.getElementById('fadeboxiframe123');
    }*/


    if (!obj_float_div) return;

    var pos_X = 0, pos_Y = 0;
    if (!e) e = window.event;
    if (e) {
        if (typeof (e.pageX) == 'number') {
            pos_X = e.pageX;pos_Y = e.pageY;
        } else if (typeof (e.clientX) == 'number') {
            pos_X = e.clientX;pos_Y = e.clientY;
            if (document.body && (document.body.scrollTop || document.body.scrollLeft) && !(window.opera || window.debug || navigator.vendor == 'KDE')) {
                pos_X += document.body.scrollLeft;pos_Y += document.body.scrollTop;
            } else if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft) && !(window.opera || window.debug || navigator.vendor == 'KDE')) {
                pos_X += document.documentElement.scrollLeft;pos_Y += document.documentElement.scrollTop;
            }
        }
    }

    var scroll_X = 0, scroll_Y = 0;
    if (document.body && (document.body.scrollTop || document.body.scrollLeft) && !(window.debug || navigator.vendor == 'KDE')) {
        scroll_X = document.body.scrollLeft;scroll_Y = document.body.scrollTop;
    } else if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft) && !(window.debug || navigator.vendor == 'KDE')) {
        scroll_X = document.documentElement.scrollLeft;scroll_Y = document.documentElement.scrollTop;
    }

    var win_size_X = 0, win_size_Y = 0;
    if (window.innerWidth && window.innerHeight) {
        win_size_X = window.innerWidth;win_size_Y = window.innerHeight;
    } else if (document.documentElement && document.documentElement.clientWidth && document.documentElement.clientHeight) {
        win_size_X = document.documentElement.clientWidth;win_size_Y = document.documentElement.clientHeight;
    } else if (document.body && document.body.clientWidth && document.body.clientHeight) {
        win_size_X = document.body.clientWidth;win_size_Y = document.body.clientHeight;
    }



    if (obj_float_div.offsetWidth && obj_float_div.offsetHeight) {
        if (pos_X - scroll_X + obj_float_div.offsetWidth + 5 > win_size_X) pos_X -= (obj_float_div.offsetWidth + 10);
        if (pos_Y - scroll_Y + obj_float_div.offsetHeight + 5 > win_size_Y) pos_Y -= (obj_float_div.offsetHeight + 5);


    }
    document.getElementById(id1).style.display = "block";
    obj_float_div.style.left = pos_X + "px";obj_float_div.style.top = pos_Y + "px";
/* if (!isMozilla) {
        document.getElementById('fadeboxiframe123').style.display = "block";
        obj_float_div_iframe.style.left = pos_X + "px"; obj_float_div_iframe.style.top = pos_Y + "px";
    }*/

}
function hidediv(id2) {
    document.getElementById(id2).style.display = 'none';
    isMozilla = (document.all) ? 0 : 1;
    //obj_float_div = get_obj('divaddshrt');
    obj_float_div = document.getElementById(id2);
/* if (!isMozilla) {
        document.getElementById('fadeboxiframe123').style.display = 'none';
    }*/
}

function SendGridBindRequestTrashmanager(url,targetdiv,action,chkidfordelete,view,tablename)
{
    xmlHttp = GetXmlHttpObject();
    if(xmlHttp != null)
    {
        //alert(xmlHttp.readyState);
        xmlHttp.onreadystatechange = function()
        {
            if(xmlHttp.readyState==1)
            {
                // ProcessLoader();
                SetBackground();
            }
		
            if((xmlHttp.readyState==4||xmlHttp.readyState=="complete")&&(xmlHttp.status==200))
            {
                var str =  xmlHttp.responseText;

                document.getElementById(targetdiv).innerHTML = '';
                document.getElementById(targetdiv).innerHTML = str;

                UnsetBackground();
	
                switch(action)
                {
                    case 'R': // to set the focus on the search text field
                        alert('The record(s) has been succesfully restored');
                        break;
                    case 'D': // to set the focus on the go to page text field on top
                        alert('The record(s) has been succesfully deleted');
                        break;
                }
            }
        };

        var appendurl = '';

        switch(action)
        {
            case 'D': // This is for delete

                var chkelements = document.getElementsByName(chkidfordelete);
                var ids = "";
                var countChecked = 0;
                for(var i = 0; i < chkelements.length; i++)
                {
                    if(chkelements.item(i).checked == true)
                    {
                        countChecked++;
                        if(ids != "")
                            ids += ",";
                        ids += chkelements.item(i).value;
                    }
                }
                if(countChecked == 0)
                {
                    alert("Please select atleast one record for delete.");
                    return false;
                }
                if(!confirm('This will delete the selected records permanent.Are you sure you want to continue?'))
                {
                    return false;
                }
                //alert(ids);
                var totalpagerecords = document.getElementById('ptrecords').value;

                appendurl = '&tablename='+tablename+'&view='+view+'&action=delete&ptotalr='+totalpagerecords+'&dids='+ids;

                break;

            case 'R':

                var chkelements = document.getElementsByName(chkidfordelete);
                var ids = "";
                var countChecked = 0;
                for(var i = 0; i < chkelements.length; i++)
                {
                    if(chkelements.item(i).checked == true)
                    {
                        countChecked++;
                        if(ids != "")
                            ids += ",";
                        ids += chkelements.item(i).value;
                    }
                }
                if(countChecked == 0)
                {
                    alert("Please select atleast one record for restore.");
                    return false;
                }
                if(!confirm('This will restore the selected records.Are you sure you want to continue?'))
                {
                    return false;
                }
                //alert(ids);
                var totalpagerecords = document.getElementById('ptrecords').value;

                appendurl = '&tablename='+tablename+'&view='+view+'&action=restore&ptotalr='+totalpagerecords+'&rids='+ids;

                break;
            
        }
           
        xmlHttp.open('GET', url + '&ajax=Y'+appendurl, true);
        xmlHttp.send(null);
    }
    else
    {
        alert("Your browser does not support HTTP Request");
    }
    return true;
}

function chkObjects(theVal)
{
    if (document.getElementById(theVal) != null)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function checksameemail(emailid,emailid1,emailid2)
{
   
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null)
    {
        alert ("Your browser does not support XMLHTTP!");
        return;
    }

    url="index.php?module=customer&action=validemail&emailid="+emailid+"&emailid1="+emailid1+"&emailid2="+emailid2;

  
    xmlHttp.open("GET",url,false);
    xmlHttp.send(null);

    return trim(xmlHttp.responseText);
}

function prodata(id)
{
    xmlHttp = GetXmlHttpObject();

    if(xmlHttp != null)
    {
		

        xmlHttp.onreadystatechange = function()
        {
            if((xmlHttp.readyState==4||xmlHttp.readyState=="complete")&&(xmlHttp.status==200))
            {
                var str=xmlHttp.responseText;

                document.getElementById('abcd').innerHTML = '';
                document.getElementById('abcd').innerHTML = str;


            }
        };

        url='index.php?module=whatsnew&action=categorydata&catid='+id;
        xmlHttp.open('GET', url + '&ajax=Y', true);
        xmlHttp.send(null);
    }
    else
    {
        alert("Your browser does not support HTTP Request");
    }
    return true;
}
function videogallery_update(id)
{
    xmlHttp = GetXmlHttpObject();

    if(xmlHttp != null)
    {
        var textvalue=document.getElementById('var_title_'+id).value;

        xmlHttp.onreadystatechange = function()
        {
            if((xmlHttp.readyState==4||xmlHttp.readyState=="complete")&&(xmlHttp.status==200))
            {
                var str=xmlHttp.responseText;

                document.getElementById('gridbody').innerHTML = '';
                document.getElementById('gridbody').innerHTML = str;

                alert("Records updated successfully.");
            }
        };

        url='index.php?module=videogallery&action=edit&title='+textvalue+'&id='+id;
        xmlHttp.open('GET', url + '&ajax=Y', true);
        xmlHttp.send(null);
    }
    else
    {
        alert("Your browser does not support HTTP Request");
    }
    return true;

}


function getzipdatausr(id,file,bidtitle)
{
    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: "ajax=Y&menudata=Y&module=bidlist&reqpopup=Y&bidid="+id+"&bidfile="+file+"&bidtitle="+bidtitle,
        async: false,
		start:openpopuploader(),
        success: function(data)
        {
            var str = jQuery.trim(data);
            closeDashBoardDiv('Bidlist');
            $('#middlepopup').fadeIn();
            $('#middlepopup').html(str);
			closepopuploader();
            return false;
        }
    });
   
}

function sendmail_zip()
{
	
    if(trim(document.getElementById('name').value) == "")
    {
        alert("Please enter name.");
        document.getElementById('name').focus();
        return false;
    }
    else if(document.getElementById('email').value == "")
    {
        alert("Please enter email address.");
        document.getElementById('email').focus();
        return false;
    }
    if(!checkemail(document.getElementById('email').value))
    {
        alert("Please enter valid email address");
        document.getElementById('email').focus();
        return false;
    }
    else if(trim(document.getElementById('var_companyname').value) == "")
    {
        alert("Please enter company name.");
        document.getElementById('var_companyname').focus();
        return false;
    }	
    else if(trim(document.getElementById('code').value) == 'Enter the code' || trim(document.getElementById('code').value) == '')
    {
        alert("Please enter code.");
        document.getElementById('code').focus();
        return false;
    }
    else if(trim(document.getElementById('code').value) != trim(document.getElementById('eyncode').value))
    {
        alert("You have entered wrong code..Please try again!");
        document.getElementById('code').focus();
        return false;
    }


    var name = document.getElementById('name').value;
    var email = document.getElementById('email').value;
    var company = document.getElementById('var_companyname').value;
    var phone = document.getElementById('phone').value;
    var message = document.getElementById('message').value;
    var bidid = document.getElementById('bidcode').value;
	var bidfile = document.getElementById('bidfile').value;

   $.ajax({
        type: "POST",
        url:"index.php" ,
        data: "module=pages&ajax=N&task=bidlistmail&name="+name+"&email="+email+"&var_companyname="+company+"&phone="+phone+"&message="+message+"&bidid="+bidid,
        async: true,
		start:openpopuploader(),
        success: function(data)
        {
            var str = jQuery.trim(data);
            closepopuploader();
			closeDashBoardDiv('Reqpopup');
			
	  
		window.parent.location='download.php?f=powerpanel/modules/bidlist/html/uploads/bidfile/'+bidfile;	
    
        }
    });

	return false;
}

function openpopuploader()
{
	document.getElementById('backgroundPopup').style.display='block';
    var w = $(window).width();
    var h = $(window).height();
    
    document.getElementById('loader').style.display='block';
    document.getElementById('loader').style.left= w/2 + "px";
    document.getElementById('loader').style.top= h/2 + "px";
}

function closepopuploader()
{
	document.getElementById('loader').style.display='none';
    document.getElementById('backgroundPopup').style.display='none';
}


function photogallery_update(param,id)
{
    //alert(id);
    
    xmlHttp = GetXmlHttpObject();
    
    if(xmlHttp != null)
    {
        var textvalue=document.getElementById('var_title_'+id).value;

        xmlHttp.onreadystatechange = function()
        {
            if((xmlHttp.readyState==4||xmlHttp.readyState=="complete")&&(xmlHttp.status==200))
            {
                var str=xmlHttp.responseText;

                document.getElementById('gridbody').innerHTML = '';
                document.getElementById('gridbody').innerHTML = str;
                                
                alert("Records updated successfully.");
            }
        };
                
        url=param+'&action=edit&title='+textvalue+'&id='+id;
        
        xmlHttp.open('GET', url + '&ajax=Y', true);
        xmlHttp.send(null);
    }
    else
    {
        alert("Your browser does not support HTTP Request");
    }
    return true;
    
}

function login()
{
    if(trim(document.getElementById('username').value) == "" || document.getElementById('username').value == "User Id")
    {
        alert("Please enter username.");
        document.getElementById('username').focus();
        return false;
    }
    if(!checkemail(document.getElementById('username').value))
    {
        alert("Please enter valid email address");
        document.getElementById('username').focus();
        return false;
    }
    if(trim(document.getElementById('password').value) == "" || document.getElementById('password').value == "Password")
    {
        alert("Please enter password.");
        document.getElementById('password').focus();
        return false;
    }
			
    var name = document.getElementById('username').value;
    var email = document.getElementById('password').value;
		
    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: "module=login&ajax=Y&task=loginuser&name="+name+"&email="+email,
        async: false,
        success: function(data)
        {
            var str = jQuery.trim(data);

            if(trim(str)=='1')
            {
                alert('Invalid User Id or Password.');
                document.getElementById('password').focus();
            }
            else
            {
                var data_array=str.split('*@#$*');
				document.getElementById('user-name').innerHTML = "Welcome, <strong>"+data_array[0]+"</strong>";
				$('#ContainerMiddleNav').html(data_array[1]);
                anylinkcssmenu.init("anchorclass");
            }
        }
    });
	
    return false;
}

function getchangeprofile(uid)
{
    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: "module=changeprofile&ajax=Y&uid="+uid,
        async: false,
		start:openpopuploader(),
        success: function(data)
        {
            var str = trim(data);
			closepopuploader();
            $('#middlepopup').fadeIn();
            $('#middlepopup').html(str);
        }
    });
    return false;
}

function getcalendardata()
{
    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: "module=calendar&ajax=Y",
        async: false,
		start:openpopuploader(),
        success: function(data)
        {
			//alert(data);
            var str = trim(data);
			closepopuploader();
            $('#middlepopup').fadeIn();
            $('#middlepopup').html(str);
        }
    });
	
    return false;
}

function geteventdata(eventid)
{
    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: "module=calendar&ajax=Y&event=Y&evid="+eventid,
        async: false,
		start:openpopuploader(),
        success: function(data)
        {
			//alert(data);
            var str = trim(data);
			closepopuploader();
            $('#middlepopup').fadeIn();
            $('#middlepopup').html(str);
        }
    });
	
    return false;
}

function geteventlisting(date)
{
    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: "module=calendar&ajax=Y&eventlisting=Y&date="+date,
        async: false,
		start:openpopuploader(),
        success: function(data)
        {
			//alert(data);
            var str = trim(data);
			closepopuploader();
            $('#middlepopup').fadeIn();
            $('#middlepopup').html(str);
        }
    });
	
    return false;
}

function getCal()
{
	var y = document.getElementById('cmbYear').value;
	var m = document.getElementById('cmbMonth').value;
	
    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: "module=calendar&m="+m+"&y="+y,
        async: false,
		start:openpopuploader(),
        success: function(data)
        {
			//alert(data);
            var str = trim(data);
			closepopuploader();
            $('#middlepopup').fadeIn();
            $('#middlepopup').html(str);
        }
    });
	
    return false;
}

function getnextprevcaldata(urldata)
{
    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: urldata,
        async: false,
		start:openpopuploader(),
        success: function(data)
        {
			//alert(data);
            var str = trim(data);
			closepopuploader();
            $('#middlepopup').fadeIn();
            $('#middlepopup').html(str);
        }
    });
	
    return false;
}

function getticket(uid)
{
    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: "module=ticket&ajax=Y&uid="+uid,
        async: false,
		start:openpopuploader(),
        success: function(data)
        {
            var str = trim(data);
			closepopuploader();
            $('#middlepopup').fadeIn();
            $('#middlepopup').html(str);
        }
    });
	
    return false;
}

function getticketmsgdata(id)
{
    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: "module=ticket&task=ticketdetail&ajax=Y&tid="+id,
        async: false,
		start:openpopuploader(),
        success: function(data)
        {
			closepopuploader();
            var str = trim(data);
            $('#middlepopup').html(str);
        }
    });
    return false;
}

function getticketadd()
{
    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: "module=ticket&task=addticket&ajax=Y",
        async: false,
		start:openpopuploader(),
        success: function(data)
        {
			closepopuploader();
            var str = trim(data);
            $('#middlepopup').html(str);
        }
    });
    return false;
}


function ticketcls()
{
    var s=confirm("This ticket will close. Are you sure you want to continue?");
    if (s==true)
    {
        var projectid = document.getElementById('pid').value;
		var msg = trim(document.getElementById('var_message').value);
		//alert(projectid);
        $.ajax({
            type: "POST",
            url:"index.php" ,
            data: "module=pages&ajax=N&task=closeticket&proid="+projectid+"&var_message="+msg,
            async: true,
			start:openpopuploader(),
            success: function(data)
            {
                var str = jQuery.trim(data);
				alert("Ticket has been closed.");
				closeDashBoardDiv('ticketdetail');
				closepopuploader();
                
            }
        });
		return false;
    }
    else
	{
    	document.getElementById('var_message').focus();
        return false;
    }
}

function ticketpopupclose()
{
    var s=confirm("This will close the ticket.Are you sure you want to continue?");
    if (s==true)
    {
		closeDashBoardDiv('ticketdetail');
	}
}

function sendticketdata()
{

    if(trim(document.getElementById('var_message').value) == "")
    {
        alert("Please enter message.");
        document.getElementById('var_message').value='';
        document.getElementById('var_message').focus();
        return false;
    }

    var message = document.getElementById('var_message').value;
    var projectid = document.getElementById('pid').value;
		
    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: "module=pages&ajax=N&task=ticketmsgmail&var_message="+message+"&proid="+projectid,
        async: true,
		start:openpopuploader(),
        success: function(data)
        {
            var str = jQuery.trim(data);
            
            alert('Your mail has been sent successfully.');
            closepopuploader();
			closeDashBoardDiv('ticketdetail');
			
        }
    });
	return false;
}

function sendticketadd()
{
    if(document.getElementById('fk_projectglcode').value == 0)
    {
        alert("Please select project.");
        document.getElementById('fk_projectglcode').focus();
        return false;
    }
    else if(trim(document.getElementById('var_subject').value) == "")
    {
        alert("Please enter subject.");
        document.getElementById('var_subject').value='';
        document.getElementById('var_subject').focus();
        return false;
    }
   else if(trim(document.getElementById('var_message').value) == "")
    {
        alert("Please enter message.");
        document.getElementById('var_message').value='';
        document.getElementById('var_message').focus();
        return false;
    }

    var project = document.getElementById('fk_projectglcode').value;
    var subject = document.getElementById('var_subject').value;
    var message = document.getElementById('var_message').value;

    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: "module=pages&ajax=N&task=mailticketadd&fk_projectglcode="+project+"&var_subject="+subject+"&var_message="+message,
        async: false,
		start:openpopuploader(),
        success: function(data)
        {
            var str = jQuery.trim(data);
           
            alert('Your ticket has been successfully submitted.');
			closepopuploader();
            return false;
        }
    });
}
function getprivacydata()
{
    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: "module=cms-Privacypolicy&ajax=Y",
        async: false,
		start:openpopuploader(),
        success: function(data)
        {
            var str = jQuery.trim(data);
            //alert(str);
            //alert(document.getElementById('middlepopup').value);
			closepopuploader();
            $('#middlepopup').fadeIn();
            $('#middlepopup').html(str);
            //document.getElementById('middlepopup').innerHTML = str;
            //document.getElementById('centerpopup').innerHTML = str;
            //alert('Your are successfully login.');
            return false;
        }
    });
	
}
function getarticle(id)
{
    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: "module=whatsnew&view=article&id="+id+"&ajax=Y",
        async: false,
		start:openpopuploader(),
        success: function(data)
        {
            var str = jQuery.trim(data);
            closepopuploader();
            $('#middlepopup').fadeIn();
            $('#middlepopup').html(str);
            return false;
        }
    });
}
function getsitemapdata()
{
    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: "module=cms-Sitemap&ajax=Y&menudata=Sitemap",
        async: false,
		start:openpopuploader(),
        success: function(data)
        {
            var str = jQuery.trim(data);
									
            //document.getElementById('LoginDiv').style.display='none';
			closepopuploader();
            $('#middlepopup').fadeIn();
            $('#middlepopup').html(str);
            //document.getElementById('middlepopup').innerHTML = str;
            //alert('Your are successfully login.');
            return false;
        }
    });
	
}

function checkValid(eid)
{
    if(trim(document.getElementById('fname').value) == "" )
    {
        alert("Please enter first name.");
        document.getElementById('fname').focus();
        return false;
    }
    else if(trim(document.getElementById('lname').value) == "" )
    {
        alert("Please enter last name.");
        document.getElementById('lname').focus();
        return false;
    }
    else if(trim(document.getElementById('email').value) == "" )
    {
        alert("Please enter email.");
        document.getElementById('email').focus();
        return false;
    }
    if(!checkemail(document.getElementById('email').value))
    {
        alert("Please enter valid email address");
        document.getElementById('email').focus();
        return false;
    }
    if(trim(document.getElementById('npass').value) != trim(document.getElementById('cpass').value))
    {
        alert("Please enter valid password.");
        document.getElementById('npass').focus();
        return false;
    }
		
    var fname = document.getElementById('fname').value;
    var lname = document.getElementById('lname').value;
    var email = document.getElementById('email').value;
    var phone = document.getElementById('phone').value;;
    var npass = document.getElementById('npass').value;
    var cpass = document.getElementById('cpass').value;
	
		
    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: "module=changeprofile&ajax=Y&task=insert&eid="+eid+"&fname="+fname+"&lname="+lname+"&email="+email+"&npass="+npass+"&cpass="+cpass+"&phone="+phone,
        async: true,
        start:openpopuploader(),
        success: function(data)
        {
            var str = jQuery.trim(data);
			alert('Your Profile has been changed successfully');
            closepopuploader();
        }
    });
	
    return false;
}

function forgotpass()
{
    document.getElementById('loginfield').style.display='none';
    document.getElementById('forgot').style.display='';
}
function forgotpassword()
{
	
    if(trim(document.getElementById('foruser').value) == "" || trim(document.getElementById('foruser').value) =="User Id" )
    {
        alert("Please Enter User Id.");
        document.getElementById('foruser').focus();
        return false;
    }
    if(!checkemail(document.getElementById('foruser').value))
    {
        alert("Please Enter Valid User Id.");
        document.getElementById('foruser').focus();
        return false;
    }
	
    var username = document.getElementById('foruser').value;
	
    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: "module=changeprofile&ajax=Y&task=forgotpass&username="+username,
        async: true,
        start:document.getElementById('backgroundPopup').style.display='block',
        success: function(data)
        {
            var str = jQuery.trim(data);
            if(trim(str)=='0')
            {
                alert("Login detail sent successfully to your email id.");
                logoutmodule('login','LoginDiv','logintab');
                document.getElementById('username').focus();
            }
            else if(trim(str)=='2')
            {
                alert("Error in sending mail, please try again.");
                forgotpass();
                document.getElementById('foruser').focus();
            }
            else
            {
                alert("You have entered wrong email id, please try again.");
                forgotpass();
                document.getElementById('foruser').focus();
            }
            document.getElementById('backgroundPopup').style.display='none';
        }
    });
	
    return false;
}
function sendmail()
{
		
    if(trim(document.getElementById('name').value) == "")
    {
        alert("Please enter name.");
        document.getElementById('name').focus();
        return false;
    }
       
    else if(document.getElementById('email').value == "")
    {
        alert("Please enter email address.");
        document.getElementById('email').focus();
        return false;
    }
    if(!checkemail(document.getElementById('email').value))
    {
        alert("Please enter valid email address");
        document.getElementById('email').focus();
        return false;
    }
    else if(trim(document.getElementById('code').value) == 'Enter the code' || trim(document.getElementById('code').value) == '')
    {
        alert("Please enter code.");
        document.getElementById('code').focus();
        return false;
    }
    else if(trim(document.getElementById('code').value) != trim(document.getElementById('eyncode').value))
    {
        alert("You have entered wrong code..Please try again!");
        document.getElementById('code').focus();
        return false;
    }
	
    var name = document.getElementById('name').value;
    var email = document.getElementById('email').value;
    var phone = document.getElementById('phone').value;
    var message = document.getElementById('message').value;
	
    $.ajax({
        type: "POST",
        url:"index.php" ,
        data: "module=pages&ajax=N&task=mailsend&name="+name+"&email="+email+"&phone="+phone+"&message="+message,
        async: true,
        start:openpopuploader(),
        success: function(data)
        {
			str =data.split("@@@"); 
            alert('Thank You for contacting to KM LIMITED. We will get back to your request very soon.');
			document.getElementById('pinimage').innerHTML=str[2];
			document.getElementById('eyncode').value=str[1];
            document.contactform.reset();
            closepopuploader();
        }
    });
    return false;
}

function logout(module,divid,divtab)
{
    var response;
    $.ajax({
        type: "GET",
        url:"index.php" ,
        data: "ajax=Y&menudata=Y&task=logout&module="+module+"&divtab="+divtab,
        async: false,
		start:openpopuploader(),
        success: function(data)
        {
			
			closepopuploader();
            document.getElementById('user-name').innerHTML='';
			document.getElementById('ContainerMiddleNav').innerHTML=data;
			document.getElementById('middlepopup').style.display = 'none';
        }
    });
}

function getcusproject(cid)
{
    var response;
    $.ajax({
        type: "GET",
        url:"index.php" ,
        data: "ajax=Y&menudata=Y&task=listing&module=cusproject&cid="+cid,
        async: false,
		start:openpopuploader(),
        success: function(data)
        {
			closepopuploader();
            $('#middlepopup').fadeIn();
            $('#middlepopup').html(data);

        }
    });
}

function getcusprojectdetail(pid)
{
    var response;
    $.ajax({
        type: "GET",
        url:"index.php" ,
        data: "ajax=Y&menudata=Y&task=detail&module=cusproject&pid="+pid,
        async: false,
		start:openpopuploader(),
        success: function(data)
        {
			closepopuploader();
            document.getElementById('middlepopup').innerHTML=data;
			var n = $("#content").height();
			$("#content").height(n-180);
			//Galleria.loadTheme('<?php echo $configObj->themePath?>js/galleria.classic.js');
			$('#galleria').galleria();
        }
    });
}

function getcusallproject(vid)
{
    var response;
    $.ajax({
        type: "GET",
        url:"index.php" ,
        data: "ajax=Y&menudata=Y&task=photo&module=cusproject&vid="+vid,
        async: false,
		start:openpopuploader(),
        success: function(data)
        {
            document.getElementById('middlepopup').innerHTML=data;
			closepopuploader();
        }
    });
}
