// JavaScript Document
/*
 File Name:		enewsletter_subscribe.js
 Date Created:	24/04/2008
 Author:			Andrew Newnham/Mariam Saim
 Description:		This file is used only for displaying the enewsletter form in the website.
 Related files:	scripts/newsletter-validation.js
 Updates:	02.03.08: - created.
 			27.04.08: - made all tags lowercase
					  - changed html encompassing quotation marks to single quotes
					  - removed unrequired spacing
			11.08.08: - added arrays to hold various languages and changed the form to allow the language to be specified
					  - Added switch code to change folder names according to language
			02.03.09: - Added parameter to have the default elected dep city
					  - Added parameter to have a custom submit label.		
*/

var japanesemsgemail=String.fromCharCode(69,45,12513,12540,12523,12539,12450,12489,12524,12473,12434,12372,20837,21147,12367,12384,12373,12356,12290);
var japanesemsgcity=String.fromCharCode(12424,12367,21033,29992,12377,12427,20986,30330,37117,24066,12434,25351,23450,12375,12390,12367,12384,12373,12356,12290);
/*finding the site the script is being used on through the URI*/
var folder;
var filename
var URI=parent.document.URL;
folder=URI.substring(URI.indexOf('/',7)+1,URI.length);
filename=folder.substring(folder.indexOf('/')+4,folder.length);
folder=folder.substring(folder.indexOf(''),folder.indexOf('/')+3);

//Restricting relevant fields to numeric only
function numbersonly(myfield,e,dec){
	var key;
	var keychar;
	if(window.event)key=window.event.keyCode;
	else if(e)key=e.which;
	else return true;
	keychar=String.fromCharCode(key);
	//control keys
	if((key==null)||(key==0)||(key==8)||(key==9)||(key==13)||(key==27))return true;
	//numbers
	else if((("0123456789").indexOf(keychar)>-1))return true;
	//decimal point jump
	else if(dec&&(keychar==".")){myfield.form.elements[dec].focus();return false;}
	else return false;
}

//Creating a 3d array to hold all language data
function fieldDef(select,title,mr,mrs,ms,fName,lName,email,city,member,yes,privacy,source,flyer,newspaper,online,question,maha,ffp,qdfc,submit,mobile){
	this.select=select;
	this.title=title;
	this.mr=mr;
	this.mrs=mrs;
	this.ms=ms;
	this.fName=fName;
	this.lName=lName;
	this.email=email;
	this.city=city;
	this.member=member;
	this.yes=yes;
	this.privacy=privacy;
	this.source=source;
	this.flyer=flyer;
	this.newspaper=newspaper;
	this.online=online;
	this.question=question;
	this.maha=maha;
	this.ffp=ffp;
	this.qdfc=qdfc;
	this.submit=submit;
	this.mobile=mobile;
}


