shown_category = 0;
chosen_subcategory = 0;
deleteButtonToBeClicked = '';

var categoryUrls = new Array();
categoryUrls[categoryUrls.length] = '';
categoryUrls[categoryUrls.length] = 'search/VehicleSearch';
categoryUrls[categoryUrls.length] = 'search/RealEstateSearch';
categoryUrls[categoryUrls.length] = 'search/JobSearch';
categoryUrls[categoryUrls.length] = 'search/KahtenSearch';
categoryUrls[categoryUrls.length] = 'search/ProfessionalSearch';
categoryUrls[categoryUrls.length] = 'search/RealEstateKonesTableView';
categoryUrls[categoryUrls.length] = 'search/VehicleKonesTableView';

function preSubmit(form) {
	var formAction = form.action;
	var siteCategotyId = document.getElementById("sc").value;
	var siteSubCategotyId = document.getElementById("ssc").value;
	var pageName;
	
	if(siteCategotyId == 2 && siteSubCategotyId == 6) //RealEstate kones
	{
		pageName = categoryUrls[6];
	}
	else if(siteCategotyId == 1 && siteSubCategotyId == 9) //vehicle kones
		 {
			 pageName = categoryUrls[7];
		 }
		 else
		 {
			 pageName = categoryUrls[shown_category*1];
		 }
	
	
	
	formAction = formAction.replace('HomePage', pageName);
	//alert(formAction);
	form.action = formAction;
}

function showCategory(idx){
	$('category_choose').style.display = 'none';
	$('cat:'+idx+':subcategory').style.display = 'inline';
	shown_category = idx;
	document.getElementById("sc").value=(idx);
	clickSubcategory(idx,1); // select first subcategory
}

function gobackToCategory(){
	$('category_choose').style.display = 'inline';
	$('cat:'+shown_category+':subcategory').style.display = 'none';
	if(chosen_subcategory!=0){
		chosen_subcategory_id='cat:'+chosen_subcategory.charAt(0)+':subCat:'+chosen_subcategory.charAt(1)+':subcategory'
		$(chosen_subcategory_id).className = 'subcategory';

//		$('cat:'+shown_category+':subcategory').className = 'subcategory';
		chosen_subcategory = 0;
	}

	
	shown_category = 0;
	document.getElementById("sc").value=0;
	document.getElementById("ssc").value=0;

	// clear area
	gobackToArea();

}

function overSubcategory(cat, subCat){
	if(chosen_subcategory != (cat+''+subCat)){
		$('cat:'+cat+':subCat:'+subCat+':subcategory').className = 'subcategory_hover';
	}
}

function outSubcategory(cat, subCat){
	if(chosen_subcategory != (cat+''+subCat)){
		$('cat:'+cat+':subCat:'+subCat+':subcategory').className = 'subcategory';
	}
}

function clickSubcategory(cat, subCat, subCatValue){
	if(chosen_subcategory != (cat+''+subCat)){
		if(chosen_subcategory!=0){
			chosen_subcategory_id='cat:'+chosen_subcategory.charAt(0)+':subCat:'+chosen_subcategory.charAt(1)+':subcategory'
			$(chosen_subcategory_id).className = 'subcategory';
		}
		
		$('cat:'+cat+':subCat:'+subCat+':subcategory').className = 'subcategory_hover';
		chosen_subcategory= (cat+''+subCat);
		if (!subCatValue) {
			subCatValue = subCat;
		}
		document.getElementById("ssc").value=subCatValue;
	}	
}

/* AREA FUNCTIONS ***************************************************** */
shown_area = 0; //==chosen area
chosen_subarea = 0;

function showArea(idx){
	clearCities(idx);
	
	
	if (shown_category == 2 && idx != 0){	// Real estate
		$('choose_area').style.display = 'none';
		$('area:'+idx+':subarea').style.display = 'inline';
		$('u_can_choose_more').style.display = 'block';
		setCurrentArea(-1); // clear all
	}
	else{
		setCurrentArea(idx);
	}
	
	shown_area = idx;
	document.getElementById("areaNo").value=idx;
}

