//---- browser detect ----//
var myBrowser;
var BrowserDetect = {
	init: function(){
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		myBrowser=this.browser;
	},
	searchString: function(data){
		for(var i=0;i<data.length;i++){
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if(dataString){
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}else if(dataProp){
				return data[i].identity;
			}
		}
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			prop: window.opera,
			identity: "Opera"
		}
	]
}
BrowserDetect.init();
//---------------php to js---------------//
function addslashes(str){
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\0/g,'\\0');
	return str;
}
function stripslashes(str){
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\0/g,'\0');
	str=str.replace(/\\\\/g,'\\');
	return str;
}
function removeApostrophe(str){
	str=str.replace("'","");
	str=str.replace('"',"");
	return str;
}
//---------------check email validity---------------//
function checkEmail(email){
	valid = false;
	if(document.getElementById(email).value!=''&&document.getElementById(email).value.match(/[\w\-]+@[\w\-]+\..+/)){
		valid = true;
	}else{
		//alert('אנא מלא כתובת דואר אלקטרוני תקינה');
	}
	return valid;
}
//---------------ajax form---------------//
var http_request = false;
function makeRequest(url){
	if (window.XMLHttpRequest) { // Mozilla, Safari, IE7...
		http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE6 and older
		http_request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	http_request.onreadystatechange = alertContents;
	http_request.open('GET', url, true);
	http_request.send(null);
}
function alertContents(){
	if(http_request.readyState == 4){
		if(http_request.status == 200){
			//alert(http_request.responseText);
			// WHAT HAPPENS ON SUCCESS
			document.getElementById('footer_form_wrap').style.backgroundImage='url(/images/footer_thanks.png)';
			document.getElementById('footer_form_wrap').innerHTML = "";
		}else{
			alert('אנא מלא את כל הפרטים הנחוצים');
		}
	}
}
//---- add to bookmarks ----//
function bookmark(url,title){
	if(title!=''){
		title=removeApostrophe(title);
	}else{
		title='Bidan';
	}
	var href = "";
	if(myBrowser=='Firefox'){
		href = "onclick=\"window.sidebar.addPanel('"+title+"','"+url+"','');\"";
	}else if(myBrowser=='Explorer'){
		href = "onclick=\"window.external.AddFavorite('"+url+"','"+title+"');\"";
	}else if(myBrowser=='Opera'){
		href = "href='"+url+"' rel='sidebar'";
	}else{
		// chrome and safari has no option for this action
	}
	if(href!=""){
		a_href = "";
		a_href += "<a "+href+" title='"+title+"' style='background-image:url(/images/icon_star.png); width:30px;'>";
		a_href += "&nbsp;";
		a_href += "</a>";
		document.write(a_href);
	}
}
