﻿var ErrorMessage = "";
var blnCaptchaError = false;
var lngDataID = 0;

function WS_File(params)
{
	glbXmlRequest = new AkimanXmlHTTP(getID(strLoadingDiv),getID(strDebugDiv));
	var soapData = SoapDataBuilder("FileService",params);
	AjaxRequest("/Mod/File/WS_File.asmx",soapData,"",strLoadingDiv);
}
function InsertData()
{
    var strTitle = GetAspFormField("strTitle");
    var strFirstname = GetAspFormField("strFirstname");
    var strLastname = GetAspFormField("strLastname");
    var strOrganisation = GetAspFormField("strOrganisation");
    var strTelephone = GetAspFormField("strTelephone");
    var strEmail = GetAspFormField("strEmail");
    var strDescription = GetAspFormField("strDescription");
    
    NoDisplay("Error");
    ErrorMessage = "";
    if (ControlData())
    {
        var params = CustomParamBuilder("strOperation", "InsertData");	
        params += CustomParamBuilder("strTitle", strTitle.value);	
        params += CustomParamBuilder("strFirstname", strFirstname.value);	
        params += CustomParamBuilder("strLastname", strLastname.value);	
        params += CustomParamBuilder("strOrganisation", strOrganisation.value);	
        params += CustomParamBuilder("strTelephone", strTelephone.value);	
        params += CustomParamBuilder("strEmail", strEmail.value);	
        params += CustomParamBuilder("strDescription", strDescription.value);	
        params += CustomParamBuilder("strCriteria", "");
        WS_File(params);
    }
}
function RemoveFile(lngFileID)
{
    var	params ;
    params = CustomParamBuilder("strOperation", "RemoveFile");
    params += CustomParamBuilder("lngFileID", lngFileID);
    WS_File(params);
}
function DeleteFile(lngFileID)
{
    var	params ;
    params = CustomParamBuilder("strOperation", "DeleteFile");
    params += CustomParamBuilder("lngFileID", lngFileID);
    params += parseAspForm();
    WS_File(params);
}
function File_RefreshList()
{      
    Display("File_RefreshList");
    NoDisplay("FileList");
    setTimeout("Display('FileList')",1000);
    setTimeout("NoDisplay('File_RefreshList')",1000);
}
function ControlData()
{
    var strFirstname = GetAspFormField("strFirstname");
    var strEmail = GetAspFormField("strEmail");
    var strCaptcha = GetAspFormField("strCaptcha");
    
    if (strFirstname.value.length < 2)
    {
       ErrorMessage += "<p>"+Error_Firstname+"</p>";
    }         
    if (!isEmail(strEmail.value))
    {
	    ErrorMessage += "<p>"+Error_Email+"</p>";
	}
    if (strCaptcha.value.length != 5)	
	{
		ErrorMessage += "<p>"+Error_Captcha+"</p>";
	}
	if (!(ErrorMessage.length > 0))
	{
	    var	params ;
	    params = CustomParamBuilder("strOperation", "ControlCaptcha");
	    params += CustomParamBuilder("strFirstname", strFirstname.value);
        params += CustomParamBuilder("strEmail", strEmail.value);
        params += CustomParamBuilder("strCaptcha", strCaptcha.value);
	    //params += parseAspForm();
	    WS_File(params);
	    if (blnCaptchaError)
	    {
	        ErrorMessage += "<p>"+Error_Captcha+"</p>";
	    }
	}
	if (ErrorMessage.length > 0)
	{
	    SetInnerHtml("Error",ErrorMessage);
	    Display("Error");
	    return false;
	}
	else
	{
	    return true;
	}
}
