var imguploadguid = "";
var imgfname;
var imgNameHeader;


function querySt(ji)
{
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i=0;i<gy.length;i++)
    {
        ft = gy[i].split("=");
        if (ft[0] == ji)
        {
            return ft[1];
        }
    }
}

function saveimgFile(type){
        var iframedoc;
        var isPortal = false;
        
        if (querySt('isPreview') == 'True')
        {   
            isPortal = true;
            iframedoc = document.getElementById('uploadimgIFRAMEStrange').contentDocument;
            if ( iframedoc == null )
                iframedoc = document.getElementById('uploadimgIFRAMEStrange').contentWindow.document;                
        }
        else {
        
            if (document.getElementById('uploadimgIFRAME') != null) {   
                iframedoc = document.getElementById('uploadimgIFRAME').contentDocument;
                if (iframedoc == null)
                    iframedoc = document.getElementById('uploadimgIFRAME').contentWindow.document;	
            }
            else if (document.getElementById('uploadimgIFRAMEStrange') != null) {
                //retry the portal iframe, to fix a bug that occurs from the add portal.
                isPortal = true;
                iframedoc = document.getElementById('uploadimgIFRAMEStrange').contentDocument;
                if (iframedoc == null)
                   iframedoc = document.getElementById('uploadimgIFRAMEStrange').contentWindow.document;
            }
        }     

	    iframeForm = iframedoc.getElementById('uploadForm');
	    imgfname = iframedoc.getElementById('file').value;
	    imgNameHeader = iframedoc.getElementById('file2').value;
	    
	    if ((imgfname != '') && (imgNameHeader != '')) {
	        iframeForm.action = iframeForm.action + '&action='+type+':true:true';
	    }
	    else if ((imgfname != '') && (imgNameHeader == ''))	    
	    {
           iframeForm.action = iframeForm.action + '&action='+type+':true:false';
	    }
	    else if ((imgfname == '') && (imgNameHeader != '')) {
	        iframeForm.action = iframeForm.action + '&action='+type+':false:true';
	    }
	    
    	if (imgfname != '' || imgNameHeader !='' )
	    {
	        imguploadguid = iframedoc.getElementById('guid').value;
	        iframedoc.getElementById("fileErr").innerHTML = "";
	        if (querySt('isPreview') == 'True' || isPortal){   
	            document.getElementById('uploadimgIFRAMEStrange').contentWindow.submitform();
	        }
            else {
	            document.getElementById('uploadimgIFRAME').contentWindow.submitform();
	        }
	    }
	    else {
	        if (type.toLowerCase() == "edit") {
	            SetEditUploadImageToDone("");
	        }
	        else if (type.toLowerCase() == "add"){
	            SetAddUploadImageToDone("");
	        }
	        else if (type.toLowerCase() == "portal"){
	            SetPortalEditImageUploadToDone("");
	        }	        
	    }
  

}

var imgdownloadCompleted = false;
function getimgUploadData()
{
	if (!imgdownloadCompleted)
	{
		upload.GetUploadData(uploadguid, callback_getimgUploadData);
		window.setTimeout('getimgUploadData()',500);
	}
}



function callback_getimgUploadData(res)
{
	if (res.error)
	{
		alert(res.error);
		return;
	}
  if(typeof(res.value) == 'object')
  {

  }
}
