/////////////////////////////////////////////////////////
// Function for image upload controls ///////////////////
/////////////////////////////////////////////////////////

function dropFile(btn)
{
	if(document.getElementById) {
		tr = btn;
		while (tr.tagName != 'TR') tr = tr.parentNode;
		tr.parentNode.removeChild(tr);
		checkForLast();
	}
}

function addFile(btn)
{
	if(document.getElementById) {
		tr = btn;
		
		while (tr.tagName != 'TR') tr = tr.parentNode;
		var idSuffix = Math.round(Math.random()*1000);
		var newTr = tr.parentNode.insertBefore(tr.cloneNode(true),tr.nextSibling);
		
		thisChilds = newTr.getElementsByTagName('td');
		
		for (var i = 0; i < thisChilds.length; i++)
		{			
			if (thisChilds[i].getAttribute("id") == "tdFile")
			{
				//alert(thisChilds[i].getAttribute("id"));
				thisChilds[i].innerHTML = '<input type="file" name="userfile_' + idSuffix + '"  size="20" class="defform"> (<font color="#808080">size: 111x83 px.</font>)';
			}
		}
		checkForLast();
	}
}

function checkForLast()
{
	btns = document.getElementsByName('drop');
	for (i = 0; i < btns.length; i++){
		btns[i].disabled = (btns.length == 1) ? true : false;
	}
}

function delete_image(obj_name, image_id, obj_id)
{
	var bRet = window.confirm('Are you sure want to delete this image?');
	
	if (bRet)
	{
		document.forms['form'].action = "code/" + obj_name + "_image_del.asp?id=" + image_id + "&" + obj_name + "_id=" + obj_id;
		document.forms['form'].submit();	
	}
	return bRet;
}

/////////////////////////////////////////////////////////

function popupInstance(strFilename, strWidth, strHeight, obj)
{  
    var strURL = "./" + strFilename + "?r=" + Math.random();

    if (obj != null)
    {
        strURL += "&" + obj;    
    }
    window.showModalDialog(strURL, obj, "scroll:yes;status:yes;dialogWidth:" + strWidth + "px;dialogHeight=" + strHeight + "px;center:yes");
}

function openSimpleWindow(strFilename, strWidth, strHeight, obj)
{  
    var i;
    var strURL = "./" + strFilename;
    var strPath = document.location.pathname;
    var retVal = window.open(strURL, obj, "status=yes,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=" + strWidth + ",height=" + strHeight );
    return retVal;
}

var dog = "&#064;";
function insertM(a,b,c) 
{
	document.write("<a href='mailto:" + a + dog + b + "'>" + (c != "" ? c : a + dog + b) + "</a>" );
}

