﻿// JScript File

//Global XMLHTTP Request object
  //stdlabel.innerText="loading pleasewait...";
var XmlHttp;

//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp()
{
	//Creating object of XMLHTTP in IE
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;
		}
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
	}
}

function dropdownonchange(element1,element2,element3,action) 
{
    
    var sourse = document.getElementById(element1);
    var target = document.getElementById(element2);
    var nexttarget = document.getElementById(element3);
    var selectedcatogory = sourse.options[sourse.selectedIndex].value;
//    if(action=="statechange")
//    {
//      setareacodes(selectedcatogory);
//    }
    //clear next target if exist
    if(nexttarget!=null)
    {
        try
        {
	        for (var count = nexttarget.options.length-1; count >-1; count--)
	        {
		        nexttarget.options[count] = null;
	        }
	        var textValue; 
	        var optionItem;
	        optionItem = new Option( "Select One",0,  false, false);
	        nexttarget.options[nexttarget.length] = optionItem;
	    }catch(es)
	    {
	    }
	}
	//Getting the selected country from country combo box.
	var requestUrl = "newajaxserver.aspx?action="+action+"&val=" + encodeURIComponent(selectedcatogory);
	CreateXmlHttp();
	// If browser supports XMLHTTPRequest object 
	if(XmlHttp)
	{
		//Setting the event handler for the response
		    XmlHttp.onreadystatechange =function(){
		    if(XmlHttp.readyState == 4)
	        {
		        // To make sure valid response is received from the server, 200 means response received is OK
		        if(XmlHttp.status == 200)
		        {		
			       ClearAndSetstates(XmlHttp.responseText,target);
		        }
		        else
		        {
			        alert("There was a problem retrieving data from the server." );
		        }
	        }
		
		}
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		//Sends the request to server
		XmlHttp.send(null);	
		
	}
	
}
///general output
function ClearAndSetstates(statenodes,target)
{
   //alert("abdu");
    try
    {
	 //Clears the state combo box contents.
	    for (var count = target.options.length-1; count >-1; count--)
	    {
		    target.options[count] = null;
	    }
        var sd= statenodes.split(",");
	    var textValue; 
	    var optionItem;
	    optionItem = new Option( "Select One",0,  false, false);
	    target.options[target.length] = optionItem;
        for(i=0;i<sd.length-1;i++)
        {
            optionItem = new Option( sd[i++],sd[i],  false, false);
		    target.options[target.length] = optionItem;
        }
	}catch(ess)
	{
	}
}
//////////////drpdown changeing actions

function setareacodesto(value)
{
    var nexttarget = document.getElementById(value);
    var selectedcatogory = nexttarget.options[nexttarget.selectedIndex].value;
    var requestUrl = "newajaxserver.aspx?action=loadareacode&val="+selectedcatogory;
	CreateXmlHttp();
	// If browser supports XMLHTTPRequest object 
	if(XmlHttp)
	{
	        // alert("xmlhttp");
		   //Setting the event handler for the response
		    XmlHttp.onreadystatechange =function(){
		    if(XmlHttp.readyState == 4)
	        {
	            //alert("redystate change");
		        // To make sure valid response is received from the server, 200 means response received is OK
		        if(XmlHttp.status == 200)
		        {		
			       Clearandloadareacode(XmlHttp.responseText);
		        }
		        else
		        {
			        alert("There was a problem retrieving data from the server." );
		        }
	        }
		
		}
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		//Sends the request to server
		XmlHttp.send(null);		
	}
}


