// ===================================================================
// Author: Nicholas Watts <njwatts@martechsocial.com>
// WWW: http://www.martechsocial.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// -------------------------------------------------------------------
// HISTORY
/* 
DESCRIPTION: Common Script files to control main aspects of inlondon.com
COMPATABILITY: 
USAGE:
*/
// ===================================================================


function ge()
{var ea;for(var i=0;i<arguments.length;i++){var e=arguments[i];if(typeof e=='string')
e=document.getElementById(e);if(arguments.length==1)
return e;if(!ea)
ea=new Array();ea[ea.length]=e;}
return ea;}

/*
function hide()
{for(var i=0;i<arguments.length;i++){var element=ge(arguments[i]);if(element&&element.style)element.style.display='none';}
return false;}
*/

function showMe(showthis,hidethis) {
var curr = document.getElementById(showthis);
hide(hidethis);
show(showthis);
}

function showhide(id) {
var e = document.getElementById(id);
if(e.style.display == 'none')
e.style.display = 'block';
else
e.style.display = 'none';
}

function btnsubmit() {
var e = document.getElementById('submitbtn');
e.innerHTML = "Please wait";
//e.onclick = "";
}

function setFocus(id) {
	document.getElementById(id).focus();
}

function updreftext(id,str) {
var e = document.getElementById(id);
e.innerHTML = ''+str+'';
e.onclick = "";
}


function uploadmedia(id) {
var e = document.getElementById(id);
if (e.className == 'mediaupload0')
e.className = 'mediaupload1';
else
e.className = 'mediaupload0';
}

function uploadmediasel(id) {
var e = document.getElementById(id);
if (e.className == 'mediauploadsel0')
e.className = 'mediauploadsel1';
else
e.className = 'mediauploadsel0';
}


function mediahighlight(id) {
var e = document.getElementById(id);
if (e.className == 'mediahighlight0')
e.className = 'mediahighlight1';
else
e.className = 'mediahighlight0';
}

function checkbox_checker(frmname)
{
var checkbox_choices = 0;
frmobj = document.forms[frmname];
elmlen=frmobj.length

// Loop from zero to the one minus the number of checkbox button selections
for (i = 0; i < elmlen; i++)
{
if (frmobj.elements[i].checked)
	{ checkbox_choices = checkbox_choices + 1; }
}
if (checkbox_choices > 0 )
	show('uploaddiv')
else
	hide('uploaddiv')
}

function AcheckUncheckAll(form)
{
	if (form.elements[0].checked == false)
	{
		for ( var i=0; i < form.elements.length; i++ )
		{
			form.elements[i].checked = true;
		}
	}
	else
	{
		for ( var i=0; i < form.elements.length; i++ )
		{
			form.elements[i].checked = false;
		}
	}
}

function showmplayer(url,name,width,height)
{
	newwindow=window.open(url, "mPlayer", "location=no,menubar=no,resizable=no,scrollbars=yes,status=no,titlebar=no,toolbar=no,width=455,height=400");
	newwindow.moveTo(0, 0);
	if (window.focus) {newwindow.focus()}
	return false;
}

function popitup(url,name,width,height)
{
	newwindow=window.open(url,'+name+','dependent=no,directories=no,toolbar=no,resizable=no,scrollbars=yes,width='+width+',height='+height+'');
	if (window.focus) {newwindow.focus()}
	return false;
}


last_tab = 'tab1';

function show(layerName) { 
document.getElementById(layerName).style.display = '';
} 

function hide(id) {
var e = document.getElementById(id);
if(e.style.display == 'none')
e.style.display = 'block';
else
e.style.display = 'none';
}

function showobj(id) {
var e = ge(id);
e.style.display = 'block';
}

function hideobj(id) {
var e = ge(id);
e.style.display = 'none';
}

function show_next(tab_name) {
document.getElementById(last_tab).className = 'tab';
var curr = document.getElementById(tab_name);
curr.className='tab_hover';
hide(last_tab+'_data');
show(tab_name+'_data');
last_tab=tab_name;
}


function getElem(elem_name, event_id) {
return document.getElementById(elem_name + event_id);
}

function togglePreview(event_id) {
var display = getElem("", event_id);
var show_div = getElem("show", event_id);
var hide_div = getElem("hide", event_id);

if (display.style.display == "none")
{
	display.style.display = "block";
	hide_div.style.display = "block";
	show_div.style.display = "none";
}
	else 
{
	display.style.display = "none";
	hide_div.style.display = "none";
	show_div.style.display = "block";
}
}



function submitform(formid)
{
	document.getElementById(formid).submit();
}

function checkboxroll(obj) {
if (document.getElementById(obj).checked == true)
	{
		document.getElementById(obj).checked = false;
	}
else
	{
		document.getElementById(obj).checked = true;
	}
}

function gotourl(url) 
{ 
window.location = url; 
} 


function checkEnter(e,formid){ //e is event object passed from function invocation
var characterCode 
if(e && e.which){ //if which property of event object is supported (NN4)
e = e
characterCode = e.which //character code is contained in NN4's which property
}
else{
e = event
characterCode = e.keyCode //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
document.getElementById(formid).submit() //submit the form
return false 
}
else{
return true 
}
}

var lastDiv = "";
function showDiv(divName) {
	
	// hide last div
	if (lastDiv) {
		document.getElementById(lastDiv).className = "hiddenDiv";
	}
	//if value of the box is not nothing and an object with that name exists, then change the class
	if (divName && document.getElementById(divName)) {
		document.getElementById(divName).className = "visibleDiv";
		lastDiv = divName;
	}
}


function updatedate(from,to){
    var from=document.getElementById(from)
    var to=document.getElementById(to);
		to.options[to.selectedIndex].text = from.options[from.selectedIndex].text
	  to.options[to.selectedIndex].value = from.options[from.selectedIndex].value
}

function roll(img_name, img_src)
   {
   document[img_name].src = img_src;
   }

function sendto(url) {
	window.location = ""+url+"";
}

function confirmDeleteitem(str)
{
	return confirm(str);
}

function JumpToIt(list) {
    var newPage = list.options[list.selectedIndex].value
    if (newPage != "None") {
        location.href=newPage
    }
}


