// DM - 11-13-2008 edit : changeSubTabDisplay
// PC - Photo Upload Optimization
var img_src_dir = "/zones-ssi/js-css-images/top-nav/"	
	/*
	 *	function to set the timeout for active subtab to close
	 *
	 * @param  string  tabId		Top tab id which will get activated on clicking Page link
	 * @return
	 *
	 * @usage $var_name = function_name($param);
	*/
	var t
	function subTabTimeout(subtabId){
		clearTimeout(t);
		t = setTimeout("changeSubTabDisplay("+subtabId+")",30000); 

	}

	function changeSubTabDisplay(subtabId) {
		var parent = subtabId.parentNode.className
		if(checkIfTabActive(parent)){ 
//DM			if(!checkIfTabPageActive(parent)){
				//active tab but not selected
				subtabId.parentNode.className = parent.replace("active","")
				var imgId =  "arrow" + subtabId.id.replace("sub","")
				var imgEl = document.getElementById(imgId)
				imgEl.src = img_src_dir + "arw-normal-01.gif"
		
//DM			}
			subtabId.style.display = "none";
		}
		//clear the timeout variable
		clearTimeout(t);
		
	}
// FUNCTION ADDED BY DHANESH M
function changetab(tabId,action)
{
		var tabEl = document.getElementById(tabId).parentNode;
		if(action==1)
			{
			tabEl.className = tabEl.className+" active";
//document.getElementById("arrow"+tabId).src='/zones-ssi/js-css-images/top-nav/arw-hover-01.gif';
			}
		else
		{
			tabEl.className = tabEl.className.replace("active","");
//document.getElementById("arrow"+tabId).src='/zones-ssi/js-css-images/top-nav/arw-normal-01.gif';
		}
}
	function imageMouseOut(imgId,tabId)	{
		var tabEl = document.getElementById(tabId).parentNode;
		var imgEl = document.getElementById(imgId);
		//dm st
		subtab = document.getElementById('sub'+tabId);
			try
			{
				if(subtab.style.display!='block') 
					changetab(tabId,2); 
			}
			catch (e)
			{
				changetab(tabId,2); 
			}
		//dm en
//		if(tabEl.className.match("active") || tabEl.className.match("page active") ){	
//			imgEl.src = img_src_dir + "arw-hover-01.gif" 
//			clearTimeout(t);
//			subTabTimeout("sub" + tabId)
//		}
//		else{	
			imgEl.src = img_src_dir + "arw-normal-01.gif"	
//		}
	}
	function imageHover(imgId,tabId){
		var tabEl = document.getElementById(tabId).parentNode
		var imgEl = document.getElementById(imgId)
		if(tabEl.className.match("active") || tabEl.className.match("page active") ){	
			imgEl.src = img_src_dir + "arw-hover-active-01.gif" 
		}
		else{	
			imgEl.src = img_src_dir + "arw-hover-01.gif";
			changetab(tabId,1); // dm
		}
	}

	/**
	 * function to return the type of top tab  "active" or "page active"
	 * "active" tab			- when the arrow image is clicked to view the dropdown
	 * "page active" tab	- the current page, when the user clicks the toptab link the tab	                          becomes "page active"
	 *
	 * @return
	 *
	 * @usage $var_name = function_name($param);
	*/
	function checkIfTabPageActive(tabParentClass){
		//returns not null value if the tab is page active
		return tabParentClass.match("page active")
	}

	function checkIfTabActive(tabParentClass){
		//returns not null value if the tab is active
		return tabParentClass.match("active")
	}

	/**
	 * function to set the temporary active tab
	 *
	 * @param  string  tabId		Top tab id which will get activated on clicking Page link
	 * @return
	 *
	 * @usage $var_name = function_name($param);
	*/

	function setPageActiveTopTab(tabId)	{
		//clear the timeout variable
		clearTimeout(t)
		/* browse all toptabs and set the page active tab
		 * set all the other to tabs to in-active state
		 */
		for(var i = 0; i<allTopTabs.length; i++){
			var getParentDiv = allTopTabs[i].parentNode
			var class_name = getParentDiv.className
			if(allTopTabs[i].id == tabId){
				//check if tab already active
				if(checkIfTabActive(class_name)){
					class_name = class_name.replace("page","")
					class_name = class_name.replace("active","")
					class_name = class_name.replace("droptrue","")
				}

				//set page active tab
				if(!checkIfTabPageActive(class_name)){
					getParentDiv.className = class_name + " page active droptrue"
				}
				subtab = allTopTabs[i].getAttribute("rel")

				//set active arrow
				var arrow = document.getElementById("arrow"+tabId)
				arrow.src = img_src_dir + "arw-hover-01.gif"
				
			}
			else{
			   //set other tabs to in-active
			   if(class_name.match("active")){
					class_name = class_name.replace("active","")
				}
			   if(class_name.match("page"))	{
				   class_name = class_name.replace("page","")
				}
				if(class_name.match("droptrue"))	{
				   class_name = class_name.replace("droptrue","")
				}

			   	getParentDiv.className = class_name
				//set in-active arrow
				var arrow = document.getElementById("arrow"+allTopTabs[i].id)
				arrow.src = img_src_dir + "arw-normal-01.gif"
			}//end of else
		}

		/* hide all subtabs */
		for(var i=0;i<allSubTabs.length;i++){
		  	allSubTabs[i].style.display="none"
		}
	}

	/*
		store all the toptabs and subtabs in their respective arrays
		required to be used by other functions
	*/
	
	var allTopTabs = []
	var allSubTabs = []
	
	function onloadAllTabs()
	{
		var container_div = document.getElementById("logo-search-container");
		var topnav_panel = document.getElementById("toptab-panel");
		var topnav_parent = document.getElementById("topnav-parent");
		var ad_container_div = document.getElementById("ad-container");
		
		//to take care of window resizing
		
		if(screen.width >= 1024){
				container_div.style.width =  "998px";
				topnav_panel.style.width = "990px";
				topnav_parent.style.width = (screen.width - 21) + "px";
				ad_container_div.style.width = (screen.width - 21) + "px";
		}
		else{
				container_div.style.width =  "770px";
				topnav_panel.style.width = "760px";
				topnav_parent.style.width = "1000px";
				ad_container_div.style.width = "1000px";
		}

		var panel = document.getElementById("toptab-panel").getElementsByTagName("div")
		//set the all the toptabs and subtabs in respective arrays	
		for(var i=0;i<panel.length;i++){
		  if(panel.item(i).getAttribute( 'name' ) == 'toptab' ){
			allTopTabs.push( panel.item(i) );
		  }
		   if(panel.item(i).getAttribute( 'name' ) == 'subtab' ){
			allSubTabs.push( panel.item(i) );
		  }
		}		
	}

	function closeDropdownMenus(ev)
	{
		//close dropdown menu when clicked elsewhere
		var node =(typeof event!=='undefined')? event.srcElement : ev.target
		
		while (node && !node.id)
		{
			node = node.offsetParent;
		}
		
		if(node && node.id.match("arrowtab"))
		{
			var tabstr = node.id.replace("arrow","");
			tabstr = "sub" + tabstr
		}
		for(var i = 0; i<allSubTabs.length; i++){
			if(allSubTabs[i].id == tabstr)
				continue;
			changeSubTabDisplay(allSubTabs[i])
		}
	}
	if (window.captureEvents)
	{
		window.captureEvents(Event.CLICK);
		window.onclick=closeDropdownMenus;
	}
	else
	{
		document.onclick=closeDropdownMenus;
	}
	
	//if there are existing onload functions,execute them

	/*function addLoadEvent(func) { 
		  var oldonload = window.onload; 
		  if (typeof window.onload != 'function') { 
			window.onload = func; 
		  } else { 
			window.onload = function() { 
			  if (oldonload) { 
				oldonload(); 
			  } 
			  func(); 
			} 
		  } 
	} 
		 
	addLoadEvent(onloadAllTabs); */



	/**
	 * function to set the temporary active tab
	 *
	 * @param  string  tabId		Top tab id which will get activated on clicking arrow img
	 * @return
	 *
	 * @usage $var_name = function_name($param);
	*/
	function setActiveTopTab(tabId)	{
		//clear the timeout variable
		clearTimeout(t)
		/*
			browse all toptabs
			if page active tab, leave it as it is
			if any other tab is active , deactivate it 
			set the selected tab to active state
		*/
		var subtab
		for(var i = 0; i<allTopTabs.length; i++){
			var getParentDiv = allTopTabs[i].parentNode
			var class_name = getParentDiv.className
			if(allTopTabs[i].id == tabId){
				
				//set active arrow
				var arrow = document.getElementById("arrow"+tabId)

				//if active page
				if(checkIfTabPageActive(class_name)){
					getParentDiv.className = class_name.replace("droptrue","")
					arrow.src = img_src_dir + "arw-hover-01.gif"
				}
				//set active tab
				else if(!checkIfTabActive(class_name)){
					getParentDiv.className = class_name + " active"
					arrow.src = img_src_dir + "arw-hover-01.gif"
				}
				else
				{
					getParentDiv.className = class_name.replace("active","")
					arrow.src = img_src_dir + "arw-normal-01.gif"
				}
				subtab = allTopTabs[i].getAttribute("rel")

			}
			else{
				if(!getParentDiv.className.match("page")){
					getParentDiv.className = class_name.replace("active","")
			   		//set in-active arrow
					var arrow = document.getElementById("arrow"+allTopTabs[i].id)
					arrow.src = img_src_dir + "arw-normal-01.gif"
				}
				if(checkIfTabPageActive(class_name) && !class_name.match("droptrue")){
					getParentDiv.className = class_name + " droptrue"
				}
			}//end of else
		}

		/*
			browse all subtabs 
			if the subtab is of the selected top tab, toggle its display 
			hide all other subtabs
		*/
		for(var i = 0; i<allSubTabs.length; i++){
			if(allSubTabs[i].id == subtab){
				//set active sub tab
				if( allSubTabs[i].style.display == "none" ||
					allSubTabs[i].style.display == "" )	{
					allSubTabs[i].style.display="block"
				}
				else{
					allSubTabs[i].style.display="none"
				}//end of else
			}
			else{
				allSubTabs[i].style.display="none"
			}//end of else
		}
	}

	function video_error_div_display(div_id, fade_div_id, width, height,Z_IMAGE_SITE_NAME)
	{
		if(width == undefined)
			width = 500;

		if(height == undefined)
			height = 550;

		//alert(fade_div_id);
		var hrefDiv = document.getElementById(fade_div_id);

		var bheight = document.body.clientHeight;
		var bwidth = document.body.clientWidth;		
		//alert("Body Height " + bheight);
		//alert("Body Width " + bwidth);

		// alert(document.documentElement.clientHeight);
		// alert(document.documentElement.clientWidth);

		//alert(document.all['body'].offsetHeight);
		//alert(document.all['body'].offsetWidth);

		//alert(window.innerWidth);
		//alert(window.innerHeight);

		// alert(document.getElementsByTagName('body')[0].clientWidth);
		// alert(document.getElementsByTagName('body')[0].clientHeight);

		var layr_ht = hrefDiv.offsetHeight;
		var layr_wd = hrefDiv.offsetWidth;

		//alert("layer Height : " + layr_ht);
		//alert("layer Width : " + layr_wd);

		if(document.getElementById(div_id))
			document.getElementById(div_id).style.display = 'block';
		
		if(document.getElementById(fade_div_id))
		{
			document.getElementById(fade_div_id).style.display = 'block';
			document.getElementById('frame_video_layer').style.display='block';
		}
		// var layer_heading_str = "Choose recipients using an option below:";

		
		share_str = "<span class=\"right large\" style=\"margin-top: -10px;\"><a href=\"#\" onclick = \"document.getElementById('"+div_id+"').style.display='none';document.getElementById('"+fade_div_id+"').style.display='none';document.getElementById('frame_video_layer').style.display='none';\" class=\"noborder\">Close [ X ]</a></span><br clear=\"all\"><img src=\""+ Z_IMAGE_SITE_NAME+"/zones-images/videos/video-image.jpg\" width=\"72\" height=\"70\" border=\"0\" vspace=\"0\" hspace=\"0\" align=\"left\" style=\"margin-right: 8px;\">We are upgrading our features to make your Fropper Videos experience more exciting. As a result, this section has been temporarily disabled.";
		
		document.getElementById(div_id).innerHTML = share_str;

		return false;
	}

	function display_layer_center_video(obj_div)
{

	//alert("Hi");
	//alert(obj_div);
	var hrefDiv = document.getElementById(obj_div);
	hrefDiv.style.display = "block";

	//hrefDiv.innerHTML = "<div id=\"error_div\"></div><div></div>";
	hrefDiv.innerHTML = "";

	var bheight = document.body.clientHeight;
	var bwidth = document.body.clientWidth;		
	//alert("Body Height " + bheight);
	//alert("Body Width " + bwidth );

	//alert("Scrolling");
	var scrolly = document.body.scrollTop;
	var scrollx = document.body.scrollLeft;
	//alert("Page y :" + scrolly);
	//alert("page x :" + scrollx);

	//alert("Layer Div");	
	
	//hrefDiv.style.display = "block";
	
	var layr_ht = hrefDiv.offsetHeight;
	var layr_wd = hrefDiv.offsetWidth;
	//alert("layer Height : " + layr_ht);
	//alert("layer Width : " + layr_wd);


	var aa = Math.ceil(layr_ht/2);
	var bb = Math.ceil(layr_wd/2);
 	//alert("layer center height " + aa);
	//alert("layer center width" + bb);
	
	var c = Math.ceil(bheight/2);
	var d = Math.ceil(bwidth/2);
	//alert("body center h pos : " + c);
	//alert("body center x pos : " + d);


	var disp_layer_top_st = c + scrolly - aa ;
	var disp_layer_width_st = d + scrollx - bb;
	//alert("pos top" + disp_layer_top_st);
	//alert("pos left" + disp_layer_width_st);
	
	//for Mozilla
	hrefDiv.setAttribute("style","display: block;position: absolute ;top: "+disp_layer_top_st+"px;left: "+disp_layer_width_st+"px; border: 6px solid #333333; z-index:1010; background: #ffffff;");

	//for IE
	hrefDiv.style.cssText = "display: block;position: absolute ;top: "+disp_layer_top_st+"px;left: "+disp_layer_width_st+"px; border: 6px solid #333333; z-index:1010; background: #ffffff;";
}//EO

	function findPosVideo(obj) {
	if(obj)
	{
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
		

		document.getElementById('fade_video_layer').style.height = curtop;
		// document.getElementById('fade_id').style.display = 'block';
	}
}

