//******************************************************************************
//
//******************************************************************************

function getSiteUrl() {

   //---------------------------------------------------------------------------
   // Note that 'index.php' is a hardcoded value contrary to the PHP implementation
   //---------------------------------------------------------------------------

   //s var visitedUrl=window.top.location.href;
   var visitedUrl=window.location.href;

   if (visitedUrl.indexOf("index.php") > 0) {  // url is similar to http://www.site.com/index.php..... or similar to http://www.site.com/~samidoon/index.php...
      pos=visitedUrl.indexOf("index.php");
      siteUrl = visitedUrl.substr(0, pos) ;
   } else {
      siteUrl = visitedUrl ;  // url is similar to http://www.site.com or http://www.site.com/ or http://www.site.com/~samidoon/
   }

   // now remove posible slashes at the end
   while( siteUrl.lastIndexOf('/') == siteUrl.length-1 ) {
      siteUrl = siteUrl.substr(0, siteUrl.length-1);
   }

   // document.cookie="siteUrl="+siteUrl;
   return siteUrl;
}

//******************************************************************************
//                          favoriets and homepage
//******************************************************************************

function addToFavorites() {
   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   // order in the if statement is significant
   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   
   if(window.sidebar) {
      // Firefox Bookmark
      window.sidebar.addPanel(document.title, location.href, "");
   } else if(window.external) {   
      // IE Favorite
      window.external.AddFavorite(location.href, document.title);      
   } else {
      alert("الرجاء استخدام الآلية التي يوفرها متصفحك لإضافة الصفحة لمفضلتك");
   }
}

//==============================================================================

function setHomePage() {

   if(window.sidebar) {
   //---------------------------------------------------------------------------
   // This condition applies to Firefox where the following code
   // does not work. So just return for now
   //---------------------------------------------------------------------------
      alert("الرجاء استخدام الآلية التي يوفرها متصفحك لجعل الموقع صفحتك الرئيسية");
      return;
   }
   
   document.body.style.behavior='url(#default#homepage)';
   document.body.setHomePage(location.href);   
}

//******************************************************************************
//                                Cookies
//******************************************************************************

function cookiesEnabled() {
  document.cookie="testCookie=cookies enabled test";

  var cookieValue = get_cookie(testCookie);
  if (cookieValue == "") {
     return false;
  }

  return true;
}

//==============================================================================

//Get cookie routine by Shelley Powers
function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    // if cookie exists
    if (offset != -1) {
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
  }
  return returnvalue;
}

//******************************************************************************
//                     Scroll Up On Double Click
//******************************************************************************

function scrollUpOnDoubleClick() {
   if (document.layers) {
      document.captureEvents(Event.ONDBLCLICK);
   }

   document.ondblclick=scrollUp;
}

function scrollUp() {
   window.scrollTo(0,0)
}

//******************************************************************************
//                   Disable Right Mouse Click On Images
//******************************************************************************

function disableImageRightMouseClick() {

   // var clickmessage="معذرة ... هذه الخاصية معطلة"; did not know how to pass the message variable so I defined it in the function below

   if (document.all)
      document.onmousedown=disableclick
   else if (document.layers)
      associateimages()
}

function disableclick(e) {

   var clickmessage="معذرة ... هذه الخاصية معطلة";

   if (document.all) {
      if (event.button==2||event.button==3) {
         if (event.srcElement.tagName=="IMG"){
            alert(clickmessage);
            return false;
         }
      }
   }

   if (document.layers) {
      if (e.which == 3) {
         alert(clickmessage);
         return false;
      }
   }
}

function associateimages(){
   for(i=0;i<document.images.length;i++)
      document.images[i].onmousedown=disableclick;
}

//******************************************************************************
//                     Disable Right Mouse Click
//******************************************************************************

function disableRightMouseClick() {

   //Disable right mouse click Script
   //By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
   //For full source code, visit http://www.dynamicdrive.com

   if (document.layers){
      document.captureEvents(Event.MOUSEDOWN);
      document.onmousedown=clickNS4;
   } else if (document.all&&!document.getElementById){
      document.onmousedown=clickIE4;
   }

   document.oncontextmenu = new Function("return false")

}

function clickIE4(){

   var message="معذرة ... هذه الخاصية معطلة";

   if (event.button==2){
      alert(message);
      return false;
   }
}

function clickNS4(e){

   var message="معذرة ... هذه الخاصية معطلة";

   if (document.layers||document.getElementById&&!document.all){
      if (e.which==2||e.which==3){
         alert(message);
         return false;
      }
   }
}

//******************************************************************************
//                              Popup Window
//******************************************************************************

