/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function isDelete(name){
	return confirm( " هل انت متأكد من رغبتك في حذف " +"( "+name+" )"+"ا");
}
function isConfirm(msg){
	return confirm( msg );
}
function isDeleteFromBook(){
    return confirm(" هل أنت متأكد من رغبتك في حذف هذه المشاركة");
}

function popupPen(page, value){
    if(value!=0){
        popup(page);
    }
}
function popup(page) {
    var browser = navigator.appName;
    var width;
    if(browser=="Netscape"){
        width=720;
    }else{
        width=740;
    }
    windowprops = "scrollbars=yes,menubars=yes,toolbars=yes,resizable=no,height=700,width="+width;
    var newWindow;
    newWindow= window.open(page, "Popup", windowprops);
    if (window.focus) {newWindow.focus()} 
}

function popup2(form, page,width,height) {
    windowprops = "scrollbars=yes,menubars=yes,toolbars=yes,resizable=no,height="+height+",width="+width;
    var newWindow;
    var param="?email="+form.email.value+"&type="+form.type.value;
    newWindow= window.open(page+param, "Popup2", windowprops);
    if (window.focus) {newWindow.focus()} 
}

function back(){
    history.go(-1);
}
function goPage(page){
	window.location=page;
}
function goTo(page){
	//if (!window.event.ctrlKey) return;
	goPage(page);
}
function setDisplay(v, idField){
	document.getElementById(idField).style.display=v;
}
function trim(field) {
	var TRIM_VALUE=field.value;
	if(TRIM_VALUE.length < 1) {
		return "";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);

	field.value=TRIM_VALUE;
}

function RTrim(VALUE) {
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";

	if(v_length < 0) {
		return "";
	}
	var iTemp = v_length -1;

	while(iTemp > -1) {
		if(VALUE.charAt(iTemp) == w_space){}
		else {
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	}
	return strTemp;
}

function LTrim(VALUE) {
	var w_space = String.fromCharCode(32);

	if(v_length < 1) {
		return "";
	}
	var v_length = VALUE.length;
	var strTemp = "";
	var iTemp = 0;

	while(iTemp < v_length) {
		if(VALUE.charAt(iTemp) == w_space){}
		else {
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	}
	return strTemp;
}


/*
 *
لاضافة تعليقات على المقالات في جريدة الرياض
 * 
 */

// ==== Open window in screen center ====
 function rnp_open_window(name,width,height) {
	 x= (screen.availWidth-width)/2
	 y= (screen.availHeight-height)/2
   window.open('',name,'width='+width+',height='+height+',screenX='+x+',screenY='+y)
	 return true
}


// ==== Show or Hide Element ====
function showhide(el) {
  els = el.split(',')
  for(i=0;i<els.length;i++) {
    el=document.getElementById(els[i]);
    el.style.display=(el.style.display=="none")?"":"none";
  }  
}


// ==== Get Cookie ====
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return '';
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}


// ==== Open Comment Window ====
function open_comment_window(window_name) {

  f = document.comment_post

  end = ';path=/;expires=Fri, 29 Oct 2020 16:28:58 UTC';
  document.cookie = 'comment_author='+escape(f.name.value)+end
  document.cookie = 'comment_email='+escape(f.email.value)+end

  f.submit.disabled=true
  f.submit.value="تم الارسال"


  rnp_open_window(window_name, 330, 380)   
}


// ==== Show Comment Form ====
function show_comment_form() {
  f = document.comment_post
	
  showhide('post_form');
  if (f.name.value=='') {
    f.name.value  = getCookie('comment_author');
    f.email.value = getCookie('comment_email');
    f.name.focus();
  } else {	 
    f.subject.focus();
	}	
  return false;
}



 <!--
/****************************************************
     Created With: PopupGenerator
     URL: http://www.popupgenerator.com
	 By Turki
****************************************************/
var win=null;
function NewWindow(mypage,myname,w,h,pos,infocus){
if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20}
settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=no";win=window.open(mypage,myname,settings);
win.focus();}
// -->




var NS4 = (document.layers);    // Which browser?
var IE4 = (document.all);

var win = window;    // window to search.
var n   = 0;

function findInPage(str) {

  var txt, i, found;

  if (str == "")
    return false;

  // Find next occurance of the given string on the page, wrap around to the
  // start of the page if necessary.

  if (NS4) {

    // Look for match starting at the current point. If not found, rewind
    // back to the first match.

    if (!win.find(str))
      while(win.find(str, false, true))
        n++;
    else
      n++;

    // If not found in either direction, give message.

    if (n == 0)
      alert("Not found.");
  }

  if (IE4) {
    txt = win.document.body.createTextRange();

    // Find the nth match from the top of the page.

    for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
      txt.moveStart("character", 1);
      txt.moveEnd("textedit");
    }

    // If found, mark it and scroll it into view.

    if (found) {
      txt.moveStart("character", -1);
      txt.findText(str);
      txt.select();
      txt.scrollIntoView();
      n++;
    }

    // Otherwise, start over at the top of the page and find first match.

    else {
      if (n > 0) {
        n = 0;
        findInPage(str);
      }

      // Not found anywhere, give message.

      else
        alert("Not found.");
    }
  }

  return false;
}



function check_length(my_form)
{
maxLen = 500; // max number of characters allowed

if (my_form.comment.value.length >= maxLen) {
// Alert message if maximum limit is reached.
// If required Alert can be removed.
// var msg = "You have reached your maximum limit of characters allowed";
var msg = "عفواً ... تجاوزت عدد الحروف المسموح بها وهى 500 حرف";
alert(msg);
// Reached the Maximum length so trim the textarea
my_form.comment.value = my_form.comment.value.substring(0, maxLen);
}
else{ // Maximum length not reached so update the value of GoYouNote counter
my_form.text_num.value = maxLen - my_form.comment.value.length;}
}