// JavaScript Document
//*****************    common functions for all pages *****************/
function slow(ele)
 {
 	ele.scrollAmount = 0.5;
 }
 
 function fast(ele)
 {
 	ele.scrollAmount = 2;
 }
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		home_over = newImage("images/home-over.gif");
		company_over = newImage("images/company-over.gif");
		products_over = newImage("images/products-over.gif");
		services_over = newImage("images/services-over.gif");
		support_over = newImage("images/support-over.gif");
		news_over = newImage("images/news-over.gif");
		careers_over = newImage("images/careers-over.gif");
		contact_us_over = newImage("images/contact-us-over.gif");
		preloadFlag = true;
	}
}
// in this function we are getting the all form elements 
function buildPOST(textForm) { 
    String.prototype.trim = function() {  return this.replace(/^\s*|\s*$/g, "");  }
    theForm = textForm; 
    var qs = '';
	
    for(e=0;e<theForm.elements.length;e++){ 
	    if (theForm.elements[e].name!='') { 
			var name = theForm.elements[e].name; 
			qs+=(qs=='')?'':'&';   //var val =theForm.elements[e].value;
            qs+= name+'='+escape(theForm.elements[e].value); 
        } 
    } 
    qs+="\n"; 
    return qs ;
} 
// Ajax Object creation
  function httpObj()
  {
  		var xmlHttp;
		if(window.XMLHttpRequest)
		 { 
			var xmlHttp = new XMLHttpRequest();
						}
		 // For Internet Explorer
		 else if(window.ActiveXObject)
		 { 
			var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		 }
		 return (xmlHttp);
  }

//********************************************************************//
//************************  function for login page *****************//
// login form validation
function chkLoginfrm(frm)
{
	String.prototype.trim = function() {  return this.replace(/^\s*|\s*$/g, "");  }
	firstname 	= frm.user_firstname.value;
	mailid		= frm.user_emailid.value;
	pwd			= frm.user_password.value;
	pwd1		= frm.user_password1.value;
	verfic		= frm.verificationno.value;
	user_grp	= frm.user_group_id.value;
	if(firstname.trim()==""	|| mailid.trim()=="" || pwd.trim()=="" || pwd1.trim()=="" || verfic.trim()=="" || user_grp.trim()=="")
	{
		alert("You should fill all mandatary fields in signup form!!"); return false;
	}
	if(pwd.trim()!=pwd1.trim())
	{
		alert("Warning!! Re-type your password Correctly."); return false;
	}
	if (echeck(mailid.trim())==false) 
	{
		frm.user_emailid.focus(); return false;
	}
	loginAction(frm);
}
// login form action
function loginAction(frm)
{
	String.prototype.trim = function() {  return this.replace(/^\s*|\s*$/g, "");  }
	var xmlqs =buildPOST(frm);
	var xmlHttp = httpObj();	
	url = 'Action4Login.php';
	xmlHttp.open('POST', url, true); 
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(xmlqs); 
	xmlHttp.onreadystatechange = function()
								{ 
								   if (xmlHttp.readyState == 4) 
								   {
										var rescont=new String(xmlHttp.responseText);
										if (frm.action.value==2 && rescont.trim() == 'correct')
										{
											window.location='redir.php';
										}
										else
										{
											alert(rescont);
											document.getElementById("msg").innerHTML = rescont;
											document.getElementById("errmsg").style.display = 'inline';
										}
								   }
								}
}
// email address validation
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
//*************************************************************************//
//********************* service.php page  ****************************//

