error_count=0;
self.onerror=report_error;
bIsIE = false;
function Populate()
{
	if (parseInt(navigator.appVersion[0])<4)
	{
		alert(notice);
		location.href="/search/male_model_fulllist.asp";
		return false;
	}
	if (String(navigator.appName).indexOf("Microsoft",0)>=0)
	{
		bIsIE = true;
	}
	setTimeout("update()", 300);
	return true;
}
function update()
{
	x = self.document.searchform;
	x.models.options.length = 0;
	
	var hairtype=new Array();
	var eyecolor=new Array();
	var ent=new Array();
	
	hlow = x.heightlow.options[x.heightlow.selectedIndex].value;
	hhi = x.heighthi.options[x.heighthi.selectedIndex].value;
	if (hlow > hhi)
	{
		x.heighthi.selectedIndex=x.heightlow.selectedIndex;
		hlow = hhi;
	}
	var dslow = new String();
	var dshi = new String();
	
	dslow = x.sizelow.options[x.sizelow.selectedIndex].value;
	dshi = x.sizehi.options[x.sizehi.selectedIndex].value;
	if (!checkpic(dslow, dshi, x.sizelow, x.sizehi)){
		dslow = dshi;}
	
	sslow = x.shoelow.options[x.shoelow.selectedIndex].value;
	sshi = x.shoehi.options[x.shoehi.selectedIndex].value;
	if (!checkpic(sslow, sshi, x.shoelow, x.shoehi)){
		sslow = sshi;}
	
	collow = x.collarlow.options[x.collarlow.selectedIndex].value;
	colhi = x.collarhi.options[x.collarhi.selectedIndex].value;
	if (!checkpic(collow, colhi, x.collarlow, x.collarhi)){
		collow = colhi;}
	
	slevelow = x.sleevelow.options[x.sleevelow.selectedIndex].value;
	slevehi = x.slevehi.options[x.slevehi.selectedIndex].value;
	if (!checkpic(slevelow, slevehi, x.sleevelow, x.slevehi)){
		slevelow = slevehi;}

	wlow = x.waistlow.options[x.waistlow.selectedIndex].value;
	whi = x.waisthi.options[x.waisthi.selectedIndex].value;
	if (!checkpic(wlow, whi, x.waistlow, x.waisthi)){
		wlow = whi;}

	inlow = x.inseamlow.options[x.inseamlow.selectedIndex].value;
	inhi = x.inseamhi.options[x.inseamhi.selectedIndex].value;
	if (!checkpic(inlow, inhi, x.inseamlow, x.inseamhi)){
		inlow = inhi;}

	agelow = x.agelow.options[x.agelow.selectedIndex].value;
	agehi = x.agehi.options[x.agehi.selectedIndex].value;
	if (!checkpic(agelow, agehi, x.agelow, x.agehi)){
		agelow = agehi;}

	IncludeOutOfTown = (x.OutOfTown.checked==true);
	IncludeBilingual = (x.Bilingual.checked==true);

	for (i=0; i < x.elements.length; i++)
	{
		if (x.elements[i].type == "checkbox")
		{
			if (x.elements[i].checked)
			{
				if(x.elements[i].name=="hair"){
					hairtype[hairtype.length]=new String(x.elements[i].value);}
				else if(x.elements[i].name=="eyes"){
					eyecolor[eyecolor.length]=new String(x.elements[i].value);}
				else if(x.elements[i].name=="ethnicity"){
					ent[ent.length]=new String(x.elements[i].value);}
			}
				
		}
	}
	idx=0;

	for (i=0; i < Mal.length; i++)
	{
	
		if (isMatch(hairtype, Mal[i][5]) &&
			isMatch(eyecolor, Mal[i][6]) &&
			Mal[i][2] >= hlow && Mal[i][2] <= hhi &&
			// dress size
			((parseInt(Mal[i][3]) >= parseInt(dslow)) &&
			(parseInt(Mal[i][3]) <= parseInt(dshi)) )&&
			// shoe size
			((parseInt(Mal[i][4]) >= parseInt(sslow)) &&
			(parseInt(Mal[i][4]) <= parseInt(sshi)) )&&
			// collar
			((parseInt(Mal[i][7]) >= parseInt(collow)) &&
			(parseInt(Mal[i][7]) <= parseInt(colhi)) ) &&
			//sleeve
			((parseInt(Mal[i][8]) >= parseInt(slevelow)) &&
			(parseInt(Mal[i][8]) <= parseInt(slevehi)) ) && 
			//waist
			((parseInt(Mal[i][9]) >= parseInt(wlow)) &&
			(parseInt(Mal[i][9]) <= parseInt(whi)) ) &&
			//inseam
			((parseInt(Mal[i][10]) >= parseInt(inlow)) &&
			(parseInt(Mal[i][10]) <= parseInt(inhi)) ) &&
			//age
			(Mal[i][11] >= agelow)&& (Mal[i][11] <= agehi) &&
			//etnicity
			isMatch(ent, Mal[i][12]) &&
			(IncludeOutOfTown==true | (Mal[i][14] == 0)) &&
			((IncludeBilingual==true  && (Mal[i][15] == 1))||IncludeBilingual==false)
			)
		{
			x.models.options[idx] = new Option(Mal[i][1]+', '+ Mal[i][0], i);
			idx++;
		}
		//else
			//alert(idx);
	}
	if (idx > 0)
	{
        if (GetCookie("MaleModelSearchID") != null) x.models.options[GetCookie("MaleModelSearchID")].selected = true; 
        else x.models.options[0].selected = true; 
		go(x.models)
	}
	else
	{
		x.models.options[0]=new Option("No matches found");
		x.models.options[1]=new Option("Please modify Search");
			
		if (bIsIE)
		{
			self.document.images[0].alt = "Click to reset search";
			self.document.images[0].title= "Click to reset search";
		}
		self.document.links[0].href="";
	    with (document) {
            if (self.document.images.length){
                self.document.images[self.document.images.length-1].src = "../images/notfound.jpg";}
            else{
                self.document.images.src = "../images/notfound.jpg";}
        }	
		
	}
	x.nummat.value=idx + " Matches Found";
	if (bIsIE)
		x.style.cursor = "default";
	return true;
}
function go()
{
	if (idx == 0){
		return false;}
	var n = self.document.searchform.models.selectedIndex;
	document.cookie = "MaleModelSearchID=" + n; 
	var urlName = "";
	var urlLink = "";
	var lastName = "";
	var firstName = "";

	urlName = "../male/images/";
	urlLink = "../male/";
		
	offset = parseInt(self.document.searchform.models.options[n].value);

	firstName = Mal[offset][0];
	lastName = Mal[offset][1];

	var hvr=new String();
	hvr = "Name: "+firstName+" " +
			lastName + 
			"\nHair: "+ Mal[offset][5]+
			"\nEyes: "+ Mal[offset][6]+
			"\nHeight: "+ getHeight(Mal[offset][2])+
			"\nSize: "+ Mal[offset][3]+
			"\nShoe: "+ Mal[offset][4]+
			"\nEthnicity: " + Mal[offset][12];
	
	if (lastName.indexOf(" ") > 0)
	{
		lastNameTHB = lastName.substring(0,lastName.indexOf(" ")) +"_"+lastName.substring(lastName.indexOf(" ")+1,lastName.length);
		lastNameLNK = lastName.substring(0,lastName.indexOf(" ")) +"%20"+lastName.substring(lastName.indexOf(" ")+1,lastName.length);
	}
	else
	{
		lastNameTHB = lastName;
		lastNameLNK = lastName;
	}
	if (firstName.indexOf(" ") > 0)
	{
		firstNameTHB = firstName.substring(0,firstName.indexOf(" ")) +"_"+firstName.substring(firstName.indexOf(" ")+1,firstName.length);
		firstNameLNK = firstName.substring(0,firstName.indexOf(" ")) +"%20"+firstName.substring(firstName.indexOf(" ")+1,firstName.length);
	}
	else
	{
		firstNameTHB = firstName;
		firstNameLNK = firstName;
	}


   lastNameTHB = lastName; 
   lastNameLNK = lastName; 
   if (lastName.indexOf(" ") > 0) {
      lastNameTHB = lastName.substring(0, lastName.indexOf(" ")) + "_" + lastName.substring(lastName.indexOf(" ") + 1, lastName.length); 
      lastNameLNK = lastName.substring(0, lastName.indexOf(" ")) + "%20" + lastName.substring(lastName.indexOf(" ") + 1, lastName.length); 
      }
   if (firstNameTHB.indexOf("*") >= 0) firstNameTHB = ""; 
   
   
	urlLink += "male_"+Mal[offset][13]+"pics.asp?FirstName="+firstNameLNK+"&LastName="+lastNameLNK;
	urlName += firstNameTHB.substring(0,1) + "/"+firstNameTHB + lastNameTHB +"_THB.jpg";
	
   ImageTemp = document.getElementById("TalentImage"); 
   ImageLinkTemp = document.getElementById("ImageLink"); 
   if(ImageTemp != null) {
      ImageLinkTemp.href = urlLink; 
      ImageTemp.alt = "Name: " + Mal[offset][0] + " " + lastName; 
      ImageTemp.title = hvr; 
      ImageTemp.src = urlName; 
      }
	return true;
}