function setCurrentArea(idx){
	var maxAreas = 7;
	for (i=0; i<=maxAreas; i++){
		obj = document.getElementById('area_cube_'+i);
		
		if (i == idx){
			obj.className = 'area_cube_'+i+'_hover';
		}
		else{
			obj.className = 'area_cube_'+i;
		}
	}
}


/*
* Old version: user can choose cities in all categories
function showArea(idx){
	clearCities(idx);
	if (idx == 0){
		document.getElementById("areaAll").className="area_cube_all_hover"
	}else{
		document.getElementById("areaAll").className="area_cube_all"
		$('choose_area').style.display = 'none';
		$('area:'+idx+':subarea').style.display = 'inline';
		$('u_can_choose_more').style.display = 'inline';
	}
	shown_area = idx;
	document.getElementById("areaNo").value=idx;
}
*/

function gobackToArea(){
	clearCities(shown_area);
	$('choose_area').style.display = 'inline';
	$('area:'+shown_area+':subarea').style.display = 'none';
	if(chosen_subarea!=0)
	{
		$('area:'+chosen_subarea+':subarea').className = 'subcategory';
		chosen_subarea = 0;
	}
	
	$('u_can_choose_more').style.display = 'none';
	setCurrentArea(0); // clear all
	shown_area = 0;
	document.getElementById("areaNo").value=0;
	document.getElementById("cityNo").value=0;
}

function overSubarea(area, city){
	if(!($('area:'+area+':city:'+city+':subarea').hasClassName('subarea_clicked'))){
		$('area:'+area+':city:'+city+':subarea').className = 'subarea_hover';
	}
}
function outSubarea(area, city){
	if(!($('area:'+area+':city:'+city+':subarea').hasClassName('subarea_clicked'))){
		$('area:'+area+':city:'+city+':subarea').className = 'subarea';
	}
}
function clickSubarea(area, city){
	if (city==0){
		clearCities(area)
	}else{
		subAreaId='area:'+area+':city:'+0+':subarea';
		$(subAreaId).className = 'subarea';
	}
	subAreaId='area:'+area+':city:'+city+':subarea';
	if(!($(subAreaId).hasClassName('subarea_clicked'))){
		$(subAreaId).className = 'subarea_clicked';
	}else{
		$(subAreaId).className = 'subarea';
	}
	document.getElementById("cityNo").value=city;
	selectCity(city);
	
}

function selectCity(city){
	if(city > 0){
		inputs = document.getElementsByName("citiesId");
		
		if(get_browser() > 0){ // IE
			inputs[city+1].click();
		}
		else{ //FF
			inputs[city].click();
		}
		
		//clickOblect(inputs[city+1]);
	}
}

function clearCities(area){
	inputs = document.getElementsByName("citiesId");
	for (i=0; i<11; i++){
		inputs[i].checked=false;
		subAreaId='area:'+area+':city:'+i+':subarea';
		if($(subAreaId)){
			$(subAreaId).className = 'subarea';
		}
	}

}

var currentImg = null;
function overImage(idx, arr){
	//Position.absolutize(idx);
	currentImg = idx;
	is_over=true;
	if(images_texts[arr]!=undefined){
		$('over_img_text').innerHTML = images_texts[arr];
	}else{
		$('over_img_text').innerHTML = "-";
	}
	if(get_browser()==0){// for FF
		$('over_image').style.left = Position.cumulativeOffset(idx)[0]-24 + "px";
		$('over_image').style.top = Position.cumulativeOffset(idx)[1]-7 + "px";
	}else if(get_browser()>=7){// for IE7
		$('over_image').style.left = Position.positionedOffset(idx)[0]-24 + "px";
		$('over_image').style.top = Position.positionedOffset(idx)[1]-6 + "px";
	}else{// for IE6 and else....
		$('over_image').style.left = Position.positionedOffset(idx)[0]+16 + "px";
		$('over_image').style.top = Position.positionedOffset(idx)[1]-6 + "px";
	}
}

