﻿/*
				################################
				#                        Shlomo's AJAX javascript                     #
				#            All rights reserved shlomoweb1@gmail.com      #
				#################################
*/

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function loadAJAX(){
	var page_request = false
	if (window.XMLHttpRequest){ // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	}else if (window.ActiveXObject){ // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
		try{
			page_request = new ActiveXObject("Microsoft.XMLHTTP")
		}
		catch (e){}
		}
		
	}else{
		return false
		//break;
	}
	return page_request;
}

function ajaxpage(url, containerid, title, Vwidth, Vheight){
	var page_request = loadAJAX();
	if(document.getElementById(containerid))
	document.getElementById(containerid).innerHTML = "<BR><center><img src=\"images/loading.gif\"><BR>Please wait while the information/data is loading.";
	
	page_request.onreadystatechange=function(){
		loadpage(page_request, containerid)
	}
	if (bustcachevar) //if bust caching of external page
		bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	page_request.open('GET', url+bustcacheparameter, true)
	page_request.send(null)
	

}

function changeOpac(opacity, id) { //change the opacity for different browsers
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function closeAJAXpopup(){ //destroy all popup div
	closelementById('bgpopup');
	closelementById('popupBar');
	closelementById('popup');
}

function closelementById(id){
	while (document.getElementById(id)){ // A bug that won't close on one click ?!??!
		document.getElementById(id).parentNode.removeChild(document.getElementById(id));
	}
}

function loadpage(page_request, containerid){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
		//document.getElementById(containerid).innerHTML="";
		document.getElementById(containerid).innerHTML=page_request.responseText;
		}
}

function loadobjs(){
	if (!document.getElementById)
	return
	for (i=0; i<arguments.length; i++){
		var file=arguments[i]
		var fileref=""
		if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
			if (file.indexOf(".js")!=-1){ //If object is a js file
				fileref=document.createElement('script')
				fileref.setAttribute("type","text/javascript");
				fileref.setAttribute("src", file);
			}else if (file.indexOf(".css")!=-1){ //If object is a css file
				fileref=document.createElement("link")
				fileref.setAttribute("rel", "stylesheet");
				fileref.setAttribute("type", "text/css");
				fileref.setAttribute("href", file);
			}
		}
		if (fileref!=""){
			document.getElementsByTagName("head").item(0).appendChild(fileref)
			loadedobjects+=file+" " //Remember this object as being already added to page
		}
	}
}


