// General JavaScript Function
function showdiv(showdiv)
{	
	if(showdiv!=""){
		divId =document.getElementById(showdiv);
		divId.style.display="block";
	}
}

function hidediv(hidediv)
{
	if(hidediv!=""){
		divId =document.getElementById(hidediv);
		divId.style.display="none";
	}
}

//Validation function
function loginValidation(){
	
	if(document.getElementById('txt_email_id').value.length==0){
		alert("Please specify email id and proceed");
		document.getElementById('txt_email_id').focus();			
		return false;
	}
	if(document.getElementById('txt_password').value.length==0){
		alert("Please specify Password and proceed");
		document.getElementById('txt_password').focus();			
		return false;
	}
}

//is_numeric validation
function IsNumeric(value1)
{
	 
   var sText = document.getElementById(value1).value;
  
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
	 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
		
      }
	  
   if(IsNumber==false){
	  
	   alert('Enter only Numeric Value');
	   document.getElementById(value1).value="";
	   document.focus(value1);
   }
   
}//End IsNumeric

//Email Validation

		function checkemail(value1){
			
			var str=document.getElementById(value1).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{
			
				alert("Please Enter valid email address");	
				document.getElementById(value1).value="";					 
				return false;
			}
		
		}
		
		function emailValidation(value1){
		 
			if (document.getElementById(value1).value!="")
			return checkemail(value1)
			else
			return true
		}
		
 //End Email Validation
  