var langList=new Array();
//English
langList[0]=new fieldDef('select','Title','Mr','Mrs','Ms','First Name','Family Name','Email Address','Preferred City of Departure','Privilege Club Member','Yes','I have read, understood and accepted the <a href="/global/en/privacy-policy.html#Newsletter">Privacy Policy</a>','','','','','Q: Our passengers enjoy a range<br/>of exclusive privileges and benefits at: ','Al Maha Services','Privilege Club','Qatar Duty Free','Submit','Mobile/Cell Number');
//French
langList[1]=new fieldDef('select','Titre','Mr','Mme','Mlle','Pr&#233;nom','Nom','Adresse Email','A&#233;roport de d&#233;part habituel','Membre Privilege Club','Oui','J\'ai pris connaissance de la <a href="charte-de-confidentialite.html" title="view the Privacy Policy">charte de confidentialit&#233;</a>. Je la comprends et j\'en accepte les conditions.','Flyer','Journaux','Internet','','','','','Envoyer','Numéro de téléphone portable');
//German
langList[2]=new fieldDef('auswählen','Titel','','Frau','Herr','Vorname','Nachname','E-Mail-Adresse','Bevorzugter Abflughafen','Privilege Club Mitglied','Ja','Ich habe die Nutzungsbedingungen gelesen,<a href="privacy-policy.html"> datenschutzrichtlinie</a>','','','','','','','','','Absenden','Handynummer');
//Japanese
langList[3]=new fieldDef('&#12362;&#36984;&#12403;&#12367;&#12384;&#12373;&#12356;','&#31216;&#21495;','Mr','Mrs','Ms','&#12362;&#21517;&#21069;&#65288;&#21517;&#65289;','&#12362;&#21517;&#21069;&#65288;&#22995;&#65289;','E&#12513;&#12540;&#12523;&#12539;&#12450;&#12489;&#12524;&#12473;','&#12424;&#12367;&#21033;&#29992;&#12377;&#12427;&#20986;&#30330;&#37117;&#24066;','&#12503;&#12522;&#12499;&#12524;&#12483;&#12472;&#12463;&#12521;&#12502;&#20250;&#21729;&#12391;&#12377;&#12363;','&#12399;&#12356;','<a href="/global/en/privacy-policy.html#Newsletter">&#35215;&#32004;</a>&#12434;&#35501;&#12415;&#12289;&#21516;&#24847;&#12375;&#12414;&#12377;&#12290;','','','','','','','','','&#30331;&#37682;&#12377;&#12427;','Mobile/Cell Number');
//Arabic
langList[4]=new fieldDef('select','&#1575;&#1604;&#1604;&#1602;&#1576;','&#1575;&#1604;&#1587;&#1610;&#1583;','&#1575;&#1604;&#1587;&#1610;&#1583;&#1577;','&#1575;&#1604;&#1570;&#1606;&#1587;&#1577;','&#1575;&#1604;&#1575;&#1587;&#1605;&#32;&#1575;&#1604;&#1571;&#1608;&#1604;','&#1575;&#1587;&#1605;&#32;&#1575;&#1604;&#1593;&#1575;&#1574;&#1604;&#1577;','&#1575;&#1604;&#1576;&#1585;&#1610;&#1583;&#32;&#1575;&#1604;&#1573;&#1604;&#1603;&#1578;&#1585;&#1608;&#1606;&#1610;','&#1575;&#1604;&#1605;&#1583;&#1610;&#1606;&#1577;&#32;&#1575;&#1604;&#1605;&#1601;&#1590;&#1604;&#1577;&#32;&#1604;&#1604;&#1605;&#1594;&#1575;&#1583;&#1585;&#1577;','&#1607;&#1604;&#32;&#1571;&#1606;&#1578;&#32;&#1593;&#1590;&#1608;&#32;&#1601;&#1610;&#32;&#1606;&#1575;&#1583;&#1610;&#32;&#1575;&#1604;&#1575;&#1605;&#1578;&#1610;&#1575;&#1586;','&#1606;&#1593;&#1605;','&#1602;&#1585;&#1571;&#1578;&#1548;&#32;&#1601;&#1607;&#1605;&#1578;&#32;&#1608;&#1602;&#1576;&#1604;&#1578;&#32;&#1588;&#1585;&#1608;&#1591 <a href="/global/en/privacy-policy.html#Newsletter">&#1575;&#1604;&#1582;&#1589;&#1608;&#1589;&#1610;&#1577;</a>','','','','','','','','','&#1575;&#1606;&#1578;&#1607;&#1609;','&#1585;&#1602;&#1605;&#32;&#1575;&#1604;&#1607;&#1575;&#1578;&#1601;&#32;&#1575;&#1604;&#1580;&#1608;&#1575;&#1604;');
//Italian
langList[5]=new fieldDef('select','Titolo','Sig.','Sig.na','Sig.ra','Nome','Cognome','Indirizzo e-mail','Citt&#224; di partenza preferita','Numero di Privilege Club','Si','Ho letto, compreso e accettato i termini in materia di legge della <a href="/global/en/privacy-policy.html#Newsletter">Privacy</a>','','','','','','','','','Iscrizione','Mobile/Cellulare');
//Spanish
langList[6]=new fieldDef('seleccionar','Tratamiento','Sr','Sra','Srta','Nombre','Apellido','Direcci&#243;n de e-mail','Ciudad de salida','Es socio de \'Privilege Club\'','Sí','He le&#237;do y acepto los <a href="/global/en/privacy-policy.html#Newsletter">política de privacidad</a>','D&oacute;nde ha visto esta promoci&oacute;n?','Folleto','Peri&#243;dico','Online','','','','','Enviar','Móvil');
//Chinese
langList[7]=new fieldDef('&#36873;&#25321;','&#31216;&#35859;','&#20808;&#29983;','&#22827;&#20154;','&#23567;&#22992;','&#21517;&#23383;','&#22995;&#27663;','&#37038;&#31665;&#22320;&#22336;','&#39318;&#36873;&#22987;&#21457;&#22478;&#24066;','&#24120;&#26053;&#23458;&#20465;&#20048;&#37096;&#20250;&#21592;&#65311;','&#26159;','&#25105;&#24050;&#38405;&#35835;&#12289;&#29702;&#35299;&#24182;&#25509;&#21463;&#35813;<a href="/global/en/privacy_policy.html#Newsletter">&#38544;&#31169;&#25919;&#31574;</a>&#12290;','','','','','','','','','&#25552;&#20132;','&#25163;&#26426;&#21495;');
//Russian
langList[8]=new fieldDef('&#1042;&#1099;&#1073;&#1088;&#1072;&#1090;&#1100;','&#1054;&#1073;&#1088;&#1072;&#1097;&#1077;&#1085;&#1080;&#1077;','&#1043;&#45;&#1085;','&#1043;&#45;&#1078;&#1072;','','&#1048;&#1084;&#1103;','&#1060;&#1072;&#1084;&#1080;&#1083;&#1080;&#1103;','&#1040;&#1076;&#1088;&#1077;&#1089;&#32;&#1101;&#1083;&#1077;&#1082;&#1090;&#1088;&#1086;&#1085;&#1085;&#1086;&#1081;&#32;&#1087;&#1086;&#1095;&#1090;&#1099;','&#1055;&#1088;&#1077;&#1076;&#1087;&#1086;&#1095;&#1090;&#1080;&#1090;&#1077;&#1083;&#1100;&#1085;&#1099;&#1081;&#32;&#1075;&#1086;&#1088;&#1086;&#1076;&#32;&#1086;&#1090;&#1087;&#1088;&#1072;&#1074;&#1083;&#1077;&#1085;&#1080;&#1103;','&#1042;&#1099; &#1091;&#1095;&#1072;&#1089;&#1090;&#1085;&#1080;&#1082; Privilege Club','&#1044;&#1072;','&#1071;&#32;&#1086;&#1079;&#1085;&#1072;&#1082;&#1086;&#1084;&#1083;&#1077;&#1085;&#32;&#1080;&#32;&#1089;&#1086;&#1075;&#1083;&#1072;&#1089;&#1077;&#1085;&#32;&#1089; <a href="/global/en/privacy-policy.html#Newsletter">&#1091;&#1089;&#1083;&#1086;&#1074;&#1080;&#1103;&#32;&#1080;&#32;&#1087;&#1088;&#1072;&#1074;&#1080;&#1083;&#1072;</a>','','','','','','','','','&#1055;&#1077;&#1088;&#1077;&#1076;&#1072;&#1090;&#1100;','&#1053;&#1086;&#1084;&#1077;&#1088;&#32;&#1084;&#1086;&#1073;&#1080;&#1083;&#1100;&#1085;&#1086;&#1075;&#1086;&#32;&#1090;&#1077;&#1083;&#1077;&#1092;&#1086;&#1085;&#1072;');
//Korean
langList[9]=new fieldDef('&#49440;&#53469;','&#53440;&#51060;&#53952;','Mr','Mrs','Ms','&#51060;&#47492;','&#49457;','&#51060;&#47700;&#51068;&#32;&#51452;&#49548;','&#49440;&#54840;&#54616;&#45716;&#32;&#52636;&#48156;&#51648;','&#54532;&#47532;&#48716;&#47532;&#51648; &#53364;&#47101; &#54924;&#50896;&#51060;&#49901;&#45768;&#44620;','&#45348;','&#51060;&#32;&#50557;&#44288;&#51012;&#32;&#51069;&#50632;&#51004;&#47728;&#32;&#51060;&#32;&#45236;&#50857;&#50640; <a href="/global/en/privacy_policy.html#Newsletter">&#46041;&#51032;&#32;&#54633;&#45768;&#45796;</a>','','','','','','','','','&#48372;&#45236;&#44592;','&#55092;&#45824;&#54256;&#32;&#48264;&#54840;');
//Turkish
langList[10]=new fieldDef('se&#231;iniz','&#220;nvan','Bay','Bayan','','Ad','Soyad','E–posta adresi','Kalk&#305;&#351; i&#231;in tercih edilen &#351;ehir','Privilege Club üyeli&#287;iniz var m&#305;','Evet','Gizlilik Politikas&#305;n&#305; okudum, anlad&#305;m ve kabul <a href="/tr/tr/privacy-policy.html#Newsletter">ediyorum</a>','','','','','','','','','Gönder','Cep Telefonu Numaras&#305;');

