// JavaScript Document
function senddivecenter(cenno)
{
var popupresult=window.open("sendcenter_ar.aspx?Cenno="+String(cenno), "popupSendDiveCenter","width=680,height=480,scrollbars=yes,resizable=yes,status=yes,toolbar=no,location=no"); // to open the pop up Send Dive center arabic window
popupresult.focus();
return popupresult.closed;

}
document.onclick=function(e)//just to open external links in a new window
{ var target=e? e.target : window.event.srcElement
  while(target && !/^(a|body)$/i.test(target.nodeName)){
	  target=target.parentNode;
	  }
	if (target && target.getAttribute("rel")=="external"){
		var external=window.open(target.href);
		return external.closed;
		}
	}

//addLoadListener(showDate); //to show date on each page
addLoadListener(PrintArticle);

function ShowPollResult(pollno) {
var popupresult=window.open("PollResult_ar.aspx?PollID="+String(pollno), "popupwindow","width=640,height=515,scrollbars=yes,resizable=yes,status=yes,toolbar=no,location=no");
popupresult.focus();
return popupresult.closed;
}




function ShowsubscribePopClick(){

var popupresult=window.open("subscriptionar.aspx", "popupSubscribe","width=680,height=680,scrollbars=yes,resizable=yes,status=yes,toolbar=no,location=no"); // to open the pop up Subscribe window
popupresult.focus();
return popupresult.closed;

}

function ShowsubscribePopClickLevel2(){

var popupresult=window.open("../subscriptionar.aspx", "popupSubscribe","width=680,height=680,scrollbars=yes,resizable=yes,status=yes,toolbar=no,location=no"); // to open the pop up Subscribe window
popupresult.focus();
return popupresult.closed;

}


function ShowWinnersPop(){

var popupresult=window.open("winners.html", "popupWinners","width=640,height=500,scrollbars=yes,resizable=yes,status=yes,toolbar=no,location=no"); // to open the pop up Subscribe window
popupresult.focus();

}

function PrintArticle() {//to print an article 
var docBodyPrintArticle=document.getElementById("PrintaArticle")
if(docBodyPrintArticle != null){ 
window.print()
}
}


function ShowFormSendFriend(ArticleID,CatID) { //to 
var popupresult=window.open("../SendToFriend.aspx?ArticleID="+String(ArticleID)+"&Cat="+String(CatID), "popupwindow","width=500,height=480,scrollbars=yes,resizable=yes,status=yes,toolbar=no,location=no");
popupresult.focus();
return popupresult.closed;



}

function Clickheretoprint(ArticleID)
{ 
  
   
  
  var popupresult=window.open("print.aspx?ArticleID="+String(ArticleID),"popUp","width=680,height=480,scrollbars=yes,resizable=yes,status=yes,toolbar=no,location=no"); 
   popupresult.focus();
   return popupresult.closed;
}






function telloptional(){ // to hide and show text box in advertise_ar.aspx
var type=document.getElementsByTagName("select");
if (type[0].selectedIndex==6){
	showOptional();
	}else{
		hideOptional();
		}
}

function closePage(){
window.close();


	
}





function showOptional()
{
  var optional = document.getElementById("optional");
  optional.className = "";

  return true;
}

function hideOptional()
{
  var optional = document.getElementById("optional");
  optional.className = "hidden";

  return true;
}




function validateForm(pollno,width, height, overflow) { //to validate the poll section in homepage
var selecta=document.forms["formapoll"]["selecta"];
var value=0;
for (var i=0;i<selecta.length;i++){
if (selecta[i].checked){
value=i+1;
}

}
if (value==0){
alert("الرجاء الاختيار لدخول الاستبيان ");
return false;
}else{

if (width>640){width=640;}
if(height>480){height=480;}
if(overflow=="" || !/^(scroll|resize|both)$/.test(overflow)){overflow='both';}

var popwindow = window.open("PollResult_ar.aspx?value="+value+"&PollID="+String(pollno),"popupwindow","width="+width+",height="+height+",scrollbars="+(/^(scroll|both)$/.test(overflow)? "yes" : "no")+",resizable="+(/^(resize|both)$/.test(overflow)? "yes" : "no")+",status=yes,toolbar=no,menubar=no,location=no");

popwindow.focus(); 
return popwindow.closed;
}}

function cleardataADform(){ // to clear all data in advertise_ar.aspx form
var elementz=document.forms[0].elements;
for (var i=0;i<elementz.length;i++){
if (elementz[i].getAttribute("type")){
	if (elementz[i].getAttribute("type")=="text"){
		elementz[i].value="";
		
		}
		
	}
	if (elementz[i].nodeName.toLowerCase()=="textarea"){
		elementz[i].value="";
		
		}
		if (elementz[i].nodeName.toLowerCase()=="select"){
			elementz[i].selectedIndex=0;}
		if (elementz[i].getAttribute("type")=="checkbox"){
		elementz[i].checked=false;
		
		}
	
	}

	
	if (document.getElementById("optional")){hideOptional();}
	
		
	
	return true;
}