function clickImage(){
	if (is_over){
		makeEvent(currentImg.id, 'click');
	}
}

 /**
 * make event for a given elementId and a given event name
 */ 
 function makeEvent(elementId, eventName)
 {
  
  if (get_browser() > 0)
  {
   if (eventName == 'click')
   {
  
    document.getElementById(elementId).click();
   }
   else if (eventName == 'mouseup')
   {
    document.getElementById(elementId).mouseup();
   }
   else
   {
    alert('event not supported !!');
   }
  }
  else //netscape..
  {
   var fireOnThis = document.getElementById(elementId);
   var evObj = document.createEvent('MouseEvents');
   evObj.initEvent( eventName, true, true );
   fireOnThis.dispatchEvent(evObj);
  }
 }
  
function clickOblect(obj){
  
  if (get_browser() > 0)
  {
    obj.click();
  }
  else //netscape..
  {
   var fireOnThis = obj;
   var evObj = document.createEvent('MouseEvents');
   evObj.initEvent( 'click', true, true );
   fireOnThis.dispatchEvent(evObj);
  }

}

function open_choose_field_zone(){
	if($('choose_field_wrap').style.display=='none'){
		$('choose_field_wrap').style.display='inline';
		$('btn_choose_field').className = 'choose_field_wrap_on';
		$('choose_field_iframe').style.height = $('choose_field_content').getDimensions().height;
	}else{
		$('choose_field_wrap').style.display='none';
		$('btn_choose_field').className = 'choose_field_wrap';
	}
}

function closeDealerPopup(row){
	document.getElementById('dealer_page['+row+']').style.display = 'none';
//	new Effect.DropOut('dealer_page['+row+']');
}

//////////////////// Fixed Popup functions start /////////////////////
function popup_contact_owner(obj){
	var the_left_pos = 0;
	if (get_browser()!=0){
		Position.absolutize('contact_owner');
		the_left_pos -= Position.cumulativeOffset($('mainPart'))[0];
	}
	the_left_pos += (Position.cumulativeOffset($(obj).ancestors()[0])[0])+ $(obj).ancestors()[0].getWidth() + 28;	
	var the_top_pos = Position.cumulativeOffset(obj)[1] - 323;
	$('contact_owner').style.left = the_left_pos + "px";
	$('contact_owner').style.top = the_top_pos + "px";
	document.getElementById('contact_owner').style.display='block';
	contact_owner_OnFinish();
//	new Effect.Appear('contact_owner',{ afterFinish: contact_owner_OnFinish });
}

function contact_owner_OnFinish(){
	setIframeHeight('contact_owner');
}

function popup_tell_friend(obj){
	var the_left_pos = 0;
	if (get_browser()!=0){
		Position.absolutize('tell_friend');
		the_left_pos -= Position.cumulativeOffset($('mainPart'))[0];
	}
	the_left_pos += (Position.cumulativeOffset($(obj).ancestors()[0])[0])+ $(obj).ancestors()[0].getWidth() + 28;	
	var the_top_pos = Position.cumulativeOffset(obj)[1] - 353;
	$('tell_friend').style.left = the_left_pos + "px";
	$('tell_friend').style.top = the_top_pos + "px";
	document.getElementById('tell_friend').style.display='block';
	tell_friend_OnFinish();
	//new Effect.Appear('tell_friend',{ afterFinish: tell_friend_OnFinish });
}

function tell_friend_OnFinish(){
	setIframeHeight('tell_friend');
}

