// popup function
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=500,height=450,scrollbars=yes');
return false;
}
// popup function end
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=450,left = 385,top = 285');");
}


// test if ti's a number
function onlynum(eventObj, obj)
{
	var keyCode
	if (document.all){ 
		keyCode=eventObj.keyCode
	}
	else{
		keyCode=eventObj.which
	}
	var str=obj.value
	if(keyCode!=0){
		if(keyCode!=8){
			if(keyCode==46){ 
				if (str.indexOf(".")>0){
				return false
			}
		}
	if(keyCode==46){ 
			if (str.indexOf(".")>0){
				return false
			}
		}
		if((keyCode<48 || keyCode >58)   &&   (keyCode != 46)){ // Allow only integers and decimal points
			return false
		}
	}}
	return true
}
// end


//function validate for the contact page
function sendmessage(){

	if(contact.fname.value==""){
		alert ("Please enter the information for the \"First Name\" field.");
		contact.fname.focus();
		return false;
	}
	if(contact.lname.value==""){
		alert ("Please enter the information for the \"Last Name\" field.");
		contact.lname.focus();
		return false;
	}
    	if(contact.email.value==""){
		alert ("Please enter information for the \"Email\" field.");
		contact.email.focus();
		return false;
	}
	if ((contact.email.value.indexOf('@', 0) == -1) || (contact.email.value.indexOf('.') == -1)){ 
		alert ("Please fill in a correct email address" );    
		contact.email.focus();
		return false;
	}
    	if(contact.phone.value==""){
		alert ("Please enter information for the \"Phone\" field.");
		contact.phone.focus();
		return false;
	}
	
	if(contact.fax.value==""){
		alert ("Please enter information for the \"Fax\" field.");
		contact.fax.focus();
		return false;
	}
	if(contact.country.value==""){
		alert ("Please enter information for the \"Country\" field.");
		contact.country.focus();
		return false;
	}
	
	if(contact.zip.value==""){
		alert ("Please enter information for the \"Zip / Code Postal\" field.");
		contact.zip.focus();
		return false;
	}
    if(contact.comments.value==""){
		alert ("Please enter information for the \"Comments\" field.");
		contact.comments.focus();
		return false;
	}	
			 
	else{
        document.contact.submit();}


}
// end of function



//to subscribe in the newsletter

nlSubscribe = function()
{
	if(document.getElementById("email_nl").value=="")
	{
		alert("Please fill in the fields correctly.")
		return;
	}
	  var parameters = "email=" + escape( encodeURI( document.getElementById("email_nl").value ) );
	  
	  parameters += "&action=" + escape( encodeURI( "1" ) );
	  
	  if(true)
	  {
		 document.getElementById('nl_form_wait').style.display = '';
		 document.getElementById('nl_form').style.display = 'none'; // hide the object so it's not clickable anymore to avoid double requests
		 
		  var xmlHttp;
		  try { xmlHttp=new XMLHttpRequest(); } // Firefox, Opera 8.0+, Safari
		  catch (e) // Internet Explorer
			{
			try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
			catch (e)
			  {
			  try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
			  catch (e)
				{
				alert("Your request could not be accomplished.")
				return false;
				}
			  }
			}
			xmlHttp.onreadystatechange=function()
			  {
			  if(xmlHttp.readyState==4)
				{
					alert(xmlHttp.responseText);
					document.getElementById('nl_form').style.display = '';
					document.getElementById('nl_form_wait').style.display = 'none';
				}
			  }
			xmlHttp.open('POST', "newsletter/ajax_nl_subscribe.php", true);
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", parameters.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.send(parameters);
	  }
}


function displayImage(imageDir, imageObjectID, imageTitle) 
{
	document.getElementById(imageObjectID+'Preloader').style.display = '';
	document.getElementById(imageObjectID).style.display = 'none';
	var img_preload = new Image();
	img_preload.onload = function()
	{
			document.getElementById('mainImagePreloader').style.display = 'none';
			document.getElementById(imageObjectID).style.display = '';
			document.getElementById(imageObjectID).src = imageDir;
			
	}
	img_preload.src = imageDir;
}

function getNextImages(industryTextID, parentID, page, tableObject, imageObjectID)
{
	var xhr;

	try 
	{
		xhr = new XMLHttpRequest();
	} 
	catch (e) 
	{
		var a = ['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'MICROSOFT.XMLHTTP.1.0 ', 'MICROSOFT.XMLHTTP.1', 'MICROSOFT.XMLHTTP'];
		for (var i = 0; i < a.length; i++) 
		{
			try 
			{
				xhr = new ActiveXObject(a[i]);
				break;
			} 
			catch (e) {}
		}
	}

	xhr.onreadystatechange = function()
	{
		if(xhr.readyState==4)
		{
			document.getElementById(tableObject).innerHTML = xhr.responseText;
		}
	}
	xhr.open("GET", "list_galery_images.php?textID="+industryTextID+"&parentID="+parentID+"&page="+page, true);
	xhr.send(null);
	getFirstGalleryImage(industryTextID, parentID, page, imageObjectID, 1);
}

function getFirstGalleryImage(industryTextID, parentID, page, imageObjectID, returnString)
{
	var xhr;

	try 
	{
		xhr = new XMLHttpRequest();
	} 
	catch (e) 
	{
		var a = ['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'MICROSOFT.XMLHTTP.1.0 ', 'MICROSOFT.XMLHTTP.1', 'MICROSOFT.XMLHTTP'];
		for (var i = 0; i < a.length; i++) 
		{
			try 
			{
				xhr = new ActiveXObject(a[i]);
				break;
			} 
			catch (e) {}
		}
	}

	xhr.onreadystatechange = function()
	{
		if(xhr.readyState==4)
		{
			var responseData = xhr.responseText;
			responseData = responseData.split(";")
			displayImage(responseData[0], imageObjectID, responseData[1]) 
		}
	}
	xhr.open("GET", "get_first_galery_image.php?textID="+industryTextID+"&parentID="+parentID+"&page="+page+"&returnString="+returnString, true);
	xhr.send(null);
}

//to subscribe in the newsletter

nlSubscribe = function()
{
	if(document.getElementById("email_nl").value=="")
	{
		alert("Please fill in the fields correctly.")
		return;
	}
	  var parameters = "email=" + escape( encodeURI( document.getElementById("email_nl").value ) );
	  
	  parameters += "&action=" + escape( encodeURI( "1" ) );
	  
	  if(true)
	  {
		 document.getElementById('nl_form_wait').style.display = '';
		 document.getElementById('nl_form').style.display = 'none'; // hide the object so it's not clickable anymore to avoid double requests
		 
		  var xmlHttp;
		  try { xmlHttp=new XMLHttpRequest(); } // Firefox, Opera 8.0+, Safari
		  catch (e) // Internet Explorer
			{
			try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
			catch (e)
			  {
			  try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
			  catch (e)
				{
				alert("Your request could not be accomplished.")
				return false;
				}
			  }
			}
			xmlHttp.onreadystatechange=function()
			  {
			  if(xmlHttp.readyState==4)
				{
					alert(xmlHttp.responseText);
					document.getElementById('nl_form').style.display = '';
					document.getElementById('nl_form_wait').style.display = 'none';
				}
			  }
			xmlHttp.open('POST', "newsletter/ajax_nl_subscribe.php", true);
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", parameters.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.send(parameters);
	  }
}
