function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  return foundObj;
}

/* BOOKMARK FUNCTION
 *
 * params:
 * title 	- the name of the bookmarj
 * url 		- the link
 */
function bookmarksite(title, url){
	if (document.all)
	window.external.AddFavorite(url, title);
	else if (window.sidebar)
	window.sidebar.addPanel(title, url, "")
}

function showhide(layer) {
	if (document.getElementById(layer).style.display=='block')
		document.getElementById(layer).style.display = 'none';
	else
		document.getElementById(layer).style.display = 'block';
}

function checkEmail() {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('email1').value))
		return true;
	else
		alert("Invalid E-mail Address! Please re-enter.")
	return false;
}

function checkContact() {
	var msg = '';
	if (document.getElementById('cname').value=='')
		msg = msg + "חובה להזין שם\n";
	if (document.getElementById('ccontent').value=='')
		msg = msg + "חובה להזין את תוכן הפניה\n";
	if (document.getElementById('cemail').value=='')
		msg = msg + "חובה להזין כתובת דואר אלקטרוני\n";
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('cemail').value)) 
		msg = msg;
	else
		msg = msg + "כתובת הדואר האלקטרוני לא תקינה";
		
	if (msg=='') return true;
	alert(msg);
	return false;
}





// ********************************************************************
// ********************************************************************
// ********************************************************************
// redirect
function redirect(url)
{
	window.location.href = url;
}
function redirect_city(url)
{
	//redirect('http://www.israel-travel-tips.com/cities/'+url+'.html');
}

// ********************************************************************
// ********************************************************************
// ********************************************************************
// corenrs
function NiftyCheck()
{
	if(!document.getElementById || !document.createElement)
		return(false);
	var b=navigator.userAgent.toLowerCase();
	if(b.indexOf("msie 5")>0 && b.indexOf("opera")==-1)
		return(false);
	return(true);
}

function Rounded(selector,bk,color,size){
	var i;
	var v=getElementsBySelector(selector);
	var l=v.length;
	for(i=0;i<l;i++){
		AddTop(v[i],bk,color,size);
		AddBottom(v[i],bk,color,size);
		}
}

function RoundedTop(selector,bk,color,size){
	var i;
	var v=getElementsBySelector(selector);
	for(i=0;i<v.length;i++)
		AddTop(v[i],bk,color,size);
	}
	
	function RoundedBottom(selector,bk,color,size){
	var i;
	var v=getElementsBySelector(selector);
	for(i=0;i<v.length;i++)
		AddBottom(v[i],bk,color,size);
}

function AddTop(el,bk,color,size){
	var i;
	var d=document.createElement("b");
	var cn="r";
	var lim=4;
	if(size && size=="small"){ cn="rs"; lim=2}
	d.className="rtop";
	d.style.backgroundColor=bk;
	for(i=1;i<=lim;i++){
		var x=document.createElement("b");
		x.className=cn + i;
		x.style.backgroundColor=color;
		d.appendChild(x);
		}
	//el.insertBefore(d,el.firstChild);
}

function AddBottom(el,bk,color,size){
	var i;
	var d=document.createElement("b");
	var cn="r";
	var lim=4;
	if(size && size=="small"){ cn="rs"; lim=2}
	d.className="rbottom";
	d.style.backgroundColor=bk;
	for(i=lim;i>0;i--){
		var x=document.createElement("b");
		x.className=cn + i;
		x.style.backgroundColor=color;
		d.appendChild(x);
		}
	el.appendChild(d,el.firstChild);
}

function getElementsBySelector(selector){
	var i;
	var s=[];
	var selid="";
	var selclass="";
	var tag=selector;
	var objlist=[];
	if(selector.indexOf(" ")>0){  //descendant selector like "tag#id tag"
		s=selector.split(" ");
		var fs=s[0].split("#");
		if(fs.length==1) return(objlist);
		return(document.getElementById(fs[1]).getElementsByTagName(s[1]));
		}
	if(selector.indexOf("#")>0){ //id selector like "tag#id"
		s=selector.split("#");
		tag=s[0];
		selid=s[1];
		}
	if(selid!=""){
		objlist.push(document.getElementById(selid));
		return(objlist);
		}
	if(selector.indexOf(".")>0){  //class selector like "tag.class"
		s=selector.split(".");
		tag=s[0];
		selclass=s[1];
		}
	var v=document.getElementsByTagName(tag);  // tag selector like "tag"
	if(selclass=="")
		return(v);
	for(i=0;i<v.length;i++){
		if(v[i].className==selclass){
			objlist.push(v[i]);
			}
		}
	return(objlist);
}