function popup_contact_metavech(obj){
	var the_left_pos = 0;
	if (get_browser()!=0){
		Position.absolutize('contact_metavech');
		the_left_pos -= Position.cumulativeOffset($('mainPart'))[0];
	}
	the_left_pos += (Position.cumulativeOffset($(obj).ancestors()[0])[0])+ $(obj).ancestors()[0].getWidth() + 28;	
	var the_top_pos = Position.cumulativeOffset(obj)[1] - 323;
	$('contact_metavech').style.left = the_left_pos + "px";
	$('contact_metavech').style.top = the_top_pos + "px";
	document.getElementById('contact_metavech').style.display='block';
	contact_metavech_OnFinish();
	//new Effect.Appear('contact_metavech',{ afterFinish: contact_metavech_OnFinish });
}
function contact_metavech_OnFinish(){
	setIframeHeight('contact_metavech');
}

function popup_submit_cv_owner(obj){
	var the_left_pos = 0;
	if (get_browser()!=0){
		Position.absolutize('submit_cv');
		the_left_pos -= Position.cumulativeOffset($('mainPart'))[0] - 60;
	}
	the_left_pos += (Position.cumulativeOffset($(obj).ancestors()[0])[0])+ $(obj).ancestors()[0].getWidth() - 193;	
	var the_top_pos = Position.cumulativeOffset(obj)[1] - 400;
	$('submit_cv').style.left = the_left_pos + "px";
	$('submit_cv').style.top = the_top_pos + "px";
	
	document.getElementById('submit_cv').style.display='';
	//submit_cv_OnFinish();
	//new Effect.Appear('submit_cv',{ afterFinish: submit_cv_OnFinish });
}
function submit_cv_OnFinish(){
	setIframeHeight('submit_cv');
}


function validateWizardInput(){
	//alert('cat='+shown_category+'; sub='+chosen_subcategory+'; area='+shown_area+'; city='+chosen_subarea);
	if (shown_category == 2) {
		inputs = document.getElementsByName("citiesId");
		var cities = '';
		for(var i = 1; i < inputs.length; i++) {
			if(inputs[i].checked) {
				cities += inputs[i].value + ',';
				//alert(inputs[i].value);
			}
		}
		//alert(cities.substring(0, cities.length - 1));	
		document.getElementById("cityNo").value = cities.substring(0, cities.length - 1);
	}
	
	var res = true;
	if (!parseInt($('ssc').value) > 0){
		res = false;
		if ($('wizardFrm:errorMsg')) {		
			$('wizardFrm:errorMsg').style.display = 'block';
		}
	}
	return res;
}



/**
*return selected index from radio buttons
*/
function getSelectedFromRadio(obj){
	var result;
	var maxLength = obj.length;
	
	for (var i=0;i<maxLength;i++)
	{
		if(obj[i].checked){
			result = obj[i].value;
			break;
		}
	}
	
	return result;
}


/*
 * return the index of a selected radio button
 */
function getRadioButtonValueById(objRadioId){
	var obj = document.getElementsByName(objRadioId);
	var result = 0;

	result = getSelectedFromRadio(obj)
	//alert('result ='+result)
	return result;
}



function validateCheckbox(objCBox, objMsg){
	var result = true;
	if (!document.getElementById(objCBox).checked){
		document.getElementById(objMsg).style.display='block';
		result = false;
	}
	else{
		document.getElementById(objMsg).style.display='none';
	}
	return result;
}

/**
 * called from adType
 * @param objCBox
 * @param objMsg
 * @param objRadioId
 * @param compareRadioIndex
 * @return
 */
function checkPageConstraints(objCBox, objMsg, objRadioId, compareRadioIndex){
	var checkBoxResult = validateCheckbox(objCBox, objMsg);
	var selectedRadiovalue = getRadioButtonValueById(objRadioId)
	
//	alert('checkBoxResult= '+checkBoxResult)
//	alert('selectedRadiovalue = ' +selectedRadiovalue);
//	alert('compareRadioIndex = ' + compareRadioIndex);
//	alert(checkBoxResult && (selectedRadiovalue == compareRadioIndex));
	return (checkBoxResult && (selectedRadiovalue == compareRadioIndex));
 }


