/* ----------------------------------------------------------------------------------------
File Name: General_Functions.js

	This file handles general functions.
 ----------------------------------------------------------------------------------------*/
var _gGroup = 0;
var first_time2 = true;
var last_item	= "";
//var printObj;

function popUpWindow(URLStr, left, top, width, height)
{
	var popUpWin=0;
	if(popUpWin)
	{
		if(!popUpWin.closed) popUpWin.close();
	}
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	popUpWin.focus();
}

function limit(El)
{
	if(El.value.length >= 40)
		El.value = El.value.substring(0,40);
}

//--------------------------------------------------------------------------------
function initGroupSelected(makeLast_item)//first group is already selected when entering the page
{
	//document.getElementById("hidGroup").value = 0;
	last_item = document.getElementById(makeLast_item).id;
	first_time2 = false;
}

function initGroupSelectedParts(makeLast_itemParts)//first group is already selected when entering the page
{
	document.getElementById("hiddGroupName").value = grName;
	document.getElementById("hiddGroupID").value = 1;
	last_itemParts = document.getElementById(makeLast_itemParts).id;
	first_time2Parts = false;
}

function selectGroupID(group)//not from leads page
{
	document.getElementById("hiddGroupID").value = group;
	//alert(document.getElementById("hiddGroupID").value)
	loadCats(group);
}

function selectPartsWParts(group)//only in leads page: changing from parts to whole sale parts
{
	if(group == 5)//whole sale parts
	{
		//in the quick quote page (the only one that has the sixth group), only registered mechanics can view whole sale parts group:
		if(document.getElementById("hiddIsLogin").value != "1" && document.getElementById("spnMsg"))//not logged in
		{
			document.getElementById("ImgSubmit").style.visibility = "hidden";//disable the submit button
			document.getElementById("spnMsg").innerHTML = "Only for logged-in mechanics.";
		}
	}
	else
	{
		document.getElementById("ImgSubmit").style.visibility = "visible";//enable the submit button
		document.getElementById("spnMsg").innerHTML = "";
	}
}

function selectGroupIDParts(group)//only in leads page: changing from car,motorcycle,boats
{
	switch(group)
	{
		case 1:
			grName = "CAR";
			document.getElementById("spnMakeTitle").innerHTML = "Car: ";
			document.getElementById("tr_userdefined_boat").style.display = "none";
			document.getElementById("trSize_car").style.display = "block";
			document.getElementById("trMotor_boat").style.display = "none";
			break;
		case 2:
			grName = "MOTORCYCLE";
			document.getElementById("spnMakeTitle").innerHTML = "Motorcycle: ";
			document.getElementById("tr_userdefined_boat").style.display = "none";
			document.getElementById("trSize_car").style.display = "none";
			document.getElementById("trMotor_boat").style.display = "none";
			break;
		case 3:
			grName = "BOAT";
			document.getElementById("spnMakeTitle").innerHTML = "Boat: ";
			document.getElementById("tr_userdefined_boat").style.display = "block";
			document.getElementById("trSize_car").style.display = "none";
			document.getElementById("trMotor_boat").style.display = "block";
			break;		
	}
	
	var modelsCombo = document.getElementById("models");
	for (var i=modelsCombo.options.length;i>0;i--)
		modelsCombo.options[i] = null;
		
	loadMakes();
	loadParts();

	document.getElementById("hiddGroupID").value = group;
	document.getElementById("hiddGroupName").value = grName;
}

function GroupItParts(El)
{
	if (El.state !== "down")
	{
		if(first_time2Parts)
		{
			last_itemParts = El.id;
			first_time2Parts = false;
		}
		else
		{
			if(document.getElementById(last_itemParts))
			{
				document.getElementById(last_itemParts).state = "";
				document.getElementById(last_itemParts).style.cursor = "hand";
				document.getElementById(last_itemParts).src =  "images/" + last_itemParts + "_normal.gif";
			}
			last_itemParts = El.id;
		}
				
		El.style.cursor = "normal";
		El.src = "images/" + El.id + "_over" + ".gif";
		El.state = "down";
	}
} 