var folder;
var URI=parent.document.URL;
folder=URI.substring(URI.indexOf('/',7)+1,URI.length);
folder=folder.substring(folder.indexOf(''),folder.indexOf('/')+3);

function writeform(lang,sourceCode,prefCityCode,submitLabel){
//If dafault city is not specified, first field is selected
if((prefCityCode==null)|| (prefCityCode=="")){prefCityCode="";}
if((submitLabel==null) || submitLabel==""){submitLabel=langList[lang].submit;}
//lang is to specify the language of the e-newsletter, 0=english, 1=french, 2=German
//sourceCode is the indicate where the signup is coming from, i.e. qr.com, msn arabia etc.
document.write('<div class="form" id="#newsletter">');
document.write('<form name="icpsignup" action="http://app.icontact.com/icp/signup.php" method="post">');
document.write('<input type="hidden" name="redirect" value="http://www.qatarairways.com/'+folder+'/confirm.html" />');
document.write('<input type="hidden" name="errorredirect" value="http://www.qatarairways.com/'+folder+'/sorry.html" />');
document.write('<input type="hidden" name="listid" value="3737" />');
document.write('<input type="hidden" name="specialid:3737" value="HUBS" />');	  
document.write('<input type="hidden" name="clientid" value="223895" />');
document.write('<input type="hidden" name="formid" value="188" />');
document.write('<input type="hidden" name="reallistid" value="1" />');
document.write('<input type="hidden" name="doubleopt" value="1" />');
//Default the source code to qr_com
document.write('<input type="hidden" name="fields_signup_location" value="'+sourceCode+'" />');
document.write('<fieldset>');

	document.write('<div class="label"><label>'+langList[lang].title+'</label></div>');
	document.write('<div><select name="fields_prefix">');
	document.write('<option value="" selected>-- '+langList[lang].select+' --</option>');
	if(langList[lang].mr!='')document.write('<option value="'+langList[lang].mr+'">'+langList[lang].mr+'</option>');
	if(langList[lang].mrs!='')document.write('<option value="'+langList[lang].mrs+'">'+langList[lang].mrs+'</option>');
	if(langList[lang].ms!='')document.write('<option value="'+langList[lang].ms+'">'+langList[lang].ms+'</option>');
	document.write('</select></div>');

document.write('<div class="label"><label for="fields_fname">'+langList[lang].fName+'</label></div>');
document.write('<div><input type="text" name="fields_fname" maxlength="40" class="middle" /></div>');
document.write('<div class="label"><label for="fields_lname">'+langList[lang].lName+'</label></div>');
document.write('<div><input type="text" name="fields_lname"  maxlength="40" class="middle" /></div>');
document.write('<div class="label required"><label for="fields_email">'+langList[lang].email+'</label></div>');
document.write('<div><input type="text" name="fields_email" maxlength="40" class="middle" /></div>');
//Do not display the mobile field on the Japanese site
if(folder!='jp/jp'){
	document.write('<div class="label"><label for="mobilenumber">'+langList[lang].mobile+'</label></div>');
	document.write('<div><input type="text" name="mobilenumber" class="middle" onKeyPress="return numbersonly(this,event)" /></div>');
}
document.write('<div class="label required"><label for="fields_departure">'+langList[lang].city+'</label></div>');
document.write('<div><select name="fields_departure">');
document.write('<option value="" >-- '+langList[lang].select+' --</option>');
document.write('<option value="AUH">Abu Dhabi</option>');
document.write('<option value="ADL">Adelaide</option>');
document.write('<option value="AMD">Ahmedabad</option>');
document.write('<option value="ALY">Alexandria</option>');
document.write('<option value="ALG">Algiers</option>');
document.write('<option value="AMM">Amman</option>');
document.write('<option value="ATQ">Amritsar</option>');
document.write('<option value="ATH">Athens</option>');
document.write('<option value="BAH">Bahrain</option>');
document.write('<option value="BKK">Bangkok</option>');
document.write('<option value="PEK">Beijing</option>');
document.write('<option value="BEY">Beirut</option>');
document.write('<option value="TXL">Berlin</option>');
document.write('<option value="BNE">Brisbane</option>');
document.write('<option value="CAI">Cairo</option>');
document.write('<option value="CPT">Cape Town</option>');
document.write('<option value="CMN">Casablanca</option>');
document.write('<option value="CEB">Cebu</option>');
document.write('<option value="MAA">Chennai</option>');
document.write('<option value="CMB">Colombo</option>');
document.write('<option value="DAM">Damascus</option>');
document.write('<option value="DMM">Dammam</option>');
document.write('<option value="DAR">Dar Es Salaam </option>');
document.write('<option value="DEL">Delhi</option>');
document.write('<option value="DPS">Denpasar Bali</option>');
document.write('<option value="DAC">Dhaka</option>');
document.write('<option value="DOH">Doha</option>');
document.write('<option value="DXB">Dubai</option>');
document.write('<option value="FRA">Frankfurt</option>');
document.write('<option value="GVA">Geneva</option>');
document.write('<option value="GOI">Goa</option>');
document.write('<option value="CAN">Guangzhou</option>');
document.write('<option value="SGN">Ho Chi Minh City</option>');
document.write('<option value="HKG">Hong Kong</option>');
document.write('<option value="HOU">Houston</option>');
document.write('<option value="HYD">Hyderabad</option>');
document.write('<option value="ISB">Islamabad</option>');
document.write('<option value="IST">Istanbul</option>');
document.write('<option value="CGK">Jakarta</option>');
document.write('<option value="JED">Jeddah</option>');
document.write('<option value="JNB">Johannesburg</option>');
document.write('<option value="KHI">Karachi</option>');
document.write('<option value="KTM">Kathmandu</option>');
document.write('<option value="KRT">Khartoum</option>');
document.write('<option value="COK">Kochi</option>');
document.write('<option value="CCJ">Kozhikode</option>');
document.write('<option value="KUL">Kuala Lumpur</option>');
document.write('<option value="KWI">Kuwait</option>');
document.write('<option value="LOS">Lagos</option>');
document.write('<option value="LHE">Lahore</option>');
document.write('<option value="LON">London</option>');
document.write('<option value="LXR">Luxor</option>');
document.write('<option value="MAD">Madrid</option>');
document.write('<option value="MLE">Maldives</option>');
document.write('<option value="MAN">Manchester</option>');
document.write('<option value="MNL">Manila</option>');
document.write('<option value="MHD">Mashad</option>');
document.write('<option value="MEL">Melbourne</option>');
document.write('<option value="MXP">Milan</option>');
document.write('<option value="DME">Moscow</option>');
document.write('<option value="BOM">Mumbai</option>');
document.write('<option value="MUC">Munich</option>');
document.write('<option value="MCT">Muscat</option>');
document.write('<option value="NAG">Nagpur</option>');
document.write('<option value="NBO">Nairobi</option>');
document.write('<option value="EWR">New York</option>');
document.write('<option value="KIX">Osaka</option>');
document.write('<option value="CDG">Paris</option>');
document.write('<option value="PER">Perth</option>');
document.write('<option value="PEW">Peshawar</option>');
document.write('<option value="PRG">Prague</option>');
document.write('<option value="RUH">Riyadh</option>');
document.write('<option value="FCO">Rome</option>');
document.write('<option value="SAH">Sanaa</option>');
document.write('<option value="ICN">Seoul</option>');
document.write('<option value="SEZ">Seychelles</option>');
document.write('<option value="PVG">Shanghai</option>');
document.write('<option value="SIN">Singapore</option>');
document.write('<option value="ARN">Stockholm</option>');
document.write('<option value="SYD">Sydney</option>');
document.write('<option value="IKA">Tehran</option>');
document.write('<option value="TRV">Thiruvananthapuram</option>');
document.write('<option value="TIP">Tripoli</option>');
document.write('<option value="TUN">Tunis</option>');
document.write('<option value="VIE">Vienna</option>');
document.write('<option value="IAD">Washington DC</option>');
document.write('<option value="ZRH">Zurich</option>');
document.write('</select></div>');
//Promotion-source script - Added by Ahmad Elorfali - on 13-May-2009
/*if((folder!='dz/fr')&&(folder!='tn/fr')&&(folder!='ma/fr')){
	if(langList[lang].source!=''){
		document.write('<div class="label required"><label>'+langList[lang].source+'</label></div>');
		document.write('<div><select name="promotion-source">');
		document.write('<option value="" selected="selected">-- '+langList[lang].select+' --</option>');
		document.write('<option value="Flyer">'+langList[lang].flyer+'</option>');
		document.write('<option value="Newspaper">'+langList[lang].newspaper+'</option>');
		document.write('<option value="Online">'+langList[lang].online+'</option>');
		document.write('</select>');
		document.write('</div>');
		}
}*/

document.write('<div class="label"><label>'+langList[lang].member+'?</label></div>');
document.write('<div class="radio"><input type="checkbox" id="fields_pc_member" name="fields_pc_member" />'+langList[lang].yes+'</div>');
document.write('<div class="fullWidth check"><input type="checkbox" name="termsagreement" value="termsagreement" />'+langList[lang].privacy+'.</span></div>');
document.write('</fieldset><div class="label"></div><input type="submit" name="submit" value="'+submitLabel+'" onClick="return validate(termsagreement);" class="');
if(folder=='ru/ru'){document.write('ButtonBig buttonLLBig" />');}else{document.write('button buttonLL" />');}
document.write('</form></div>');
document.write('<script type="text/javascript">');
document.write('var DepSelect = document.icpsignup.fields_departure;');
document.write('for(var i=0; i<DepSelect.length; i++){');
document.write('if(DepSelect.options[i].value == "'+prefCityCode+'"){DepSelect.selectedIndex=i;}');
document.write('}\n');
document.write('var frmvalidator=new Validator("icpsignup");');
document.write('frmvalidator.addValidation("termsagreement","req","Please check the Terms and Conditions.");');
/*if(folder=='fr/fr'){
	document.write('frmvalidator.addValidation("promotion-source","req","Please select where did you see this offer");');
}*/

if(folder=='jp/jp'){
	document.write('frmvalidator.addValidation("fields_email","req",japanesemsgemail);');
	document.write('frmvalidator.addValidation("fields_departure","req",japanesemsgcity);');
}

if(folder=='es/es'){
	document.write('frmvalidator.addValidation("termsagreement","req","Por favor, lea y marque la casilla de términos y condiciones.");');
/*
	document.write('frmvalidator.addValidation("promotion-source","req","Por favor, seleccione la casilla donde vio esta oferta.");');*/
	document.write('frmvalidator.addValidation("fields_email","req","Por favor, introduzca su dirección de correo electrónico.");');
	document.write('frmvalidator.addValidation("fields_departure","req","Por favor, seleccione su ciudad preferida de salida.");');
}

if(folder=='my/en'&&filename=='newsletter-my.html'){
	document.write('frmvalidator.addValidation("fields_fname","alpha");');
	document.write('frmvalidator.addValidation("fields_lname","alpha");');
	document.write('frmvalidator.addValidation("fields_departure","req","Please select preferred city of departure");');
	document.write('frmvalidator.addValidation("fields_email","req","Please enter your Email Address");');
	document.write('frmvalidator.addValidation("fields_email","email");');
	document.write('frmvalidator.addValidation("answer","req","Please Answer the question.");');
}

else{
document.write('frmvalidator.addValidation("fields_fname","alpha");');
document.write('frmvalidator.addValidation("fields_lname","alpha");');
document.write('frmvalidator.addValidation("fields_departure","req","Please select preferred city of departure");');
document.write('frmvalidator.addValidation("fields_email","req","Please enter your Email Address");');
document.write('frmvalidator.addValidation("fields_email","email");');
}


document.write('</script>');
}