function popupCompanyCard(obj){

	var the_left_pos = 0;
	var browserType = get_browser();
	
	if (browserType!=0){
		
		Position.absolutize('companyCardDiv');
		
		if(browserType == 7){ 			///IE7
			the_left_pos -= Position.cumulativeOffset($('mainPart'))[0];
		}
		else if (browserType == 6){ 		///IE6
				the_left_pos -= Position.cumulativeOffset($('mainPart'))[0] + 150;
			}
		
	}
	the_left_pos += (Position.cumulativeOffset($(obj).ancestors()[0])[0])+ $(obj).ancestors()[0].getWidth() + 28;	
	var the_top_pos = Position.cumulativeOffset(obj)[1] - 353 - 250;
	
	$('companyCardDiv').style.left = the_left_pos + "px";
	$('companyCardDiv').style.top = the_top_pos + "px";
	document.getElementById('companyCardDiv').style.display='block';
	popupCompanyCard_OnFinish();

//	new Effect.Appear('companyCardDiv',{ afterFinish: popupCompanyCard_OnFinish });
}
function popupCompanyCard_OnFinish(){
	setIframeHeight('companyCardDiv');
//	displayBackground();
}

function popup_user_and_password(obj){
	var the_left_pos = 0;
	if (get_browser()!=0)
	{
		Position.absolutize('user_and_password');
		the_left_pos -= Position.cumulativeOffset($('mainPart'))[0];
	}
	the_left_pos += (Position.cumulativeOffset($(obj).ancestors()[0])[0])+ $(obj).ancestors()[0].getWidth() + 18;	
	var the_top_pos = Position.cumulativeOffset(obj)[1]-45;
	$('user_and_password').style.left = the_left_pos + "px";
	$('user_and_password').style.top = the_top_pos + "px";
	document.getElementById('user_and_password').style.display='block';
	popup_user_and_password_OnFinish();
//	new Effect.Appear('user_and_password',{ afterFinish: popup_user_and_password_OnFinish });
	
}
function popup_user_and_password_OnFinish(){
	setIframeHeight('user_and_password');
//	displayBackground();
}

function popupConfirmDeletion(obj){
	var idPrefix = obj.id;
	var the_left_pos = 0;
	
	deleteButtonToBeClicked = idPrefix + 'Delete';
	
	if (get_browser()!=0)
	{
		Position.absolutize('confirmDeletion');
		the_left_pos -= Position.cumulativeOffset($('mainPart'))[0];
	}
	the_left_pos += (Position.cumulativeOffset($(obj).ancestors()[0])[0])+ $(obj).ancestors()[0].getWidth() + 18;	
	var the_top_pos = Position.cumulativeOffset(obj)[1]-45;
	$('confirmDeletion').style.left = the_left_pos + "px";
	$('confirmDeletion').style.top = the_top_pos + "px";
	document.getElementById('confirmDeletion').style.display='block';
	popupConfirmDeletionOnFinish();
//	new Effect.Appear('confirmDeletion',{ afterFinish: popupConfirmDeletionOnFinish });
	
}
function popupConfirmDeletionOnFinish(){
	setIframeHeight('confirmDeletion');
}

function popup_dealer_page(obj){
	var the_left_pos = Position.cumulativeOffset($('top_logo'))[0] + $('top_logo').getWidth();
	var the_top_pos = Position.cumulativeOffset(obj)[1] - 200;
	$('dealer_page').style.left = (the_left_pos - $('dealer_page').getWidth() - 10) + "px";
	$('dealer_page').style.top = the_top_pos + "px";
	new Effect.Appear('dealer_page',{ afterFinish: dealer_page_OnFinish });
}

function dealer_page_OnFinish(){
	setIframeHeight('dealer_page');
}

function popup_about_me(obj){
	var the_left_pos = (Position.cumulativeOffset($(obj).ancestors()[0])[0])+ $(obj).ancestors()[0].getWidth() + 28;
	var the_top_pos = Position.cumulativeOffset(obj)[1] - 270;
	$('about_me').style.left = the_left_pos + "px";
	$('about_me').style.top = the_top_pos + "px";
	new Effect.Appear('about_me',{ afterFinish: popup_about_me_OnFinish });
}

