/* QSEARCH Javascript Function */
/* (c) 2008, Match.com */
/* Authored by Andy Schubert, GEMs Team */
/* Created Monday, May 12, 2008 | Updated Tuesday, March 31, 2009 */
/* Provides a QSEARCH form via javascript, including form submission. */
/* Function call requires all variables. */

function dw(n) {document.write(n);}

function execqsearch(j, k, m, n) { // j = countrycode, k=r2s value, m = trackingid, n = new window/same window - 0, 1. 2+ = special cases.
	var u="\/search\/search.aspx?exec=go&tp=q";
	u+="&gc="+document.getElementById('gc').value;
	u+="&tr="+document.getElementById('tr').value;
	
	// Age Range Error Fix
	if (parseInt(document.getElementById('lage').value) > parseInt(document.getElementById('uage').value)) {
	u+="&lage="+document.getElementById('uage').value;
	u+="&uage="+document.getElementById('lage').value;
	}
	else{
	u+="&lage="+document.getElementById('lage').value;
	u+="&uage="+document.getElementById('uage').value;	
	}
	
	u+="&sl="+document.getElementById('regions').value;
	u+="&cl="+j+"&do=2&r2s="+k+"";
	if (m == "0000000")
	{}
	else {
	u+="&trackingid="+m+"";
	}
	
if ((document.getElementById('lage').value == '99')&&(document.getElementById('uage').value == '98')) {
	alert(u);	
	}
else if (n == 1) {
	window.open(u); 
	}
else if (n == 0) {
	window.location = u;
	}
else if (n == 2) { // special case for ebay channel deliverable
var v = 'http:\/\/ebay.dating.match.com.au';
		var w = v+u;
		window.location = w;
	}	
else{}	
}

