/* start right marquee code */

var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;

(function($){$(document).ready(function(){
  headline_count = $("div.headline").size();
  $("div.headline:eq("+current_headline+")").css('top','5px');
  
  headline_interval = setInterval(headline_rotate,5000); //time in milliseconds
  
});

function headline_rotate() {
  current_headline = (old_headline + 1) % headline_count; 
  $("div.headline:eq(" + old_headline + ")").animate({top: -205},"slow", function() {
    $(this).css('top','210px');
    });
  $("div.headline:eq(" + current_headline + ")").show().animate({top: 5},"slow");  
  old_headline = current_headline;
}

})(jQuery)

/* ================================================= end right marquee code ============================================== */

// used to clone a node
function clone(nodeId, deep)
{
	if(!deep) 	deep = true;
	var toClone = document.getElementById(nodeId);
	var clonedNode = toClone.cloneNode(deep);
	return clonedNode;
}

// remove element from the page
function removeElement(parentId, childId) {
  var parent = document.getElementById(parentId);
  var child = document.getElementById(childId);
  parent.removeChild(child);
}

function appendAfter(nodeId, newNode)
{
	var node = document.getElementById(nodeId);
	if (node.parentNode)
	{
		if (node.nextSibling)
		node.parentNode.insertBefore(newNode, node.nextSibling);
		else
		node.parentNode.appendChild(newNode);
	}
}

function appendBefore(nodeId, newNode)
{
	var node = document.getElementById(nodeId);
	if (node.parentNode)
	{
		node.parentNode.insertBefore(newNode, node);
	}
}

// this function to show or hide any element
function toggleElementDisplay(id)
{
	var el = document.getElementById(id);
	if(el.style.display != "none")	el.style.display = "none";
	else							el.style.display = "";
}

function show(id) {
	$(id).style.display = '';
}

function hide(id) {
	$(id).style.display = 'none';
}

// it warks like the php function
function in_array(needle, haystack, strict) {
 
    var found = false, key, strict = !!strict;
 
    for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            found = true;
            break;
        }
    }
 
    return found;
}


// it warks like the php function
function is_array(mixed_var) {
 
    return (mixed_var instanceof Array);
}


function str_replace(haystack, needle, replacement) {
	var temp = haystack.split(needle);
	return temp.join(replacement);
}




/** return innerHTML of select tag
@param: sel_id, id of select tag
@param: valarr, array of options values
@param: txtarr, array of options texts
@param: selected_val, array of values to be selected, if the list is multiple or single value to be selected 
*/
function generateList(sel_id, valarr, txtarr, selected_val) {
	var len = valarr.length;
	var opNodes = '';
	var selected = '';
	for(var i = 0; i < len; i++) {		
		if(selected_val) {
			if(selected_val.constructor.toString().indexOf("Array") != -1)	
			{
				if(selected_val.in_array(valarr[i])) selected = 'selected="selected"';
			}
			else if(selected_val == valarr[i])	selected = 'selected="selected"';
		}
		opNodes += "<option value='"+valarr[i]+"' "+selected+">"+txtarr[i]+"</option>";
		selected = '';
	}
return(opNodes);
}

function copyToClipBoard(id){
	if (window.clipboardData) {
		
		var tempval=eval("document.getElementById('"+id+"')")
		tempval.focus()
		tempval.select()
		therange=tempval.createTextRange()
		therange.execCommand("Copy")
		
	} else {
		
	}
}

function text_validator(s) {	
	r = s+'_error'
	if(document.getElementsByName(s)[0].value == "") {
	   show(r);
	   return false;
	}
	else{hide(r); return true}
}

function validateEmail(s)	
{	
	r = s+'_error'
	
	var emailStr = document.getElementsByName(s)[0].value;
	var emailReg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(')|(")/; // not valid
	var emailReg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,6}|[0-9]{1,3})(\]?)$/; // valid
	if (!(!emailReg1.test(emailStr) && emailReg2.test(emailStr))) {// if syntax is valid
		show(r);
		return false;
		}else{hide(r);}
	return true;
}

