
var error_count=0;
//self.onerror=report_error;
var urlName = "nothing";
var bIsIE = false;

$(document).ready(function () {
    Populate();
    update();
});

function Populate()
{
	if (parseInt(navigator.appVersion[0])<4)
	{
		//alert(notice);
		//location.href="../female/FemaleListLastName.htm";
		//return false;
		goodversion = false;
	}
	if (String(navigator.appName).indexOf("Microsoft",0)>=0)
	{
		bIsIE = true;
	}
	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;}
	
	bblow = x.bustlow.options[x.bustlow.selectedIndex].value;
	bbhi = x.busthi.options[x.busthi.selectedIndex].value;
	if (!checkpic(bblow, bbhi, x.bustlow, x.busthi)){
		bblow = bbhi;}
	
	bwlow = x.wlow.options[x.wlow.selectedIndex].value;
	bwhi = x.whi.options[x.whi.selectedIndex].value;
	if (!checkpic(bwlow, bwhi, x.wlow, x.whi)){
		bwlow = bwhi;}

	bhlow = x.hipslow.options[x.hipslow.selectedIndex].value;
	bhhi = x.hipshi.options[x.hipshi.selectedIndex].value;
	if (!checkpic(bhlow, bhhi, x.hipslow, x.hipshi)){
		bhlow = bhhi;}
	
	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 < Fem.length; i++)
	{
		
		if (isMatch(hairtype, Fem[i][6]) &&
			isMatch(eyecolor, Fem[i][7]) &&
			Fem[i][3] >= hlow && Fem[i][3] <= hhi &&
			// dress size
			((parseInt(Fem[i][4]) >= parseInt(dslow)) &&
			(parseInt(getHi(Fem[i][4])) <= parseInt(dshi)) ||
			Fem[i][4] == "-")&&
			// shoe size
			((parseInt(Fem[i][5]) >= parseInt(sslow)) &&
			(parseInt(getHi(Fem[i][5])) <= parseInt(sshi)) )&&
			// bust
			((parseInt(Fem[i][8]) >= parseInt(bblow)) &&
			(parseInt(Fem[i][8]) <= parseInt(bbhi)) ) &&
			//waist
			((parseInt(Fem[i][9]) >= parseInt(bwlow)) &&
			(parseInt(Fem[i][9]) <= parseInt(bwhi)) ) && 
			//hips
			((parseInt(Fem[i][10]) >= parseInt(bhlow)) &&
			(parseInt(Fem[i][10]) <= parseInt(bhhi)) ) &&
			
			//age
			(Fem[i][11] >= agelow)&& (Fem[i][11] <= agehi) &&
			//etnicity
			isMatch(ent, Fem[i][12]) &&
			(IncludeOutOfTown==true | (Fem[i][14] == 0)) &&
			((IncludeBilingual==true  && (Fem[i][15] == 1))||IncludeBilingual==false)
			)
		{
			x.models.options[idx] = new Option(Fem[i][2]+', '+ Fem[i][0], i);
			idx++;
		}
		//else
			//alert(idx);
	}
	if (idx > 0)
	{
	    if (GetCookie("FemaleModelSearchID") != null && x.models.options[GetCookie("FemaleModelSearchID")] != null)
	    { x.models.options[GetCookie("FemaleModelSearchID")].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 = "FemaleModelSearchID=" + n; 
	var urlName = "";
	var urlLink = "";
	var lastName = "";
	var firstName = "";

	urlName = "/female/images/";
	urlLink = "/female/";
		
	offset = parseInt(self.document.searchform.models.options[n].value);

	firstName = Fem[offset][0];
	lastName = Fem[offset][2];
	
	var hvr=new String();
	hvr = "Name: "+Fem[offset][0]+" " +
			lastName + 
			"\nHair: "+ Fem[offset][6]+
			"\nEyes: "+ Fem[offset][7]+
			"\nHeight: "+ getHeight(Fem[offset][3])+
			"\nBody: "+ Fem[offset][8]+"-"+Fem[offset][9]+"-"+Fem[offset][10]+
			"\nSize: "+ Fem[offset][4]+
			"\nShoe: "+ Fem[offset][5]+
			"\nEthnicity: " + Fem[offset][12];

	firstNameTHB = SpaceReplace(firstName);
	lastNameTHB = SpaceReplace(lastName);
	firstNameLNK = URLSpaceReplace(firstName);
	lastNameLNK = URLSpaceReplace(lastName);

	var np = Fem[offset][13];
	if (np) {
	    urlLink = "/female/portfolio.asp?ID=" + Fem[offset][16];
	}
	else {
	    urlLink += "female_" + np + "pics.asp?FirstName=" + firstNameLNK + "&LastName=" + lastNameLNK;
	}
	urlName += firstNameTHB.substring(0,1) + "/"+ firstNameTHB + lastNameTHB +"_THB.jpg";

   if (firstNameTHB.indexOf("*") >= 0) firstNameTHB = ""; 
   
   ImageTemp = document.getElementById("TalentImage"); 
   ImageLinkTemp = document.getElementById("ImageLink"); 
   if(ImageTemp != null) {
      ImageLinkTemp.href = urlLink; 
      ImageTemp.alt = "Name: " + Fem[offset][0] + " " + lastName; 
      ImageTemp.title = hvr; 
      ImageTemp.src = urlName; 
      }
	return true;
}