function optimize_photo_div_display(div_id,fade_id,frm_id,z_image_site_name_url,visitor_mode)
{
	if(document.getElementById(div_id))
	{
		document.getElementById(div_id).style.display = 'block';
	}

	if(document.getElementById(frm_id))
	{
		document.getElementById(frm_id).style.display = 'block';
	}

	if(document.getElementById(fade_id))
	{
		document.getElementById(fade_id).style.display = 'block';
	}

	var optimize_photo_layer_str = "<form name=\"frmUploadPhotosImageSizeType\" action=\"/z/photos/upload-photos.php\" method=\"post\" enctype=\"multipart/form-data\"><div style=\"border: 6px solid #333333; padding: 15px; padding-bottom: 0px;\"><div><span class=\"left\"><span class=\"oes head1\">&#187;</span> <span class=\" head2\">Upload Photos</span></span><span class=\"right\"><a href=\"#\" onclick=\"close_opt_photo_block('"+div_id+"','"+fade_id+"','"+frm_id+"');return false;\" class=\"noborder\">Close</a> [<a href=\"#\" onclick=\"close_opt_photo_block('"+div_id+"','"+fade_id+"','"+frm_id+"');return false;\" class=\"noborder\">x</a>]</span> </div><br clear=\"all\"><div class=\"large\" style=\"background: url('"+z_image_site_name_url+"/zones-images/photos/blue-bg-small.gif') repeat-x top center; padding: 10px;_height:100%;\"><div class=\"large\" style=\"text-align:;\"><b>Please select one of the following options:</b><br><br style=\"line-height:8px;\"><div class=\"left\"><input type=\"radio\" name=\"photo_reduce_type\" value=\"optimal_size\" style=\"margin: 0px; padding: 0px;\" checked></div><div class=\"left\" style=\"width: 265px;margin-left: 5px;\" >Web Quality ( Suitable for quick upload, fast web viewing and small/medium prints )</div><Br><Br><br style=\"line-height:15px;\"><div class=\"left\"><input type=\"radio\" name=\"photo_reduce_type\" value=\"original_size\" style=\"margin: 0px; padding: 0px;\"></div><div class=\"left\" style=\"width: 265px;margin-left: 5px;\">High Quality  ( Suitable for wallpaper and large prints )</div><Br><br></div><br style=\"line-height:15px;\"><input type=\"submit\" class=\"smlbutton\" value=\"PROCEED &nbsp; &nbsp; &nbsp;\" style=\"width:90px;margin-left: 25px;\"><br><br><br clear=\"all\"></div></div></form>";
	
	document.getElementById(div_id).innerHTML = optimize_photo_layer_str;

	return false;
}