function increasTelawatListens(id){

	var url = '/wonderful_telawat/increaslistens.php?id='+id;
	
	new Ajax.Request(url, {
		method: 'post'
	});
}

function increasQuranTopicsVisits(id){

	var url = '/quran_topics/increaslistens.php?id='+id;
	
	new Ajax.Request(url, {
		method: 'post'
	});
}

function showThumb(img){
	
	Tip('<div><table border="0" cellpadding="0" cellspacing="0" dir="ltr"><tr><th width="10"><img src="../images/thum_box/top_left.png" border="0" style="vertical-align:bottom" /></th><th style="background-image:url(../images/thum_box/top.png); background-repeat:repeat-x; background-position:bottom"></th><th><img src="../images/thum_box/top_right.png" border="0" style="vertical-align:bottom" /></th></tr><tr><th style="background-image:url(../images/thum_box/left.png); background-repeat:repeat-y"></th><th style="background:#fefeff url(../images/loading_animation.gif) no-repeat center; width:37px; height:37px"><img src="'+img+'" width="104" /></th><th style="background-image:url(../images/thum_box/right.png); background-repeat:repeat-y"></th></tr><tr><th><img src="../images/thum_box/bottom_left.png" border="0" style="vertical-align:top" /></th><th style="background-image:url(../images/thum_box/bottom.png); background-repeat:repeat-x; background-position:top"></th><th><img src="../images/thum_box/bottom_right.png" border="0" style="vertical-align:top" /></th></tr></table></div>', WIDTH, 150);
}

function showArabicHomeTip(text){
	
	Tip('<div style="width:300px;"><table border="0" cellpadding="0" cellspacing="0" width="100%" dir="rtl"><tr><th width="10"><img src="/images/thum_box/top_right.png" border="0" style="vertical-align:bottom" /></th><th style="background-image:url(/images/thum_box/top.png); background-repeat:repeat-x; background-position:bottom"></th><th><img src="/images/thum_box/top_left.png" border="0" style="vertical-align:bottom" /></th></tr><tr><th style="background-image:url(/images/thum_box/right.png); background-repeat:repeat-y"></th><th class="home_nabza" style="background-color:#fefeff; diriction:rtl; font-weight:normal; text-align:right;"><div style="width:278px">'+text+'</div></th><th style="background-image:url(/images/thum_box/left.png); background-repeat:repeat-y"></th></tr><tr><th><img src="/images/thum_box/bottom_right.png" border="0" style="vertical-align:top" /></th><th style="background-image:url(/images/thum_box/bottom.png); background-repeat:repeat-x; background-position:top"></th><th><img src="/images/thum_box/bottom_left.png" border="0" style="vertical-align:top" /></th></tr></table></div>', WIDTH, 300);
}

function showEnglishHomeTip(text){
	
	Tip('<div style="width:300px;"><table border="0" cellpadding="0" cellspacing="0" width="100%" dir="ltr"><tr><th width="10"><img src="/images/thum_box/top_left.png" border="0" style="vertical-align:bottom" /></th><th style="background-image:url(/images/thum_box/top.png); background-repeat:repeat-x; background-position:bottom"></th><th><img src="/images/thum_box/top_right.png" border="0" style="vertical-align:bottom" /></th></tr><tr><th style="background-image:url(/images/thum_box/left.png); background-repeat:repeat-y"></th><th class="home_nabza" style="background-color:#fefeff; diriction:ltr; font-weight:normal; text-align:left;"><div style="width:278px">'+text+'</div></th><th style="background-image:url(/images/thum_box/right.png); background-repeat:repeat-y"></th></tr><tr><th><img src="/images/thum_box/bottom_left.png" border="0" style="vertical-align:top" /></th><th style="background-image:url(/images/thum_box/bottom.png); background-repeat:repeat-x; background-position:top"></th><th><img src="/images/thum_box/bottom_right.png" border="0" style="vertical-align:top" /></th></tr></table></div>', WIDTH, 300);
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function gotoPage(BaseURL, MAX){

	page = jQuery("#paging_field").val();

	if (page !== null && !isNaN(page) && page == Math.floor(page) && page > 0 && page <= MAX){

		document.location.href = BaseURL + page;
	}
}