//--------------------End------------------------------
// Ajax JavaScript Document
function ajax(process,divname,value1,value2)
{ 
	if(process=="add_contact_details"){
				
		if(document.getElementById('title').value.length==0){
			alert("Please specify Title and proceed");
			document.getElementById('title').focus();			
			return false;
		}
		
		if(document.getElementById('firstName').value.length==0){
			alert("Please specify First name and proceed");
			document.getElementById('firstName').focus();
			return false;
		}
		
		if(document.getElementById('lastName').value.length==0){
			alert("Please specify Last name and proceed");
			document.getElementById('lastName').focus();			
			return false;
		}

		if(document.getElementById('email_address').value.length==0){
			alert("Please specify Email address and proceed");
			document.getElementById('email_address').focus();			
			return false;
		}
		
		if(document.getElementById('txt_password').value.length==0){
			alert("Please specify Password and proceed");
			document.getElementById('txt_password').focus();			
			return false;
		}
		
		if(document.getElementById('phone').value.length==0){
			alert("Please specify Phone number and proceed");
			document.getElementById('phone').focus();
			return false;
		}
		
		if(document.getElementById('job_title').value.length==0){
			alert("Please specify Job title and proceed");
			document.getElementById('job_title').focus();			
			return false;
		}
		
		if(document.getElementById('company_name').value.length==0){
			alert("Please specify Company name and proceed");
			document.getElementById('company_name').focus();
			return false;
		}
		
		if(document.getElementById('company_addr_1').value.length==0){
			alert("Please specify Company address and proceed");
			document.getElementById('company_addr_1').focus();			
			return false;
		}
		
		if(document.getElementById('city').value.length==0){
			alert("Please specify City and proceed");
			document.getElementById('city').focus();
			return false;
		}
		
		if(document.getElementById('zip_code').value.length==0){
			alert("Please specify Zip code and proceed");
			document.getElementById('zip_code').focus();			
			return false;
		}
		
		if(document.getElementById('country').value.length==0){
			alert("Please specify Country and proceed");
			document.getElementById('country').focus();
			return false;
		}
		
		if(document.getElementById('business_nature').value.length==0){
			alert("Please specify Business Nature and proceed");
			document.getElementById('business_nature').focus();
			return false;
		}
		
		contact_title  		 	 = document.getElementById('title').value;		
		contact_f_name	 		 = document.getElementById('firstName').value;
		contact_l_name 	 		 = document.getElementById('lastName').value;
		contact_email  			 = document.getElementById('email_address').value;
		contact_password		 = document.getElementById('txt_password').value;
		contact_phone  		 	 = document.getElementById('phone').value;
		contact_job_title	 	 = document.getElementById('job_title').value;
		contact_company_name  	 = document.getElementById('company_name').value;
		contact_company_addr_1	 = document.getElementById('company_addr_1').value;
		contact_company_addr_2 	 = document.getElementById('company_addr_2').value;
		contact_city  		 	 = document.getElementById('city').value;		
		contact_zipcode			 = document.getElementById('zip_code').value;		
		contact_country  		 = document.getElementById('country').value;
		contact_web_addr  		 = document.getElementById('web_address').value;
		contact_business_nature	 = document.getElementById('business_nature').value;		
		contact_ip_address		 = value2; //value2 contains the ip address of the visitor who register at IT Fission.
		
		
		if(contact_title!="" && contact_f_name!="" && contact_l_name!="" && contact_email!="" && contact_password!="" && contact_phone!="" && contact_job_title!="" && contact_company_name!="" && contact_company_addr_1!="" && contact_city!="" && contact_zipcode!="" && contact_country!="" && contact_business_nature){
			contact_div =document.getElementById(value1);
			contact_div.style.display="none";
			divId =document.getElementById(divname);
			divId.style.display="block";
		}
	 	 
	    qstr = 'p=' + escape(process) + '&contact_title=' + escape(contact_title) + '&contact_f_name=' + escape(contact_f_name) + '&contact_l_name=' + escape(contact_l_name) + '&contact_email=' + escape(contact_email)  + '&contact_password=' + escape(contact_password) + '&contact_phone=' + escape(contact_phone) + '&contact_job_title=' + escape(contact_job_title) + '&contact_company_name=' + escape(contact_company_name) + '&contact_company_addr_1=' + escape(contact_company_addr_1) + '&contact_company_addr_2=' + escape(contact_company_addr_2) + '&contact_city=' + escape(contact_city) + '&contact_zipcode=' + escape(contact_zipcode) + '&contact_country=' + escape(contact_country) + '&contact_web_addr=' + escape(contact_web_addr) + '&contact_business_nature=' + escape(contact_business_nature) + '&contact_ip_address=' + escape(contact_ip_address);  // NOTE: no '?' before querystring
		 
		document.getElementById(divname).innerHTML="<img src=images/wheel.gif>&nbsp;<span class='required'>Please wait, Loading...</span>"; 
		
		xmlhttpPost('common_ajax.php',divname,qstr);		
	
	}else //process end
	
	if(process=="add_contact_already_submit"){
		
		

		if(document.getElementById('submitted_email_address').value.length==0){
			alert("Please specify Email address and proceed");
			document.getElementById('submitted_email_address').focus();			
			return false;
		}
		
		contact_email  			 = document.getElementById('submitted_email_address').value;

		if(contact_email!=""){
			contact_div =document.getElementById(value1);
			contact_div.style.display="none";
			divId =document.getElementById(divname);
			divId.style.display="block";
		}
	 	 
	    qstr = 'p=' + escape(process) + '&contact_email=' + escape(contact_email);  // NOTE: no '?' before querystring
		 
		document.getElementById(divname).innerHTML="<img src=images/wheel.gif>&nbsp;<span class='required'>Please wait, Loading...</span>"; 
		
		xmlhttpPost('common_ajax.php',divname,qstr);		
	
	} //process end


}//Ajax end
 

function xmlhttpPost(strURL,divname,qstr)
 {
   
	
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText,divname);
        }
    }
    self.xmlHttpReq.send(qstr);
	 
}



function updatepage(a,divname)
{ 
	if(divname){
		document.getElementById(divname).innerHTML="";
		document.getElementById(divname).innerHTML=a;
	}
}

 function xmlhttpPostCurrency(strURL,qstr)
 {

	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq.open('POST', strURL, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
			updatePageCurrency(self.xmlHttpReq.responseText);
		}
	}
}