function qsearch_js(n,p,q, r) { // n = affiliateID, p = trackingID to be used, q = r2s default override (0=off,1=on), r = open in new window (1=yes, 0=no)

var count=0;
var entity = new Array();  // initialize Array 

function qs(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q){
 	entity[count]= new Array(16);
	entity[count].affiliateid=a; // AffiliateID number. Primary matching element.
	entity[count].affiliatename=b; // AffiliateName. Used in diagnostic table only.	
	entity[count].languageid=c; // Format: 1, 2, 3. Determines labels, regions.
	entity[count].langcountryid=d; // Format: en-au, es-ar, fr-be. Determines regions.
	entity[count].countrycode=e; // Format: 154 (mexico), 11 (argentina), 226 (united states).	
	entity[count].primarygender=f; // Values = M, F. Selected displays for I am a... and returns its opposite for Seeking a...
 	entity[count].agerange=g; // Format: 18-35 for ages 18 through 35, inclusive
	entity[count].iamlabel=h; // I am a...
	entity[count].seekinglabel=i; // Seeking a...
	entity[count].manlabel=j; // Man
	entity[count].womanlabel=k; //Woman
	entity[count].seekingmanlabel=l; // Men
	entity[count].seekingwomanlabel=m; // Women
	entity[count].fromagelabel=n; // Between ages
	entity[count].toagelabel=o; // and
	entity[count].provincelabel=p; // Province, State, Estados, etc.
	entity[count].imagealt=q; // Alt title for Search button
 	count++;
}

//MSN Affiliates
qs('1185', 'MSNTHAI', '1', 'en-th', '212', 'M', '25-35', 'ฉันเป็น', 'กำลังมองหา', 'ผู้ชาย', 'ผู้หญิง', 'ผู้ชาย', 'ผู้หญิง', 'ระหว่าง', 'และ', 'จังหวัด', 'ค้นหา');


var z;

if (n ==  '0000') {
dw('<table>');
dw('<tr>');
dw('<th>aff id</th>');
dw('<th>aff name</th>');
dw('<th>lng id</th>');
dw('<th>lng-mkt</th>');
dw('<th>cntry</th>');
dw('<th>seek expression</th>');
dw('<th>age expression</th>');
dw('<th>province label</th>');
dw('<th>button</th>');
dw('</tr>');
for(z=0; z <= (entity.length - 1); z++) { // start diagnostic mode loop
dw('<tr>');
dw('<td>'+entity[z].affiliateid+'</td>');
dw('<td>'+entity[z].affiliatename+'</td>');
dw('<td>'+entity[z].languageid+'</td>');
dw('<td>'+entity[z].langcountryid+'</td>');
dw('<td>'+entity[z].countrycode+'</td>');
dw('<td>'+entity[z].iamlabel+' ');

if (''+entity[z].primarygender == "M") {
dw('<strong>'+entity[z].manlabel+'</strong> (<em>'+entity[z].womanlabel+'</em>)');
}
else {
dw('<strong>'+entity[z].womanlabel+'</strong> (<em>'+entity[z].manlabel+'</em>)');
}

dw(' '+entity[z].seekinglabel+' ');

if (''+entity[z].primarygender == "M") {
dw('<strong>'+entity[z].seekingwomanlabel+'</strong> (<em>'+entity[z].seekingmanlabel+'</em>)</td>');
}
else {
dw('<strong>'+entity[z].seekingmanlabel+'</strong> (<em>'+entity[z].seekingwomanlabel+'</em>)</td>');
}

dw('<td>'+entity[z].fromagelabel+' '+entity[z].agerange.substring(0,2)+' '+entity[z].toagelabel+' '+entity[z].agerange.substring(3,5)+'</td>');
dw('<td>'+entity[z].provincelabel+'</td>');
dw('<td>'+entity[z].imagealt+'</td>');
dw('</tr>');
	} // end diagnostic mode loop
dw('</table>');
}

else {
	for(z=0; z <= (entity.length - 1); z++) { // start loop
	
	if (''+entity[z].affiliateid != n){}
	
	else {
	dw('<div class="qslayout" id="qslayout">');
	dw('<div class="GenderBlock">');
	dw('<label id="iamlabel">'+entity[z].iamlabel+'</label>');
	dw('<span>');
	dw('<select id="gc">');
	
		if (''+entity[z].primarygender == 'M') {
		dw('<option selected="selected" value="1">'+entity[z].manlabel+'</option>');
		dw('<option value="2">'+entity[z].womanlabel+'</option>');
		}
	
		else {
		dw('<option value="1">'+entity[z].manlabel+'</option>');
		dw('<option selected="selected" value="2">'+entity[z].womanlabel+'</option>');
		}
	
	dw('</select>');
	dw('</span>');
	dw('</div>');
	dw('<div class="ThemGenderBlock">');
	dw('<label id="seekinglabel">'+entity[z].seekinglabel+'</label>');
	dw('<span>');
	dw('<select id="tr">');
	
		if (''+entity[z].primarygender == 'M') {
		dw('<option value="1">'+entity[z].seekingmanlabel+'</option>');
		dw('<option selected="selected" value="2">'+entity[z].seekingwomanlabel+'</option>');
		}
	
		else{
		dw('<option selected="selected" value="1">'+entity[z].seekingmanlabel+'</option>');
		dw('<option value="2">'+entity[z].seekingwomanlabel+'</option>');	
		}
	
	dw('</select>');
	dw('</span>');
	dw('</div>');
	dw('<div class="AgeBlock">');
	dw('<label id="fromlabel" class="from">'+entity[z].fromagelabel+'</label>');
	dw('<span>');
	var x;
	dw('<select id="lage">');
	for(x=18; x<= 105; x++) { dw('<option value="'+x+'">'+x+'</option>'); }
	dw('</select>');
	document.getElementById('lage').value = ''+entity[z].agerange.substring(0,2);
	dw('<label id="tolabel" class="to">'+entity[z].toagelabel+'</label>');
	var y;
	dw('<select id="uage">');
	for(y=18; y<= 105; y++) { dw('<option value="'+y+'">'+y+'</option>'); }
	dw('</select>');
	document.getElementById('uage').value = ''+entity[z].agerange.substring(3,5);
	dw('</span>');
	dw('</div>');
	dw('<div class="GeoStateBlock">');
	dw('<label id="statelabel">'+entity[z].provincelabel+'</label>');
	dw('<span>');
	dw('<select id="regions">');
	dw(regions);
	dw('</select>');
	dw('</span>');
	dw('</div>');
	dw('<a href="#" id="searchbutton" onclick="execqsearch('+entity[z].countrycode+','+q+','+p+','+r+');">');
	dw('<img id="searchbuttonimg" class="rplbtn" src="http://cp.intl.match.com/msn/en-th/img/mil_search_r01bg_1.png" border="0" alt="ค้นหา" />');
	dw('</a>');
	dw('</div>');
			} // end else
		} // end loop
	} // end outer else
} // end function

