// JavaScript Document

function getHTTPObject()
{
  var xmlHttp;
  try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {
    // Internet Explorer
    try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");		
    }
    catch (e)
    {
      try
      {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
        alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }
  return xmlHttp;
}


function draw_query_string(form)

{



	var args = new Array();  

	var ele = form.elements;	  

    for (var i=0; i<ele.length; i++) 

    {		

      if (!ele[i].name) 

      continue;      

	  if (ele[i].tagname = 'input' && (ele[i].type == 'checkbox' || ele[i].type == 'radio') && !ele[i].checked) 

	  continue;

                            

          if (ele[i].tagname = 'select' && ele[i].multiple) 

          {

              for (j=0; j<ele[i].options.length; j++) 

              {

                  if (ele[i].options[j].selected)

                  args.push(ele[i].name + "=" + encodeURIComponent(ele[i].options[j].value));

              }

          } 

          else 

          {

              args.push(ele[i].name + "=" + encodeURIComponent(ele[i].value));

          }

      }			        

    postVars = args.join("&");

   //alert(postVars);

   return postVars;    

}



// function to show city or zipcode dropdown on selecting state or city.

function find_city(a,spid,list,val,valtype)

{



	var xmlHTTP = getHTTPObject();

	var url = "login_ajax.php";

	myRand=parseInt(Math.random()*99999999);  // cache buster

	var str = '';

	str = "&state="+a+"&list="+list+"&val="+val+"&valtype="+valtype;

	str += "&randNum="+myRand;

	

	xmlHTTP.onreadystatechange=function()

	{

		if (xmlHTTP.readyState==4)

		{

			object = xmlHTTP.responseText;			

			try

			{

				document.getElementById(spid).innerHTML = object;

			}

			catch(ex)

			{

				document.getElementById(spid).value = object;

			}			

		}

	}				

	xmlHTTP.open("POST",url,true);					

	xmlHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 				

	xmlHTTP.send(str);	

}





function check_email(email_val)

{

	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;

	return reg2.test(email_val);

}



//this function will compare two dates

			

function compare_date(date1,date2)

{

	var val1 = date1.split("/");

	var val2 = date2.split("/");

	var d1 = new Date();

	d1.setFullYear(val1[2],(val1[0]-1),val1[1]);

	

	var d2 = new Date();

	d2.setFullYear(val2[2],(val2[0]-1),val2[1]);

	

	if(d1 > d2)

	{

		return false;

	}

	else

	{

		return true;

	}

}



function validate_date(date_val)

{

	var val = date_val.split("/");

	var msg = '';

	if((val[0] == 4 || val[0]==6 || val[0]==9 || val[0]==11) && val[1] > 30)

	{

		msg ="invalid number of days in "+val[0]+" month,not greater than 30";

	}

	else if(val[0] == 2 && val[1] > check_leapYear(val[2]))

	{

		msg ="invalid number of days in "+val[0]+" month,not greater than "+check_leapYear(val[2]);

	}

	

	return msg;

}



//this function will comapre two times in HH:MM format



function compare_time(time1,time2)

{

	var val1 = time1.split(":");

	var val2 = time2.split(":");

	if(val1[0] > val2[0])

	{

		return false;

	}

	else if((val1[0] == val2[0])&& (val1[1] > val2[1]))

	{

		return false;

	}

	else

	{

		return true;

	}

}



//this function will check given year is leap year



function check_leapYear(datea)

{

	datea = parseInt(datea);



	if(datea%4 == 0)

	{

		if(datea%100 != 0)

		{

			return 29;

		}

		else

		{

			if(datea%400 == 0)

				return 29;

			else

				return 28;

		}

	}

	return 28;

}



function hasWhiteSpace(s)

{

	var msg = "";

	reWhiteSpace = new RegExp(/^\s+$/);

	if(reWhiteSpace.test(s))

	{

		return true;

	}

	else

	{

		return false;

	}

		

}

			