function show_opt_photo_block(obj_div,dv_width)
{
	var hrefDiv = document.getElementById(obj_div);
	hrefDiv.style.display = "block";

	var bheight = document.body.clientHeight;
	var bwidth = document.body.clientWidth;

	var scrolly = document.body.scrollTop;
	var scrollx = document.body.scrollLeft;
	
	var layr_ht = hrefDiv.offsetHeight;
	var layr_wd = hrefDiv.offsetWidth;

	var aa = Math.ceil(layr_ht/2);
	var bb = Math.ceil(layr_wd/2);
	
	var c = Math.ceil(bheight/2);
	var d = Math.ceil(bwidth/2);


	var disp_layer_top_st = c + scrolly - aa ;
	var disp_layer_width_st = d + scrollx - bb;

	//alert(disp_layer_top_st)
	//alert(disp_layer_width_st)

	//for Mozilla
	hrefDiv.setAttribute("style","display: block;position: absolute ;top: "+disp_layer_top_st+"px;left: "+disp_layer_width_st+"px; width:"+dv_width+"px; height:border: 6px solid #333333; z-index:1010; background: #ffffff;");

	
	//for IE
	hrefDiv.style.cssText = "display: block;position: absolute ;top: "+disp_layer_top_st+"px;left: "+disp_layer_width_st+"px; width:"+dv_width+"px; height: border: 6px solid #333333; z-index:1010; background: #ffffff;";

}//EO

function close_opt_photo_block(div_id,fade_id,frm_id)
{
	if(document.getElementById(div_id))
	{
		document.getElementById(div_id).style.display = 'none';
	}

	if(document.getElementById(fade_id))
	{
		document.getElementById(fade_id).style.display = 'none';
	}

	if(document.getElementById(frm_id))
	{
		document.getElementById(frm_id).style.display = 'none';
	}
	return false;
}

function findPosOptPhoto(last_div,fade_id,frm_id)
{
	if(document.getElementById(last_div))
	{
		obj = document.getElementById(last_div);
	}
	if(obj)
	{
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
		document.getElementById(fade_id).style.height = curtop;
		document.getElementById(frm_id).style.height = curtop;
		document.getElementById(fade_id).style.display = 'block';
		document.getElementById(frm_id).style.display = 'block';
	}
}

function RedirectToLogin(anchor_link)
{
	window.location.href = '/z/login/login.php?go='+encodeURIComponent(anchor_link);
}//EOF