function popup_about_me_OnFinish(){
	setIframeHeight('about_me');
}

function popup_about_you(obj){
	var the_left_pos = (Position.cumulativeOffset($(obj).ancestors()[0])[0])+ $(obj).ancestors()[0].getWidth() + 28;
	var the_top_pos = Position.cumulativeOffset(obj)[1] - 270;
	$('about_you').style.left = the_left_pos + "px";
	$('about_you').style.top = the_top_pos + "px";
	new Effect.Appear('about_you',{ afterFinish: popup_about_you_OnFinish });
}

function popup_about_you_OnFinish(){
	setIframeHeight('about_you');
}

function popup_partners(obj){
	var the_left_pos = (Position.cumulativeOffset($(obj).ancestors()[0])[0])+ $(obj).ancestors()[0].getWidth() + 28;
	var the_top_pos = Position.cumulativeOffset(obj)[1] - 500;
	$('popup_partners').style.left = the_left_pos + "px";
	$('popup_partners').style.top = the_top_pos + "px";
	new Effect.Appear('popup_partners',{ afterFinish: popup_partners_OnFinish });
}

function popup_partners_OnFinish(){
	setIframeHeight('popup_partners');
}

//////////////////// Fixed Popup functions end /////////////////////

function displayBackground(){

	document.getElementById('backgroundDiv').style.display='block'; 
	document.getElementById('backgroundDiv').style.height = document.body.scrollHeight + 'px'; 
}

/**
* recieves id of input with phone prefix and number,
* if it is valid phone prefix and number, returns true,
* otherwise - false
*/
function validatePhone(prefixId, numberId){
	var result = true;
	var prefix = document.getElementById(prefixId).value;
	var number = document.getElementById(numberId).value;

	if (prefix != parseInt(prefix) || prefix.length < 2){
		result = false;
	}
	if (number != parseInt(number) || number.length < 7){
		result = false;
	}

	return result;
}


function popupMiniSite(objId)
{
	var obj				= document.getElementById(objId);
	var the_left_pos	= Position.cumulativeOffset($('top_logo'))[0] + $('top_logo').getWidth();
	var the_top_pos		= 600; //just a number to ensure the window is displayed. should never use that number.
	
	if (obj == null) //to avoid js errors. should never get here..
	{
//	 alert('objId:' + objId);
	}	
	else
	{
	 the_top_pos = Position.cumulativeOffset(obj)[1] - 300;
	}
	
	$('popupMiniSite').style.left = (the_left_pos - $('popupMiniSite').getWidth() - 100) + "px";
	$('popupMiniSite').style.top = the_top_pos + "px";
	document.getElementById('popupMiniSite').style.display='block';
	new Effect.Appear('popupMiniSite');
	//big_picture_OnFinish();
	
}

var currentClickedImagePreviewSrc="";
function popup_large_image(objId)
{
	var obj				= document.getElementById(objId);
	var the_left_pos	= Position.cumulativeOffset($('top_logo'))[0] + $('top_logo').getWidth();
	var the_top_pos		= 600; //just a number to ensure the window is displayed. should never use that number.

	if (obj == null) //to avoid js errors. should never get here..
	{
//	 alert('objId:' + objId);
	}	
	else
	{
	 the_top_pos = Position.cumulativeOffset(obj)[1] - 353;
	}

	$('big_picture').style.left = (the_left_pos - $('big_picture').getWidth()) + "px";
	$('big_picture').style.top = the_top_pos + "px";
	document.getElementById('big_picture').style.display='block';
	big_picture_OnFinish();
}

function big_picture_OnFinish(){
	setIframeHeight('big_picture');
}

function popupImageChangePic(url){
	document.getElementById('popupPictureMainImg').src=url;//obj.src;
}

function popupImageChangePicPreview(){
	document.getElementById('popupPictureMainImg').src = currentClickedImagePreviewSrc;
}

