
function validateField(fld){
        if( fld.value.length == 0 || fld.value == "-" || fld.value == "" ){
        fld.focus();
        return false;
        }else {
       return true;
        }
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var tfld = trim(fld.value);                       
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;

    if (fld.value == "") {
        fld.focus();
        return false;
    } else if (!emailFilter.test(tfld)) {
        fld.focus();
        return false;
    } else if (fld.value.match(illegalChars)) {
        fld.focus();
        return false;
    } else {
       return true;
    }
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}
function checkPage()
{
	page=getCookie('page');
	if(page != null && page != "")
	 {
		
		window.location="http://www.esad.org.bd";
		getContent(page);
	 }
	else
	{
	window.location="http://www.esad.org.bd";
	}
}

function PostQuery()
{
var oRequest;
var params = "content=" + document.getElementById("content").value + "&search_year=" + document.getElementById("search_year").value;

try {
        oRequest=new XMLHttpRequest();
     } catch (e)   {
     try {
          oRequest=new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e) {
          try {
              oRequest=new ActiveXObject("Microsoft.XMLHTTP");
               } catch (e) {
                   alert("Your browser does not support AJAX!");
                  return false;
               }
         }
      }
  oRequest.open("POST","search.php",true);
  oRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  oRequest.setRequestHeader("Content-length", params.length);
  oRequest.setRequestHeader("Connection", "close");
  oRequest.send(params);  
  document.getElementById("cdiv1").innerHTML = "Searchng....";
  oRequest.onreadystatechange=function() {
  if(oRequest.readyState==4 && oRequest.status == 200)
      {
        document.getElementById("cdiv1").innerHTML = oRequest.responseText;
      }
 } 
}

function SendMessage()
{
if(document.getElementById("registered").checked)
{
alert(document.getElementById("registered").checked);
}
}

function DoRegister()
{
var oRequest;
var params = "fname=" + document.getElementById("fname").value + "&gender=" + document.getElementById("gender").value + 
	     "&bgroup=" + document.getElementById("bgroup").value + "&bday=" + document.getElementById("bday").value +
	     "&bmonth=" + document.getElementById("bmonth").value + "&byear=" + document.getElementById("byear").value +
 "&waline1=" + document.getElementById("waline1").value + "&waline2=" + document.getElementById("waline2").value +
 "&orgname=" + document.getElementById("orgname").value + "&deptname=" + document.getElementById("deptname").value +
  "&wcity=" + document.getElementById("wcity").value +
 "&wpcode=" + document.getElementById("wpcode").value + "&wcountry=" + document.getElementById("wcountry").value +
 "&pocc=" + document.getElementById("pocc").value + "&mphone=" + document.getElementById("mphone").value + 
 "&wphone=" + document.getElementById("wphone").value + "&hphone=" + document.getElementById("hphone").value + 
 "&paline1=" + document.getElementById("paline1").value + "&paline2=" + document.getElementById("paline2").value +
 "&paline3=" + document.getElementById("paline3").value + "&pcity=" + document.getElementById("pcity").value +
 "&ppcode=" + document.getElementById("ppcode").value + "&pcountry=" + document.getElementById("pcountry").value +
 "&ssc=" + document.getElementById("ssc").value + "&hsc=" + document.getElementById("hsc").value + 
 "&exam=" + document.getElementById("exam").value + "&group=" + document.getElementById("group").value + 
 "&house=" + document.getElementById("house").value + "&totyear=" + document.getElementById("totyear").value + 
 "&styear=" + document.getElementById("styear").value + "&endyear=" + document.getElementById("endyear").value + 
 "&nperson=" + document.getElementById("nperson").value + "&souvenir=" + document.getElementById("souvenir").checked + 
 "&sponsor=" + document.getElementById("sponsor").checked + "&connect=" + document.getElementById("connect").checked + 
 "&email=" + document.getElementById("email").value + "&volunteer=" + document.getElementById("volunteer").checked + 
 "&vlist=" + document.getElementById("vlist").checked + "&registered=" + document.getElementById("registered").checked + 
 "&nointernet=" + document.getElementById("nointernet").checked + "&description=" + document.getElementById("description").value + 
 "&regisoon=" + document.getElementById("regisoon").checked + "&regmem=" + document.getElementById("regmem").checked + 
 "&regren=" + document.getElementById("regren").checked + "&regboth=" + document.getElementById("regboth").checked;
 
try {
        oRequest=new XMLHttpRequest();
     } catch (e)   {
     try {
          oRequest=new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e) {
          try {
              oRequest=new ActiveXObject("Microsoft.XMLHTTP");
               } catch (e) {
                   alert("Your browser does not support AJAX!");
                  return false;
               }
         }
      }
  oRequest.open("POST","register.php",true);
  oRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  oRequest.setRequestHeader("Content-length", params.length);
  oRequest.setRequestHeader("Connection", "close");
  oRequest.send(params);
  document.getElementById("cdiv1").innerHTML = "Registering....";
  oRequest.onreadystatechange=function() {
  if(oRequest.readyState==4 && oRequest.status == 200)
      {
        document.getElementById("cdiv1").innerHTML = oRequest.responseText;
      }
 }
}

