/*
Carmil 1
(c) 2006-2008
contact.js
*/

function PageContactUs ()
{
this.MAX_MESSAGE_LENGTH= 2000;
this.mydebugger= new DebugHelper("PageContactUs");
this.strtbl= null;
this.objTuring= null;
this.lang= '';

this.go = function (lang)
{
this.lang= lang;
this.strtbl= new StringTable (getDocs() + "/polls/xml/strtbl_en.xml", "contact", this.lang);

new TextInputLimiter("idMailText", "idMailTextExceedMsg", this.MAX_MESSAGE_LENGTH, null );

var recipient= null; //getAndDeleteMyCookie( "ap_recipient" );
if (!isNonEmptyString(recipient))
{
var splits= /^(.+[?])(.*[&])*(recipient[=])([A-Za-z0-9]+)([&].*)?$/.exec(document.location);
if ((splits != null) && (splits.length >= 4) && (splits[4] != null))
{
recipient= unescape(splits[4]);
}
}
if (isNonEmptyString(recipient))
{
var node= document.getElementById("idRecipient");
node.value= recipient;
}

var subject= null; //getAndDeleteMyCookie( "ap_subject" );
if (!isNonEmptyString(subject))
{
subject= getQueryStringParam("subject", "");
}
if (isNonEmptyString(subject))
{
var node= document.getElementById("idSubject");
node.value= subject;
}

var bodymsg= null; //getAndDeleteMyCookie( "ap_message" );
if (!isNonEmptyString(bodymsg))
{
var splits= /^(.+[?])(.*[&])*(body[=])([A-Za-z0-9\%\_\-\.\,]+)([&].*)?$/.exec(document.location);
if ((splits != null) && (splits.length >= 4) && (splits[4] != null))
{
bodymsg= unescape(splits[4]);
}
}
if (isNonEmptyString(bodymsg))
{
var node= document.getElementById("idMailText");
node.value= bodymsg;
}


var nick= getMyCookie("ap_nick");
if (isNonEmptyString(nick))
{
var node= document.getElementById("idName");
node.value= nick;
}
};

this.doSendMail = function ()
{
var turing_enc= (this.objTuring == null) ? 0 : this.objTuring.getTuringEnc();
var turing_inp= (this.objTuring == null) ? 0 : this.objTuring.getTuringUser();

var querystr=
"?turing_enc=" + encodeURIComponent(turing_enc) +
"&turing=" + encodeURIComponent(turing_inp)
;

var nodeForm= document.getElementById("idForm");
nodeForm.action= getCgibin() + "/ap_contact.pl" ;
nodeForm.submit();
};

this.isTextFieldValid = function (id, msgEmpty, maxlength, msgTooLong)
{
var node= document.getElementById(id);

if (node.value == "")
{
node.focus();
alert(msgEmpty);
return false;
}

if ((maxlength > 0) && (node.value.length > maxlength))
{
node.focus();
alert(msgTooLong);
return false;
}
return true;
};

this.isFormMailValid = function ()
{
var isValid=
this.isTextFieldValid("idName", this.strtbl.get("idContactMissingName"), 0, "") &&
this.isTextFieldValid("idEmail", this.strtbl.get("idContactMissingEmail"), 0, "") &&
this.isTextFieldValid("idSubject", this.strtbl.get("idContactMissingSubject"), 0, "") &&
this.isTextFieldValid("idMailText", this.strtbl.get("idContactMissingMsg"), this.strtbl.format("idContactMsgTooLong", this.MAX_MESSAGE_LENGTH) );
if ( ! isValid )
{
return false;
}

var nodeEmail= document.getElementById("idEmail");
if ( getEmailValidation(nodeEmail.value) != 0 )
{
nodeEmail.focus();
alert("Email is not valid.\nPlease enter a valid mailbox.");
return false;
}
return true;
};

this.onSubmitMail = function ()
{
if (! this.isFormMailValid () )
{
return;
}

if (this.objTuring == null)
{
this.objTuring= new TuringObj("idDivTuring");
this.objTuring.setLang(this.lang);
this.objTuring.doDynamicTuring();
this.objTuring.focus();

var nodeSubmit= document.getElementById("idBtnSubmit");
nodeSubmit.value= "Submit";
}
else if (! this.objTuring.isValidUserInput(true) )
{
 
}
else
{
this.objTuring= null;
this.doSendMail ();
}
};
}

 

