// JavaScript Document
function open_calendar_window(mode)
{
	window.open("includes/calendar_popup.php?mode="+mode,"calendar","width=125,height=175,top=200,left=560,scrollbars=no");
}

function image_preview(file_name)
{
	window.open("image_preview.php?file_name="+file_name,"img_preview","width=500,height=410,top=100,left=250,scrollbars=yes;resize=yes");
}

function video_preview(file_name)
{
	window.open("video_preview.php?file_name="+file_name,"vid_preview","width=500,height=380,top=100,left=250,scrollbars=yes;resize=yes");
}

function end_date(d)
{
	split_date="";
	split_date=d.split("-");
	
	frm.end_date.value=split_date[2]+"-"+split_date[1]+"-"+split_date[0];
}

function generate_upload(loop)
{
	if(loop<=0)
	frm.upload_num.value=1;
	else
	frm.upload_num.value=loop;
	
	if(loop>0)
	{
	i=0;
	upload_contents="";
	upload_contents=upload_contents+"<table width=100% border=0  cellpadding=0 cellspacing=0 >";
	for(i=0;i<loop;i++)
	{
	upload_contents=upload_contents+"<tr><td><table width=100% border=0 cellpadding=0 cellspacing=0><tr> ";
	upload_contents=upload_contents+"<td><input name=image"+i+" type=file size=55></td></tr></table></td></tr>";
	}
	upload_contents=upload_contents+"</table>";
	uploads.innerHTML=upload_contents;
	}
}

function generate_slideshow(loop)
{
	if(loop==0)
	frm.upload_num.value=1;
	else
	frm.upload_num.value=loop;
	
	if(loop>0)
	{
		i=0;
		upload_contents="";
		upload_contents=upload_contents+"<table width=100% border=0  cellpadding=0 cellspacing=0 >";
		for(i=0;i<loop;i++)
		{
			upload_contents=upload_contents+"<tr>";
			upload_contents=upload_contents+"<td class=normal_text>Image Name:</td>";
			upload_contents=upload_contents+"<td><input name=image"+i+" type=file size=36></td>";
			upload_contents=upload_contents+"</tr>";
		}
		upload_contents=upload_contents+"</table>";
		uploads.innerHTML=upload_contents;
	}
}

function delete_library(id,category,offset)
{
	return_confirm=confirm("Are you sure that you want to delete this library?");
	if(return_confirm==true)
	{
		window.location="libraries.php?id="+id+"&category="+category+"&offset="+offset+"&mode=delete";
	}
}

function delete_project(id,category,offset)
{
	return_confirm=confirm("Are you sure that you want to delete this Project?");
	if(return_confirm==true)
	{
		window.location="projects.php?id="+id+"&category="+category+"&offset="+offset+"&mode=delete";
	}
}

function delete_product(id)
{
	return_confirm=confirm("Are you sure that you want to delete this Product?");
	if(return_confirm==true)
	{
		window.location="products.php?id="+id+"&mode=delete";
	}
}


function delete_module_category(page_name,id)
{
	return_confirm=confirm("Are you sure that you want to delete this category?");
	if(return_confirm==true)
	window.location=page_name+"?id="+id+"&delete_category=1";
}

function check_authentication(image_code)
{
	if(ccoptin.ea.value=="") 
	{
		alert("Please enter the E-mail address");
		ccoptin.ea.focus();
	}
	else
	if(ccoptin.ea.value.indexOf("@",1)==-1) 
	{
		alert("Invalid E-mail address");
		ccoptin.ea.focus();
	}
	else
	if(ccoptin.ea.value.indexOf("@",1)==0) 
	{
		alert("Invalid E-mail address");
		ccoptin.ea.focus();
	}
	else
	if(ccoptin.ea.value.indexOf("@",ccoptin.ea.value.indexOf("@",1)+1)>-1) 
	{
		alert("Invalid E-mail address");
		ccoptin.ea.focus();
	}
	else
	if(ccoptin.ea.value.indexOf(".",ccoptin.ea.value.indexOf("@",1)+2)==-1)	
	{
		alert("Invalid E-mail address");
		ccoptin.ea.focus();
	}
	else		
		ccoptin.submit();
			
}

function print_library(id)
{
	window.open("print_library.php?id="+id,"print_library","width=600,height=550,top=100,left=250,scrollbars=yes");
}

function email_library(id)
{
	window.open("email_library.php?id="+id,"email_library","width=600,height=550,top=100,left=250,scrollbars=yes");
}

function print_news(id)
{
	window.open("print_news.php?id="+id,"print_news","width=600,height=550,top=100,left=250,scrollbars=yes");
}

function email_news(id)
{
	window.open("email_news.php?id="+id,"email_news","width=600,height=550,top=100,left=250,scrollbars=yes");
}

function clear_intro_text()
{
	if(frm.keywords_idntify.value=="") 
	{
		frm.keywords.value="";
		frm.keywords_idntify.value=1;
	}
}

function show_hide_menu(link_id,menu_id,left,top)
{ 
	offset_left=calculateSumOffset(link_id,'offsetLeft')+left;
	offset_top=calculateSumOffset(link_id,'offsetTop')+top;
	if (menu_id.style.visibility == "hidden")
	 { 
		menu_id.style.left=offset_left;
		menu_id.style.top= offset_top+parseInt(link_id.height);
		menu_id.style.visibility = "visible";
	 } 
	else 
	 { 
		menu_id.style.visibility = "hidden";
	 } 
}

function calculateSumOffset(idItem, offsetName)
{
	var totalOffset = 0;
	var item = eval('idItem');
	do
	{
		totalOffset += eval('item.'+offsetName);
		item = eval('item.offsetParent');
	} while (item != null);
	return totalOffset;
}