function popup_large_video(obj,src){
	var the_left_pos = Position.cumulativeOffset($('top_logo'))[0] + $('top_logo').getWidth();
	var the_top_pos = Position.cumulativeOffset(obj)[1] - 300;
	$('big_video').style.left = (the_left_pos - $('big_video').getWidth()) + "px";
	$('big_video').style.top = the_top_pos + "px";
	document.getElementsByName('videoIFrame')[0].src=src;
	document.getElementById('big_video').style.display='block';
	big_picture_OnFinish();
//	new Effect.Appear('big_video',{ afterFinish: big_picture_OnFinish });
}
function big_picture_OnFinish(){
	setIframeHeight('big_video');
}

/* ////////////////////////////  POPUPS start //////////////////////////////////////////////// */

function setIframeHeight(idx){
	if(get_browser()=="0"){// in case of firefox we dont need the iframe
		$(idx+"_iframe").style.display='none';
	}else{
		// to set the Iframe height according the current popup images (corners)
		var decrease_height=0;
		switch(idx){
			case "tell_friend":decrease_height=18;break;
			case "contact_service":decrease_height=18;break;
			case "big_picture":decrease_height=30;break;
			case "dealer_page":decrease_height=30;break;
			case "contact_owner":decrease_height=18;break;
			case "big_video":decrease_height=30;break;
			default:decrease_height=18;break;
		}
		$(idx+"_iframe").style.height = ($(idx).getDimensions().height-decrease_height)+ "px";
	}
}

function popup_contact_service(obj){
	document.getElementById('contact_service').style.display = "block";
	contact_service_OnFinish('contact_service');
//	new Effect.Appear('contact_service',{ afterFinish: contact_service_OnFinish });
}

function contact_service_OnFinish(popUpId){
	setIframeHeight(popUpId);
}

function popup_contact_service_kones(obj){
	document.getElementById('contact_service_kones').style.display = "block";
	contact_service_OnFinish('contact_service_kones');
}



/* ////////////////////////////  POPUPS end //////////////////////////////////////////////// */

/**
* Return true if there are at leas one checkbox is selected inside 'adsResults' div. For use in personal area.
*/
function countSelectedFavoritesAds(){
	result = false;
	var objs = document.getElementById('adsResults').getElementsByTagName('INPUT');
	var objsCount = objs.length;
	for(i=0; i < objsCount; i++){
		obj=objs[i];
		if (obj.checked){
			result = true;
			break;
		}
	}
	return result;
}

/*
*
*/
function popup_partnersInAd(obj){
	var the_left_pos = 0;
	if (get_browser()!=0)
	{
		Position.absolutize('popup_partnersInAd');
		the_left_pos -= Position.cumulativeOffset($('mainPart'))[0];
	}
	the_left_pos += (Position.cumulativeOffset($(obj).ancestors()[0])[0])+ $(obj).ancestors()[0].getWidth() - 100;	
	var the_top_pos = Position.cumulativeOffset(obj)[1]-500;
	$('popup_partnersInAd').style.left = the_left_pos + "px";
	$('popup_partnersInAd').style.top = the_top_pos + "px";
//	new Effect.Appear('popup_partnersInAd');
	document.getElementById('popup_partnersInAd').style.display='block';
	popup_partnersInAd_OnFinish();
//	new Effect.Appear('popup_partnersInAd',{ afterFinish: popup_partnersInAd_OnFinish });
/*	

//

	var the_left_pos = (Position.cumulativeOffset($(obj).ancestors()[0])[0])+ $(obj).ancestors()[0].getWidth() + 28;
	var the_top_pos = Position.cumulativeOffset(obj)[1] - 500;
	$('popup_partnersInAd').style.left = the_left_pos + "px";
	$('popup_partnersInAd').style.top = the_top_pos + "px";
	new Effect.Appear('popup_partnersInAd',{ afterFinish: popup_partnersInAd_OnFinish });
*/	
}

function popup_partnersInAd_OnFinish(){
	setIframeHeight('popup_partnersInAd');
}