function Clearandloadareacode(datas)
{
   //alert(datas);
   //alert("abdu");
   var target=document.getElementById("drpareacode");
   try
    {
	 //Clears the state combo box contents.
	    for (var count = target.options.length-1; count >-1; count--)
	    {
		    target.options[count] = null;
	    }
        var sd= datas.split(",");
	    var textValue; 
	    var optionItem;
	    optionItem = new Option( "Select One",0,  false, false);
	    target.options[target.length] = optionItem;
        for(i=0;i<sd.length-1;i++)
        {
            optionItem = new Option( sd[i++],sd[i],  false, false);
		    target.options[target.length] = optionItem;
        }
	}catch(ess)
	{
	}
 
}
function loadcountrycode(element)
{
  var myindex  = element.selectedIndex
  var target=document.getElementById("isdcode");
   var target1=document.getElementById("isdmobilecode");
  target.options[myindex-1].selected=true;
  target1.options[myindex-1].selected=true;
}
 function CheckAll(element1, element2)
 {
     var ctrl1=document.getElementById(element1);
     var ctrl2=document.getElementById(element2);
     if(ctrl2.value=="Select All")
     {
          ctrl2.value="Clear";
          for(var i=0; i<ctrl1.rows.length; i++) 
          {     
           if(ctrl1.rows[i].cells[0].childNodes[0].type=='checkbox') 
           {
             ctrl1.rows[i].cells[0].childNodes[0].checked=true;
           }
          }
      }
      else
      {
          ctrl2.value="Select All";
          for(var i=0; i<ctrl1.rows.length; i++) 
          {     
           if(ctrl1.rows[i].cells[0].childNodes[0].type=='checkbox') 
           {
             ctrl1.rows[i].cells[0].childNodes[0].checked=false;
           }
          }
      }
      return false;
  }
  
  function ActivateConfirm(element1)
  {
   var ctrlgrid=document.getElementById(element1);
      for(var i=0; i<ctrlgrid.rows.length; i++) 
      {     
        if(ctrlgrid.rows[i].cells[0].childNodes[0].type=='checkbox') 
        {
            if(ctrlgrid.rows[i].cells[0].childNodes[0].checked==true)
            {
             if( window.confirm("Are you Confirm?"))
              return true;
             else
              return false;
            }
        }
      }
      alert("please select items ");
       return false;
   
  }
  
  function DeleteConfirm(element1)
  {
      var ctrlgrid=document.getElementById(element1);
      for(var i=0; i<ctrlgrid.rows.length; i++) 
      {     
        if(ctrlgrid.rows[i].cells[0].childNodes[0].type=='checkbox') 
        {
            if(ctrlgrid.rows[i].cells[0].childNodes[0].checked==true)
            {
             if( window.confirm("Do you want to Delete these items???"))
              return true;
             else
              return false;
            }
        }
      }
      alert("please select items to delete");
       return false;
  }
 function ShowControl(element1)
 {    
      var ctrlgrid=document.getElementById(element1);
       
         ctrlgrid.style.visibility="visible"; 
         return false;
 }
 function Hide(element1)
 {
    var ctrlgrid=document.getElementById(element1);
         ctrlgrid.style.visibility="hidden"; 
         return false;
 }
 function HideAllControls()
 {
 //alert("hi");drpsection
      var ctrlgrid=document.getElementById("drpstate");
       //ctrlgrid.style.visibility="hidden"; 
      ctrlgrid.disabled = true
      ctrlgrid=document.getElementById("drpdistrict");
       //ctrlgrid.style.visibility="hidden"; 
        ctrlgrid.disabled = true
        ctrlgrid=document.getElementById("drpsection");
         ctrlgrid.disabled = true
          ctrlgrid=document.getElementById("drpsubcatogory");
         ctrlgrid.disabled = true
         return false;
 }
 function CheckAllProduct(element1, element2)
 {
     var ctrl1=document.getElementById(element1);
     var ctrl2=document.getElementById(element2);
     if(ctrl2.checked==true)
     {    
          for(var i=0; i<ctrl1.rows.length; i++) 
          {   
           try{  
               if(ctrl1.rows[i].cells[0].childNodes[0].type=='checkbox') 
               {
                 ctrl1.rows[i].cells[0].childNodes[0].checked=true;
               } 
              }catch(err){}
          }
           return true;
      }
      else
      {
          for(var i=0; i<ctrl1.rows.length; i++) 
          {   
          try{    
               if(ctrl1.rows[i].cells[0].childNodes[0].type=='checkbox') 
               {
                 ctrl1.rows[i].cells[0].childNodes[0].checked=false;
               }
            }catch(err){}
          }
          return true;
      }
      
  }
  function DeleteConfirm(element1)
  {
      var ctrlgrid=document.getElementById(element1);
      for(var i=0; i<ctrlgrid.rows.length; i++) 
      {   
      
        try{    
            if(ctrlgrid.rows[i].cells[0].childNodes[0].type=='checkbox') 
            {
                if(ctrlgrid.rows[i].cells[0].childNodes[0].checked==true)
                {
                 if( window.confirm("Do you want to Delete these items"))
                  return true;
                 else
                  return false;
                }
            }
         }catch(err){}
      }
      alert("please select items to delete");
       return false;
  }