function addLoadListener(fn)
{
  if (typeof window.addEventListener != 'undefined')
  {
    window.addEventListener('load', fn, false);
  }
  else if (typeof document.addEventListener != 'undefined')
  {
    document.addEventListener('load', fn, false);
  }
  else if (typeof window.attachEvent != 'undefined')
  {
    window.attachEvent('onload', fn);
  }
  else
  {
    var oldfn = window.onload;
    if (typeof window.onload != 'function')
    {
      window.onload = fn;
    }
    else
    {
      window.onload = function()
      {
        oldfn();
        fn();
      };
    }
  }
}



function selectsubject() { //to select subject in privacystatement_ar.aspx
var statement=document.forms["formaanchor"]["menu1"];	
var statevalue=statement[statement.selectedIndex].value;
document.location="privacystatement_ar.aspx"+statevalue;
	
}

addLoadListener(initTooltips); //to show the tooltip for the links

function initTooltips()
{
  var tips = getElementsByAttribute("class", "hastooltip");

  for (var i = 0; i < tips.length; i++)
  {
    attachEventListener(tips[i], "mouseover", showTip, false);
    attachEventListener(tips[i], "mouseout", hideTip, false);
  }

  return true;
}

function showTip(event)
{
  if (typeof event == "undefined")
  {
    event = window.event;
  }

  var target = getEventTarget(event);

  while (target.className == null || !/(^| )hastooltip( |$)/.test(target.className))
  {
    target = target.parentNode;
  }

  var tip = document.createElement("div");
  var content = target.getAttribute("title");

  target.tooltip = tip;
  target.setAttribute("title", "");

  if (target.getAttribute("id") != "")
  {
    tip.setAttribute("id", target.getAttribute("id") + "tooltip");
  }

  tip.className = "tooltip";
  tip.appendChild(document.createTextNode(content));

  var scrollingPosition = getScrollingPosition();
  var cursorPosition = [0, 0];

  if (typeof event.pageX != "undefined" && typeof event.x != "undefined")
  {
    cursorPosition[0] = event.pageX;
    cursorPosition[1] = event.pageY;
  }
  else
  {
    cursorPosition[0] = event.clientX + scrollingPosition[0];
    cursorPosition[1] = event.clientY + scrollingPosition[1];
  }

  tip.style.position = "absolute";
  tip.style.left = cursorPosition[0] + 10 + "px";
  tip.style.top = cursorPosition[1] + 10 + "px";
  tip.style.visibility = "hidden";

  document.getElementsByTagName("body")[0].appendChild(tip);

  var viewportSize = getViewportSize();

  if (cursorPosition[0] - scrollingPosition[0] + 10 + tip.offsetWidth > viewportSize[0] - 25)
  {
    tip.style.left = scrollingPosition[0] + viewportSize[0] - 25 - tip.offsetWidth + "px";
  }
  else
  {
    tip.style.left = cursorPosition[0] + 10 + "px";
  }

  if (cursorPosition[1] - scrollingPosition[1] + 10 + tip.offsetHeight > viewportSize[1] - 25)
  {
    if (event.clientX > (viewportSize[0] - 25 - tip.offsetWidth))
    {
      tip.style.top = cursorPosition[1] - tip.offsetHeight - 10 + "px";
    }
    else
    {
      tip.style.top = scrollingPosition[1] + viewportSize[1] - 25 - tip.offsetHeight + "px";
    }
  }
  else
  {
    tip.style.top = cursorPosition[1] + 10 + "px";
  }

  tip.style.visibility = "visible";

  return true;
}

function hideTip(event)
{
  if (typeof event == "undefined")
  {
    event = window.event;
  }

  var target = getEventTarget(event);

  while (target.className == null || !target.className.match(/(^| )hastooltip( |$)/))
  {
    target = target.parentNode;
  }

  if (target.tooltip != null)
  {
    target.setAttribute("title", target.tooltip.childNodes[0].nodeValue);
    target.tooltip.parentNode.removeChild(target.tooltip);
  }

  return false;
}



function attachEventListener(target, eventType, functionRef, capture)
{
  if (typeof target.addEventListener != "undefined")
  {
    target.addEventListener(eventType, functionRef, capture);
  }
  else if (typeof target.attachEvent != "undefined")
  {
    target.attachEvent("on" + eventType, functionRef);
  }
  else
  {
    eventType = "on" + eventType;

    if (typeof target[eventType] == "function")
    {
      var oldListener = target[eventType];

      target[eventType] = function()
      {
        oldListener();

        return functionRef();
      }
    }
    else
    {
      target[eventType] = functionRef;
    }
  }

  return true;
}

