﻿
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

   

    function NextPhotoGallery() {
        document.getElementById("PhotoGallery").innerHTML = "<div class='Direction' align='center'>در حال خواندن ...</div>";
        gallerypage++;
        Controls_GalleryPlaceHolder.GetPhotos(gallerypage,lang,pagesize,ShowPhotoGallery_CallBack) ;
    }
    function PrvPhotoGallery() {
        document.getElementById("PhotoGallery").innerHTML = "<div class='Direction' align='center'>در حال خواندن ...</div>";
        gallerypage--;
        Controls_GalleryPlaceHolder.GetPhotos(gallerypage,lang,pagesize,ShowPhotoGallery_CallBack) ;
    }
    
    function ShowPhotoGallery() {
        document.getElementById("PhotoGallery").innerHTML = "<div class='Direction' align='center'>در حال خواندن ...</div>";
        Controls_GalleryPlaceHolder.GetPhotos(gallerypage,lang,pagesize,ShowPhotoGallery_CallBack) ;
    }
    
    function ShowPhotoGallery_CallBack(resp) {
        
        if (resp.value.indexOf('~') > -1) {
        	gallerypage = resp.value.substring(0,resp.value.indexOf('~')) ;
		     document.getElementById("PhotoGallery").innerHTML = resp.value.substring(resp.value.indexOf('~') + 1);
    	}
	    else {
    		document.getElementById("PhotoGallery").innerHTML = resp.value;
	    }
    }
function eraseCookie(name) {
	createCookie(name,"",-1);
}
 function ChangeTheme(name){
        document.styleSheets[0].href = "App_Themes/" + name + "_"+lang+"/Default.css";
        createCookie("NofaTheme",name,100000);
        
    }
    function Goto(url) {
        location.href = url;
    }
    
        
function getChildById(tagName,element,id)
{
    var childerns = element.getElementsByTagName(tagName);
    for(i = 0 ; i < childerns.length ; i++) {
        if(childerns[i].id == id)
            return childerns[i];
    }

	return null;
};    
function getElementChildren (element)
{
	var children = [];
	var child = element.firstChild;
	
	while (child)
	{
		if (child.nodeType == 1 /* Node.ELEMENT_NODE */)
			children.push(child);
		child = child.nextSibling;
	}
	return children;
};

function is_child_of(parent, child) {
			if( child != null ) {			
				while( child.parentNode ) {
					if( (child = child.parentNode) == parent ) {
						return true;
					}
				}
			}
			return false;
		}
		function fixOnMouseOut(element, event, JavaScript_code) {
			var current_mouse_target = null;
			if( event.toElement ) {				
				current_mouse_target 			 = event.toElement;
			} else if( event.relatedTarget ) {				
				current_mouse_target 			 = event.relatedTarget;
			}
			if( !is_child_of(element, current_mouse_target) && element != current_mouse_target ) {
				eval(JavaScript_code);
			}
		}