function GroupIt(El)
{
	if (El.state !== "down")
	{
		if(first_time2)
		{
			last_item = El.id;
			first_time2 = false;
		}
		else
		{
			if(document.getElementById(last_item))
			{
				document.getElementById(last_item).state = "";
				document.getElementById(last_item).style.cursor = "hand";
				document.getElementById(last_item).src =  "images/" + last_item + "_normal.gif";
			}
			last_item = El.id;
		}
				
		El.style.cursor = "normal";
		El.src = "images/" + El.id + "_over" + ".gif";
		El.state = "down";
	}
} 
function OverIt(El)
{
	if (El.state !== "down")
	{
		El.src = "images/" + El.id + "_over" + ".gif";
		El.state = "over";
	}	
}
function OutIt(El)
{
	if (El.state == "over")
	{
		El.state = "";
		El.src = "images/" + El.id + "_normal" + ".gif";
	}	
	else if (El.state !== "over" && El.state !== "down")
			El.src = "images/" + El.id+ "_normal" + ".gif";
}

function PrintData(type)
{
	/*switch(type)
	{
		case 1:
			printObj = document.getElementById("content");
			break;
	}*/
	
	printWin = open("includes/printWin.html", 'printWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=0,height=0,left=2000, top=2000');
}

function selectAllLeads()
{
	allCb = document.getElementsByTagName("INPUT");
	
	for(var i=0; i<allCb.length; i++)
	{
		if(allCb[i].type == "checkbox")
			allCb[i].checked = true;
	}	
}

function clearAllLeads()
{
	allCb = document.getElementsByTagName("INPUT");
	
	for(var i=0; i<allCb.length; i++)
	{
		if(allCb[i].type == "checkbox")
			allCb[i].checked = false;
	}	
}
function doSubmit()
{
	document.getElementById("hiddOne").value = "";
	document.getElementById("Form1").submit();
}

//quick quote send one mail to one lead
function sendDetails(strMail,stID)
{
	if(strMail != "")
	{
		//window.location = "ContactLeadsForm.aspx?sID="+sID+"&strMail="+strMail; 
		document.getElementById("hiddOne").value = "1";
		document.getElementById("hiddMail").value = strMail;
		document.getElementById("hiddID").value = stID;
		document.getElementById("Form1").submit();
	}
	else
		alert("This mechnic has no email")
}

function sendToFriend()
{
	sMechID = window.location.search.substring(6);
	//alert(sMechID);
	window.location.href="SendToFriend.aspx?mech="+sMechID;
}

function MakeAppoinment()
{
	sMechMail = document.getElementById("aMechMail").innerHTML;
	
	//alert(sMechMail);
	window.location.href="MakeAppoinment.aspx?mechMail="+sMechMail;
}


//-------------- ASK A MECHANIC -----------------------//
function showAnswer(num)
{
	var el = document.getElementById("divAnswer_"+num);
	if(el.style.display == "inline")
		el.style.display = "none";
	else
		el.style.display = "inline";
}

function openNewWindow(url,width,height) 
{
	window.open(url,'mechanicfinders','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,movable=yes,resizable=yes,width='+width+',height='+height)
}

function Preview(bannerType)
{
	//document.getElementById("spnCompName").innerHTML = document.getElementById("txtName").value;
	maxlength = 0;
	if(bannerType == 1)
		maxlength = 40;
	else if(bannerType == 2)
		maxlength = 100;
	else if(bannerType == 3)
		maxlength = 75;
	//alert(maxlength)
	//alert(document.getElementById("txaDesc").value.substring(0,maxlength))
	//document.getElementById("spnCompDesc").innerHTML = document.getElementById("txaDesc").value.substring(0,maxlength);
	//document.getElementById("spnCompDesc").href =document.getElementById("txtURL").value;
}

//----- log in page functions-----//
function checkFields()
{
	var uName = document.getElementById("txtUserName").value;
	var pass = document.getElementById("txtPassword").value;
	if(uName == "" || pass == "")
		alert("Please enter User name and password and than click the LOG IN button")
	else
		document.getElementById("btnCheck").click();
}

//--- advanced search page functions ------//
function formSubmit_advancedSearch()
{
	document.frm.action = "searchResults.aspx";
	document.frm.submit();
	//alert(document.frm.action)
}