function showctAddr(i)
{   
	document.getElementById("ctaddress"+i).style.display=(document.getElementById("ctaddress"+i).style.display=='inline')?'none':'inline';
}
function showct64Addr(i)
{   
	document.getElementById("ctaddress64"+i).style.display=(document.getElementById("ctaddress64"+i).style.display=='inline')?'none':'inline';
}
function showAddr(obj)
{   
	document.getElementById(obj).style.display=(document.getElementById(obj).style.display=='inline')?'none':'inline';
}
//******************** blink ***********************************************//
function bringBackBlinky() {
	if (swi == 1) {
		sho="visible";
		swi=0;
	}
	else {
		sho="hidden";
		swi=1;
	}
	for(i=0;i<na.length;i++) {
		na[i].style.visibility=sho;
	}
	setTimeout("bringBackBlinky()", spe);
}
//**********************************************************************************
function popUp()
{
    var div;
    
    if(document.getElementById)
    // Standard way to get element
    div = document.getElementById('popupWindow'); 
    else if(document.all) 
    // Get the element in old IE's 
    div = document.all['popupWindow']; 
    
    // if the style.display value is blank we try to check it out here 
    if(div.style.display==''&&div.offsetWidth!=undefined&&div.offsetHeight!=undefined)
    {
        div.style.display = (div.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none'; 
    }
    
    // If the PopUp is hidden ('none') then it will display it ('block').
    // If the PopUp is displayed ('block') then it will hide it ('none').
    div.style.display ='inline';
   
    // Off-sets the X position by 15px
    X = 45 ;
    Y = 50 ;
    // Sets the position of the DIV
    div.style.left = X+'px';
    div.style.top = Y+'px';
}
function clearpopup()
{
	  div = document.getElementById('popupWindow'); 
	  div.style.display ='none';
	  div = document.getElementById('backgroundFilter'); 
      div.style.display ='none';
	  
}

function viewRate()
{    
		document.getElementById("popupWindow").innerHTML = document.getElementById("ratelist").innerHTML; 
		 popUp();  //backgroundFilter();  alert("catch");
}
function backgroundFilter()
{
    var div;
    
    if(document.getElementById)
    // Standard way to get element
    div = document.getElementById('backgroundFilter'); 
    else if(document.all) 
    // Get the element in old IE's 
    div = document.all['backgroundFilter']; 
    
    // if the style.display value is blank we try to check it out here 
    if(div.style.display==''&&div.offsetWidth!=undefined&&div.offsetHeight!=undefined)
    {
        div.style.display = (div.offsetWidth!=0&&div.offsetHeight!=0)?'block':'none'; 
    }
    
    // If the background is hidden ('none') then it will display it ('block').
    // If the background is displayed ('block') then it will hide it ('none').
    div.style.display = 'block';
}
function dispServ(t,obj)
{
	 document.getElementById("popupWindow").innerHTML = '<center><img src="../image/loader.gif"></center>';   
	  popUp();  document.getElementById("popupWindow").style.left = '400px'; document.getElementById("popupWindow").style.top = '150px';
				  backgroundFilter();	
	document.getElementById('disp').innerHTML = document.getElementById(t).innerHTML;
	window.location.hash ='#'+obj ;
	clearpopup();			  
	
}
function getProd(ac,pg)
{	
	document.getElementById("popupWindow").innerHTML = '<center><img src="../image/loader.gif"></center>';   
	  popUp();  document.getElementById("popupWindow").style.left = '400px'; document.getElementById("popupWindow").style.top = '250px';
				  backgroundFilter();	
	String.prototype.trim = function() {  return this.replace(/^\s*|\s*$/g, "");  }
	var xmlqs ='action='+ac+'&page='+pg;
	var xmlHttp = httpObj();	
	url = 'ajax4service.php';
	xmlHttp.open('POST', url, true); 
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(xmlqs); 
	xmlHttp.onreadystatechange = function()
								{ 
								   if (xmlHttp.readyState == 4) 
								   {
										var rescont=new String(xmlHttp.responseText);
										document.getElementById('disp').innerHTML = rescont;
								   }
								}
								clearpopup();
}
function getProd1(ac,pg,dept)
{	
	
	String.prototype.trim = function() {  return this.replace(/^\s*|\s*$/g, "");  }
	var xmlqs ='action='+ac+'&page='+pg+'&dept='+dept;
	var xmlHttp = httpObj();	
	url = 'ajax4service.php';
	xmlHttp.open('POST', url, true); 
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(xmlqs); 
	xmlHttp.onreadystatechange = function()
								{ 
								   if (xmlHttp.readyState == 4) 
								   {
										var rescont=new String(xmlHttp.responseText);
										document.getElementById('disp').innerHTML = rescont;
								   }
								}
								clearpopup();
}
function setFcs(frm,t,obj,e)
{
  if (e.keyCode==13) 
  {
		if (t!=2){
			obj.focus();
		}
		else {
				loginAction(frm);
		}
  }
}