// JavaScript Document

	var  popuo_w = 300;
	var  popup_h = 162;
	var timer_hp = null;
	
	function displayAdw(divid){
		
		if(!hp_ppp_should_be_shown){
			return;
		}
		
		var scr = getScreenSize();
		
			var adw_pos_w = (scr.w/2)-(popuo_w/2);					
			var adw_pos_h = 250;
		
		document.getElementById(divid).style.left = adw_pos_w+"px";
		document.getElementById(divid).style.top = adw_pos_h+"px";
		
		document.getElementById('hppopupdiv').style.visibility = "visible";
		document.getElementById('hppopupdiv').style.display = "block";
		
		document.frmhppup.reset();
		document.getElementById('hopppmsg').innerHTML = "&nbsp;";
		return;
	}
	
	function getScreenSize() {
		  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;
		  }
		///  window.alert( 'Width = ' + myWidth );
		///  window.alert( 'Height = ' + myHeight );
		  
		var  w = myWidth;
		var  h = myHeight;
		  
		  return {w:w, h:h}
	}
	
	function hidePopUp(){
		document.getElementById('hppopupdiv').style.visibility = "hidden";
	}
	
	
	function closePopUp(){
		
			if(timer_hp != null){					
				clearTimeout(timer_hp);
			}
			
		 document.getElementById('hppopupdiv').style.visibility = "hidden";
	}
	
	function submitHPReq(){		
		var ev = document.frmhppup.enquiry_email.value;
		
		if(!checkEmal(ev)){
			alert("Please enter valid email address!");
			document.frmhppup.enquiry_email.focus();
		}
		else{
				// ajax processing :.
				
				document.getElementById('hopppmsg').innerHTML = '<span style="color:#ffffff;">Processing...</span>';
				document.frmhppup.submit();
				//runAjaxGet("hp_popup_exe.php", "?evalue="+ev);				
				// ajax processing .:
		}
		
	}
	
	function checkEmal(emlvalue) {					
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
					 
		return filter.test(emlvalue);					 
	}
	
	function getRequest(){
	
		 var req;
		 var faok = true;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            req = new XMLHttpRequest();
            if (req.overrideMimeType) {
                req.overrideMimeType('text/plain');
                // See note below about this line
            }
        } 
        else if (window.ActiveXObject) { // IE
            try {
                req = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) {
                try {
                    req = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                catch (e) {}
            }
        }

        if (!req) { faok = false;}

	return {status : faok, req : req};
}
// usage :: a = getRequest(); if(a.status){ ok, use req a.req }

function runAjaxGet(url, qry){

	var req = "";
	var fres = getRequest();
	
		if(fres.status){
		// 	alert("We have ajax request");			
			req = fres.req;
			// mdm.ic: processing :.
			req.onreadystatechange = function() { ajax_manageContent(req); };
			req.open('GET', url+qry, true);			
			req.send(null);
			// mdm.ic: processing .:
		}
		else{
			alert("[AJAX.GET.ERROR]: Unable to create http request!");
		}	
}

function ajax_manageContent(req){
	
	if (req.readyState == 4) {
            if (req.status == 200) {
				
				 var ret_content = req.responseText;
				 
				// alert("RET VAL : ["+ret_content+"]");
				
					if(ret_content == 1){
							document.getElementById('hopppmsg').innerHTML = '<span style="color:#0033FF;">Processing Done. Thank you!</span>';
							
							// init closing procedure :.
							timer_hp = setTimeout('closePopUp()', 3000);
							// init closing procedure .:
					}else{
							document.getElementById('hopppmsg').innerHTML = '<span style="color:#FF3300;">Error in processing. Please try again!</span>';
							document.frmhppup.enquiry_email.focus();
					}
				
            } else {
                alert('There was a problem with the request.');
            }
        }
		else{
				// alert("status: "+req.readyState);
		}
	
}
	
	displayAdw('hppopupdiv');