function ProcessContact()
{
var oRequest;
var params = "name=" + document.getElementById("name").value + "&email=" + document.getElementById("email").value + 
		"&hsc=" + document.getElementById("hsc").value + "&subj=" + document.getElementById("subj").value +
		"&attn=" + document.getElementById("attn").value + "&code=" + document.getElementById("scode").value + 
		"&message=" + document.getElementById("message").value + "&ssc=" + document.getElementById("ssc").value;

try {
        oRequest=new XMLHttpRequest();
     } catch (e)   {
     try {
          oRequest=new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e) {
          try {
              oRequest=new ActiveXObject("Microsoft.XMLHTTP");
               } catch (e) {
                   alert("Your browser does not support AJAX!");
                  return false;
               }
         }
      }
  oRequest.open("POST","contact.php",true);
  oRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  oRequest.setRequestHeader("Content-length", params.length);
  oRequest.setRequestHeader("Connection", "close");
  oRequest.send(params);
  document.getElementById("cdiv1").innerHTML = "Processing....";
  oRequest.onreadystatechange=function() {
  if(oRequest.readyState==4 && oRequest.status == 200)
      {
        document.getElementById("cdiv1").innerHTML = oRequest.responseText;
      }
 }

}
function getContent(contentName)
{
var html;
try {
        html=new XMLHttpRequest();
     } catch (e)   {
     try {
          html=new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e) {
          try {
              html=new ActiveXObject("Microsoft.XMLHTTP");
               } catch (e) {
                   alert("Your browser does not support AJAX!");
                  return false;
               }
         }
      }
  if(contentName == "constitution")
  {
  html.open("GET","constitution.html",true);
  setCookie('page','constitution',365);
  }
  else if(contentName == "constitutionen")
  {
  html.open("GET","constitution-en.html",true);
  setCookie('page','constitutionen',365);
  }
  else if(contentName == "history")
  {
  html.open("GET","history.html",true);
  setCookie('page','history',365);
  }
  else if(contentName == "members") 
  {
  html.open("GET","members.html",true);
  }
  else if(contentName == "about")
  {
  html.open("GET","about.html",true);	
  }
  else if(contentName == "room")
  {
  html.open("GET","room.html",true);
  }
  else if(contentName == "contact")
  {
  html.open("GET","contact.html",true);	
  }
  else if(contentName == "reunion")
  {
  html.open("GET","reunion.html",true);
  }
  else if(contentName == "conveners")
  {
  html.open("GET","conveners.html",true);
  }
  else if(contentName == "sponsors")
  {
  html.open("GET","sponsors.html",true);
  }
  else if(contentName == "souvad")
  {
  html.open("GET","souvenirad.html",true);
  }
  else if(contentName == "publication")
  {
  html.open("GET","publication.html",true);
  }
  else if(contentName == "register")
  {
  html.open("GET","register.html",true);
  }
  else if(contentName == "attend")
  {
  html.open("GET","attend.html",true);
  }
  else if(contentName == "gallery")
  {
  html.open("GET","gallery.html",true);
  }
  else if(contentName == "print")
  {
  html.open("GET","print.php",true);
  }
  else if(contentName == "scholer")
  {
  html.open("GET","scholer.html",true);
  }
  else
  {
  window.location="http://www.esad.org.bd";
  }
  html.send(null);
  document.getElementById("cdiv1").innerHTML = "loading....";
  html.onreadystatechange=function() {
  if(html.readyState==4 && html.status == 200)
      {
        document.getElementById("cdiv1").innerHTML = html.responseText;
      }
  }

}

