﻿// JScript File

/* Ultimater's edited version of:
   http://jibbering.com/2002/4/httprequest.html
   to serve IE7 with XMLHttpRequest instead of ActiveX */

var xmlhttp=false;
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 	try {
 		 xmlhttp = new XMLHttpRequest();
 	} catch (e) {
 		 xmlhttp=false;
 	}
}

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
if (!xmlhttp){
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
}
@end @*/

if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

/* Ultimater's edited version of:
   http://javascript.internet.com/ajax/ajax-navigation.html */

var please_wait = "Please wait...";

function open_url(targetId) {
var flag;
flag = CheckForm();
if(flag==true){
var txtSub = document.getElementById('txtSub').value;
var txtMsg = document.getElementById('txtMsg').value;

var s = document.all("D1").selectedIndex;
	var dept = document.all("D1").options[s].text;
	
var txtName = document.getElementById('txtName').value;
var txtDes = document.getElementById('txtDes').value;
var txtPrd = document.getElementById('txtPrd').value;
var txtCmp = document.getElementById('txtCmp').value;
var txtAdd = document.getElementById('txtAdd').value;
var txtCnty = document.getElementById('txtCnty').value;
var txtPhone = document.getElementById('txtPhone').value;
var txtFax = document.getElementById('txtFax').value;
var txtMail = document.getElementById('txtMail').value;
var txtSite = document.getElementById('txtSite').value;
var opts = document.getElementById('txtDept').options.value;
var atch = document.getElementById('File1').value;

var emails =opts ;

atch = atch.replace("\\","/");

var queryString = "?atch="+atch+"&emails="+opts+"&txtSub=" + txtSub + "&txtMsg="+txtMsg+ "&txtName="+txtName+ "&txtDes="+txtDes+ "&txtPrd="+txtPrd+ "&txtCmp="+txtCmp+ "&txtAdd="+txtAdd+ "&txtCnty="+txtCnty+ "&txtPhone="+txtPhone+ "&txtFax="+txtFax+ "&txtMail="+txtMail+ "&txtSite="+txtSite+ "&dept="+dept; 

//var queryString ="?txtSub="+txtSub;
var go = "ContactDB.aspx";
var url = go+queryString;


  if(!xmlhttp)return false;
    var e=document.getElementById(targetId);if(!e)return false;
    if(please_wait)e.innerHTML = please_wait;
    xmlhttp.open("GET", url, true);
    xmlhttp.onreadystatechange = function() { response(url, e); }
    try{
      xmlhttp.send(null);
    }catch(l){
    while(e.firstChild)e.removeChild(e.firstChild);//e.innerHTML="" the standard way
    e.appendChild(document.createTextNode("request failed"));
  }
document.getElementById('txtSub').value="";
document.getElementById('txtMsg').value="";
document.getElementById('txtName').value="";
document.getElementById('txtDes').value="";
document.getElementById('txtPrd').value="";
document.getElementById('txtCmp').value="";
document.getElementById('txtAdd').value="";
document.getElementById('txtCnty').value="";
document.getElementById('txtPhone').value="";
document.getElementById('txtFax').value="";
document.getElementById('txtMail').value="";
document.getElementById('txtSite').value="";
}
else
{
    alert("Some required fields are empty!!");
}
}
function response(url, e) {
  if(xmlhttp.readyState != 4)return;
    var tmp= (xmlhttp.status == 200 || xmlhttp.status == 0) ? xmlhttp.responseText : "A broken link! Please contact the webmaster of this website ASAP and give him the following error code: " + xmlhttp.status+" "+xmlhttp.statusText;
    var d=document.createElement("div");
    d.innerHTML=tmp;
    setTimeout(function(){
      while(e.firstChild)e.removeChild(e.firstChild);//e.innerHTML="" the standard way
      e.appendChild(d);
    },10)
}
function CheckForm()
{
var sub = document.all("txtSub").value;
var msg = document.all("txtMsg").value;
var name = document.all("txtName").value;
var phone = document.all("txtPhone").value;
var mail = document.all("txtMail").value;
var f;
f=checkemail();
if(f==false)
{
    alert("Incorrect Formate of Email");
}
if(sub==""||msg==""||name==""||mail==""){
    return false;
 }
 else{
     return true;
 }

 }
 
function checkemail()
{
var str=document.all("txtMail").value;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
return true;
else{
return false;
}
}