function getEventTarget(event)
{
  var targetElement = null;

  if (typeof event.target != "undefined")
  {
    targetElement = event.target;
  }
  else
  {
    targetElement = event.srcElement;
  }

  while (targetElement.nodeType == 3 && targetElement.parentNode != null)
  {
    targetElement = targetElement.parentNode;
  }

  return targetElement;
}

function getViewportSize()
{
  var size = [0,0];

  if (typeof window.innerWidth != 'undefined')
  {
    size = [
        window.innerWidth,
        window.innerHeight
    ];
  }
  else if (typeof document.documentElement != 'undefined'
      && typeof document.documentElement.clientWidth != 'undefined'
      && document.documentElement.clientWidth != 0)
  {
    size = [
        document.documentElement.clientWidth,
        document.documentElement.clientHeight
    ];
  }
  else
  {
    size = [
        document.getElementsByTagName('body')[0].clientWidth,
        document.getElementsByTagName('body')[0].clientHeight
    ];
  }

  return size;
}

function getScrollingPosition()
{
  //array for X and Y scroll position
  var position = [0, 0];

  //if the window.pageYOffset property is supported
  if(typeof window.pageYOffset != 'undefined')
  {
    //store position values
    position = [
        window.pageXOffset,
        window.pageYOffset
    ];
  }

  //if the documentElement.scrollTop property is supported
  //and the value is greater than zero
  if(typeof document.documentElement.scrollTop != 'undefined'
    && document.documentElement.scrollTop > 0)
  {
    //store position values
    position = [
        document.documentElement.scrollLeft,
        document.documentElement.scrollTop
    ];
  }

  //if the body.scrollTop property is supported
  else if(typeof document.body.scrollTop != 'undefined')
  {
    //store position values
    position = [
        document.body.scrollLeft,
        document.body.scrollTop
    ];
  }

  //return the array
  return position;
}

function getElementsByAttribute(attribute, attributeValue)
{
  var elementArray = new Array();
  var matchedArray = new Array();

  if (document.all)
  {
    elementArray = document.all;
  }
  else
  {
    elementArray = document.getElementsByTagName("*");
  }

  for (var i = 0; i < elementArray.length; i++)
  {
    if (attribute == "class")
    {
      var pattern = new RegExp("(^| )" + attributeValue + "( |$)");

      if (elementArray[i].className.match(pattern))
      {
        matchedArray[matchedArray.length] = elementArray[i];
      }
    }
    else if (attribute == "for")
    {
      if (elementArray[i].getAttribute("htmlFor") || elementArray[i].getAttribute("for"))
      {
        if (elementArray[i].htmlFor == attributeValue)
        {
          matchedArray[matchedArray.length] = elementArray[i];
        }
      }
    }
    else if (elementArray[i].getAttribute(attribute) == attributeValue)
    {
      matchedArray[matchedArray.length] = elementArray[i];
    }
  }

  return matchedArray;
}



function MM_checkPlugin(plgIn, theURL, altURL, autoGo) { //v4.0
  var ok=false; document.MM_returnValue = false;
  with (navigator) if (appName.indexOf('Microsoft')==-1 || (plugins && plugins.length)) {
    ok=(plugins && plugins[plgIn]);
  } else if (appVersion.indexOf('3.1')==-1) { //not Netscape or Win3.1
    if (plgIn.indexOf("Flash")!=-1 && window.MM_flash!=null) ok=window.MM_flash;
    else if (plgIn.indexOf("Director")!=-1 && window.MM_dir!=null) ok=window.MM_dir;
    else ok=autoGo; }
  if (!ok) theURL=altURL; if (theURL) window.location=theURL;
}

// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 8;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
// the version of javascript supported
var jsVersion = 1.0;
// -----------------------------------------------------------------------------
// -->


<!-- // Detect Client Browser type
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
jsVersion = 1.1;
// JavaScript helper required to detect Flash Player PlugIn version information
function JSGetSwfVer(i){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      		var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
      		versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      	} else {
			flashVer = -1;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	// Can't detect in all other cases
	else {
		
		flashVer = -1;
	}
	return flashVer;
} 
// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) 
{
 	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
   	// loop backwards through the versions until we find the newest version	
	for (i=25;i>0;i--) {	
		if (isIE && isWin && !isOpera) {
			versionStr = VBGetSwfVer(i);
		} else {
			versionStr = JSGetSwfVer(i);		
		}
		if (versionStr == -1 ) { 
			return false;
		} else if (versionStr != 0) {
			if(isIE && isWin && !isOpera) {
				tempArray         = versionStr.split(" ");
				tempString        = tempArray[1];
				versionArray      = tempString .split(",");				
			} else {
				versionArray      = versionStr.split(".");
			}
			versionMajor      = versionArray[0];
			versionMinor      = versionArray[1];
			versionRevision   = versionArray[2];
			
			versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			versionNum        = parseFloat(versionString);
        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
			if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
				return true;
			} else {
				return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );	
			}
		}
	}	
}