function goZoomap(obj){
	var idPrefix = obj.id;
	var city = document.getElementById(idPrefix + 'CityName').value;
	var street = document.getElementById(idPrefix + 'StreetName').value;
	var house = document.getElementById(idPrefix + 'HouseNo').value;
	var url = "http://www.zoomap.co.il/search.asp?citiesText="+escape(city)+"&streetsText="+escape(street)+"&buildText="+escape(house);
	window.open(url);
}

function goAtlasCT(obj){
	var idPrefix = obj.id;
	var city = document.getElementById(idPrefix + 'CityName').value;
	var street = document.getElementById(idPrefix + 'StreetName').value;
	var house = document.getElementById(idPrefix + 'HouseNo').value;
//	var url = "http://www.atlasct.com/Israel/LuachHair/LuachHair.asp?city="+escape(city)+"&street="+escape(street)+"&houseNum="+escape(house);
	var url = "http://www.atlasct.com/israel/luachHairNew/?address=" + escape(house) + " " + escape(street) + " " + escape(city);
	
	popupMapShow(obj, url);
//	window.open(url);
}

function textAreaMaxLength(maxLength, obj) 
{
	if (obj) 
	{
	    if (obj.value.length > maxLength) 
	    {
		    obj.value = obj.value.substring(0, maxLength);
	    }
	}
}

function checkField(){
	var phone1Prefix = document.getElementById('telephone1Prefix').value;
	var phone1No = document.getElementById('telephone1No').value;
	var email = document.getElementById('contactMail').value;
	var phone2Prefix = document.getElementById('telephone2Prefix').value;
	var phone2No = document.getElementById('telephone2No').value;
	if(	email!=''||	(phone1No != '' && phone1Prefix != '')
		|| (phone2No != '' && phone2Prefix != '')){
		return true;
	}
	else{
		document.getElementById('mustFillOneOfTheAbove').style.display='block';
		return false;
	}
}

function goPriceList(obj){
	var idPrefix = obj.id;
	var manufacturerName = document.getElementById(idPrefix +'ManufacturerName').value;
	var modelName = document.getElementById(idPrefix + 'ModelName').value;
	var url = "http://www.discovery-israel.co.il/index.cgi?type=1&car="+manufacturerName+"&dgm="+modelName+"&eir=1";
	window.open(url);
}

function popupStaticShow(obj){
	var the_left_pos = 0;
	if (get_browser()!=0){
		Position.absolutize('popupStatic');
		the_left_pos -= Position.cumulativeOffset($('mainPart'))[0];
	}
	the_left_pos += (Position.cumulativeOffset($(obj).ancestors()[0])[0])+ $(obj).ancestors()[0].getWidth() - 80;	
	var the_top_pos = Position.cumulativeOffset(obj)[1] - 323;
	$('popupStatic').style.left = the_left_pos + "px";
	$('popupStatic').style.top = the_top_pos + "px";
	document.getElementById('popupStatic').style.display='block';
	popupStatic_OnFinish();
	
//	new Effect.Appear('popupStatic',{ afterFinish: popupStatic_OnFinish });
}
function popupStatic_OnFinish(){
	setIframeHeight('popupStatic');
}

function popupMapShow(obj,src){
	var the_left_pos = Position.cumulativeOffset($('top_logo'))[0] + $('top_logo').getWidth();
	var the_top_pos = Position.cumulativeOffset(obj)[1] - 300;
	$('popupMap').style.left = (the_left_pos - $('popupMap').getWidth()) + "px";
	$('popupMap').style.top = the_top_pos + "px";
	document.getElementsByName('mapIFrame')[0].src=src;
	document.getElementById('popupMap').style.display='block';
	popupMap_OnFinish();
//	new Effect.Appear('popupMap',{ afterFinish: popupMap_OnFinish });
}

function popupMap_OnFinish(){
	setIframeHeight('popupMap');
}

function hideObject(obj_id){
	document.getElementById(obj_id).style.display = "none";
}