function popUp(url, settings) {

  if(settings == "") {
     settings = "toolbar=0,status=0,menubar=0,resizable=1,location=0,left=50,top=50,scrollbars=0,width=400,height=270," ;
  }

  myWindowHandle = window.open(url,'_blank',settings) ;
  return myWindowHandle;
}

function popUp_(url) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=0,scrollbars=1,location=0,status=1,menubar=0,resizable=1,width=300,height=300,left=50,top=50');");
}

//******************************************************************************
// hide - show Object
//------------------------------------------------------------------------------
// Note: to get an object by ID use  var obj = document.getElementById(id);
//******************************************************************************

function hide(obj, keepSpace) {

  if(keepSpace == true) {
     obj.style.visibility = "hidden";
  } else {
     obj.style.display = "none";
  }
}

function show(obj) {

  obj.style.display = "";
  obj.style.visibility = "visible";
}
 
function toggleAppearance(obj, keepSpace) {

  if( (obj.style.visibility == "hidden") || (obj.style.display == "none") ) {
     show(obj);
  } else {
     hide(obj, keepSpace)
  }

} 

//******************************************************************************
// two different implementations of the trim function
//******************************************************************************

String.prototype.trim = function() {
  return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

//******************************************************************************
// Type Detection
//******************************************************************************

function isBoolean(a) {
    return typeof a == 'boolean';
}

function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}

function isString(a) {
    return typeof a == 'string';
}

function isArray(a) {
    return isObject(a) && a.constructor == Array;
}

function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}

function isFunction(a) {
    return typeof a == 'function';
}

function isNull(a) {
    return typeof a == 'object' && !a;
}

function isUndefined(a) {
    return typeof a == 'undefined';
}

//******************************************************************************<script>

var staticlogo=new Image(300,100)
var imgNum=3
var ranNum=Math.floor(Math.random()*imgNum)
var imgName=new Array(imgNum)
imgName[0]="../../www.khayma.com/logs/zuwar.jpg"
imgName[1]="../../www.khayma.com/logs/i3lan.gif"
imgName[2]="../../www.khayma.com/logs/taskeen.jpg"
staticlogo.src=imgName[ranNum]
var logolink="../../www.khayma.com/default.htm"
var alttext="الخيمة العربية"
var fadeintoview=1
var visibleduration=0

function regenerate(){
window.location.reload()
}
function regenerate2(){
if (document.layers)
setTimeout("window.onresize=regenerate",400)
}

var fadeset=''
if (fadeintoview)
fadeset="filter:alpha(opacity=0)"

if (document.all)
document.write('<span id="logo" style="'+fadeset+';position:absolute;top:100;width:'+staticlogo.width+';height:'+staticlogo.height+'"></span>')

function bringintoview(){
if (logo.filters.alpha.opacity<=95)
logo.filters.alpha.opacity+=5
else{
clearInterval(viewit)
if (visibleduration!=0)
setTimeout("logo.style.visibility='hidden'",visibleduration*1000)
}
}

function createlogo(){
staticimage=new Layer(100)
staticimage.left=-300
staticimage.top=120
staticimage.document.write('<a target=new href="'+logolink+'"><img src="'+staticlogo.src+'" border=0 alt="'+alttext+'"></a>')
staticimage.document.close()
staticimage.visibility="show"
regenerate2()
staticitns()
}

if (document.layers)
window.onload=createlogo;

if (document.all){
w=document.body.clientWidth-logo.style.pixelWidth-5
h=document.body.clientHeight-logo.style.pixelHeight-5
logo.style.left=5
logo.style.top=h
}

function logoit(){
var w2=document.body.scrollLeft+5
var h2=document.body.scrollTop+h
logo.style.left=w2
logo.style.top=h2
}
function logoit2(){
staticimage.left=pageXOffset+window.innerWidth-staticimage.document.width-15
staticimage.top=pageYOffset+window.innerHeight-staticimage.document.height
}

function insertimage(){
logo.innerHTML='<a target=new href="'+logolink+'"><img src="'+staticlogo.src+'" border=0 alt="'+alttext+'"></a>'
if (fadeintoview)
viewit=setInterval("bringintoview()",100)
else{
if (visibleduration!=0)
setTimeout("logo.style.visibility='hidden'",visibleduration*1000)
}
}

if (document.all){
window.onscroll=logoit
window.onresize=new Function("window.location.reload()")
window.onload=insertimage
}

function staticitns(){
setInterval("logoit2()",90)
if (visibleduration!=0)
setTimeout("staticimage.visibility='hide'",visibleduration*1000)
}

</script>