//   function Checkall(element) 
//{ 
//   var the_form = window.document.forms[0]; 
//  
//   if(element.value=="Select All")
//    { 
//      for(var i=0; i<the_form.length; i++) 
//      { 
//       var temp = the_form.elements[i].type; 
//       if(temp== "checkbox") 
//       {
//         the_form.elements[i].checked=true;
//       }
//      }
//      element.value="ClearAll" 
//     return false;
//   }
//   else
//   {
//     element.value="Select All" 
//      for(var i=0; i<the_form.length; i++) 
//      { 
//       var temp = the_form.elements[i].type; 
//       if(temp== "checkbox") 
//       {
//         the_form.elements[i].checked=false;
//       }
//     }
//     return false;
//   }
//}
//  function CheckCheckbox()
//  {
//    var the_form = window.document.forms[0]; 
//    for(var i=0; i<the_form.length; i++) 
//      { 
//       var temp = the_form.elements[i].type; 
//       if(temp== "checkbox") 
//       {
//          if(the_form.elements[i].checked==true)
//            return true;
//       }
//     }
//     alert("Please Select Items ");
//     return false;
//  }
//  function Confirmation(element)
//   {
//    if(CheckCheckbox())
//    {
//      if(element.value=="Delete")
//      {
//      if(window.confirm("Do you want to Delete these items"))
//       return true;
//       else
//       return false;
//      }
//      if(element.value=="Activate")
//      {
//      if(window.confirm("Do you want to Activate these items"))
//       return true;
//       else
//       return false;
//      }
//      if(element.value=="Deactivate")
//      {
//      if(window.confirm("Do you want to Deactivate these items"))
//       return true;
//       else
//       return false;
//      }
//     }
//     else
//      return false;
//  }
function Checkemailtodb(mytextbox,mylabel)
{
     var txtemail = document.getElementById(mytextbox);
     var targetlabel = document.getElementById(mylabel);
     CreateXmlHttp();
     var requestUrl = "newajaxserver.aspx?action=checkmailtodb&val=" + encodeURIComponent(txtemail.value);
     CreateXmlHttp();
     if(XmlHttp)
	 {
		//Setting the event handler for the response
		    XmlHttp.onreadystatechange =function(){
		    if(XmlHttp.readyState == 4)
	        {
		        // To make sure valid response is received from the server, 200 means response received is OK
		        if(XmlHttp.status == 200)
		        {		
			       Setresponsetext(XmlHttp.responseText,targetlabel,txtemail);
		        }
		        else
		        {
			        alert("There was a problem retrieving data from the server." );
		        }
	        }
		
		}
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		//Sends the request to server
		XmlHttp.send(null);		
	}
  
}

function Setresponsetext(displayresult,targetlabel,txtemail)
{
   if(displayresult=="1")// email already in the database
   {
     targetlabel.innerText="This emailid already registerd with us. please choose another";
     txtemail.value="";
   }
   else
   {
    targetlabel.innerText="";
   }
}


function Checkavailability()
{
	var txtuser = document.getElementById("username");
	//alert(txtuser.value);
    var requestUrl = "newajaxserver.aspx?action=checkavailability&val=" + encodeURIComponent(txtuser.value);
	//var requestUrl = "checkavailability.aspx?username=" + encodeURIComponent(txtuser.value);
	CreateXmlHttp();
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleResponsetocheckavailability;
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		//Sends the request to server
		XmlHttp.send(null);		
	}
  
}
//Called when response comes back from server
function HandleResponsetocheckavailability()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{		
			//ClearAndSetStateListItems(XmlHttp.responseText);
			DisplayResulttocheckavailability(XmlHttp.responseText);
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}

///////////////////
function DisplayResulttocheckavailability(displayresult)
{
    var result = document.getElementById("availabilitydisplay");
   result.innerText=displayresult;
}
// JScript File