//Show Mini information pop
     function infoOpen(e){
     document.all.popupBox.style.left = e.pageX;
     document.all.popupBox.style.top = e.pageY;
     document.all.popupBox.style.visibility = "visible";
     }

     function infoClose(){
     document.all.popupBox.style.visibility = "hidden";
     } 
	 
	function searchWeb(){
		var query = document.getElementById('SearchField').value;
		var url = document.getElementById('SearchSelect').options[document.getElementById('SearchSelect').selectedIndex].value;
		if (query != ""){
		overlay(url+query, query, true)
		}else{
		alert("הכנס מילת מפתח לחיפוש");
		}
	}
	function submitonEnter(e){
		if(e.keyCode == 13){
			searchWeb();
		}
	  }
	  
	function getpagesize(what) { // For IE debug
		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;
		}
		switch(what){
			case "width":
				return myWidth;
			break;    
			case "height":
				return myHeight;
			break;
		}
	}
	// window.alert( 'Width = ' + getpagesize('width') );
 // window.alert( 'Height = ' + getpagesize('height') );	
	
	function overlay(url, title, iframe) {
		if(!title)
			title = "";
		id = "overlay";
		if (document.getElementById(id)){
			document.getElementsByTagName("body").item(0).style.margin = "20px"// debug IE margin
			for (a=0;a<document.getElementsByTagName("SELECT").length;a++){
				document.getElementsByTagName("SELECT")[a].style.visibility="visible";
			}
			while (document.getElementById(id)){ // A bug that won't close on one click ?!??!
				document.getElementById(id).parentNode.removeChild(document.getElementById(id));
			}
		}else{
			var overlay = document.createElement('div');
			overlay.setAttribute('id', id);
			//overlay.setAttribute('class', 'overlaypng');
			document.body.appendChild(overlay);
			overlay.innerHTML = "<div dir=\"ltr\" id=\"barAJAX\"><table width=\"100%\" border=\"0\"><tr><td align=\"left\">"+title+"<td></td><td align=\"right\">[<a href='#' onclick='overlay(); return false;'>סגור</a>]</td></tr></table></div><BR><div id=\"overlayInner\"><img src=\"images/loading.gif\"><BR>המתן בזמן שהמידע עולה, תודה.</div>";
			if(navigator.appName != "Microsoft Internet Explorer"){
				document.getElementById(id).style.background = "yellow";
				document.getElementById(id).style.background = "url(images/ajaxbg.png)";
			} else {
			overlay.style.width = getpagesize('width') +"px"// debug IE margin
			overlay.style.height = getpagesize('width') +"px"// debug IE margin
			overlay.style.top = "0px"// debug IE margin
			overlay.style.left = "0px"// debug IE margin
			}
			overlay.style.visibility = "visible";	

				if(iframe){
					document.getElementById('overlayInner').innerHTML = "<iframe id=\"AJAXiframe\" src=\"images/loading.gif\" width=\"100%\" height=\"100%\"></iframe>";
					//page_request.onreadystatechange=function(){
					//if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
						document.getElementById('AJAXiframe').src = url;
					//}
				//}
				}else{		
					var page_request = loadAJAX();
					page_request.onreadystatechange=function(){
					loadpage(page_request, 'overlayInner');
					page_request.open("GET", url ,true);
					page_request.send(null);
				}
				}

				
				
			//document.getElementsByTagName("body").item(0).style.margin = "0px"// debug IE margin
			
			//document.getElementsByTagName("body").item(0).style.margin = "0px"// debug IE margin
			
			for (a=0;a<document.getElementsByTagName("SELECT").length;a++){
				document.getElementsByTagName("SELECT")[a].style.visibility="hidden";
			}
		
		}
	}
	
function loadExternal(url) {
  if ( window.frames['buffer'] ) {
    window.frames['AJAXiframe'].location = url;
    var lyr = document.getElementById? document.getElementById('display'): document.all? document.all['display']: null;
    if ( lyr && typeof lyr.innerHTML != "undefined" ) {
      lyr.innerHTML = '<img src="images/loading.gif" alt="">';
    }
    return false;
  } 
  return true; // other browsers follow link
}

	function menuHover(id, image){
		document.getElementById(id).src = image;
	}
	

	function DoItSend(url, poststr){  
	  var http_request = loadAJAX();
      http_request.onreadystatechange = function(){
		ajaxpage('thankyou.html', 'mainContent');
	}
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", poststr.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(poststr);

	  }
function get(obj) {
var Vname = document.getElementById("name").value;
var Vemail =document.getElementById("email").value;
var Vsubject = document.getElementById("subject").value;
var Vmessage = document.getElementById("message").value;
var i = 0;
if (Vname != ""){
var poststr =  "name=" + escape(encodeURI( Vname ));
	if(Vemail != ""){
		poststr += "&email=" +escape(encodeURI( Vemail ));
		if(Vsubject != ""){
			poststr += "&subject=" +escape(encodeURI( Vsubject ));
			if(Vmessage != ""){
				poststr += "&message=" +escape(encodeURI( Vmessage ));
				i = 1;
			}else{
				alert("please insert a message");
			}
		}else{
			alert("please insert a subject");
		}
	}else{
		alert("please insert your email");
	}
}else{
	alert("please insert your name")
}
    
if(i == 1){    
	DoItSend('contact.php', poststr);
}
}
function menuHover(id, link){
	document.getElementById(id).src = link;
}
