$(document).ready(function () {
    $('.textSearchnew').click(function () {
        $(".dropDownSearch").css('display', 'none');
        $(this).parent().find("ul.dropDownSearch").slideDown("fast");

    });
    $('ul.dropDownSearch li').click(function () {
        var txt = $(this).text();
        var value = $(this).attr('id');


        document.getElementById("CategoryHeader_hidSearch").value = value;

        $(this).parent().next('.textSearchnew').text(txt);
        $(this).parent().next('.textSearchnew').text(txt);
        $(".dropDownSearch").css('display', 'none');

    });    
    $('body').click(function (event) {
        if ($(event.target).is('.textSearchnew')) {
            //$(this).parent().next(".dropDown").slideDown('slow');

        }
        else { $(".dropDownSearch").css('display', 'none'); }

    });

    $('.textFilter').click(function () {
        $(".filterDrop").css('display', 'none');
        $(this).parent().find("ul.filterDrop").slideDown("fast");

    });
    $('ul.filterDrop li').click(function () {
        var txt = $(this).text();
        var value = $(this).attr('id');
        var mytool_array = value.split("@");
        if (mytool_array[1] == '1') {
            document.getElementById("hidSortBy").value = mytool_array[0];
            document.getElementById("hidSortByvalue").value = txt;
        }
        if (mytool_array[1] == '2') {
            document.getElementById("hidSortType").value = mytool_array[0];
            document.getElementById("hidSortTypevalue").value = txt;
        }
        if (mytool_array[1] == '3') {
            document.getElementById("hidCountry").value = mytool_array[0];
            document.getElementById("HidCountryValue").value = txt;
        }
        if (mytool_array[1] == '4') {
            document.getElementById("hidCurrency").value = mytool_array[0];
            document.getElementById("hidCurrencyValue").value = txt;
        }

        $(this).parent().next('.textFilter').text(txt);
        $(".filterDrop").css('display', 'none');
        __doPostBack("", "");

    });

    $('body').click(function (event) {
        if ($(event.target).is('.textFilter')) {
            //$(this).parent().next(".dropDown").slideDown('slow');

        }
        else { $(".filterDrop").css('display', 'none'); }

    });
    $('.pagination span:first').hover(function () {
        $(this).find('a').css('background', 'none');

    })
    $('.pagination span:last').hover(function () {
        $(this).find('a').css('background', 'none');

    })


});

function chekSelect(typ, forwht) {
    var k = 0; // Loop through all elements
    for (i = 0; i < document.forms[0].length; i++)
        k = (document.forms[0].elements[i].name.indexOf(typ) > 0) ? (document.forms[0].elements[i].checked) ? k + 1 : k : k
    if (!(k > 0)) alert("At Least One Listing Must be Selected");
    if (forwht == "delete")
        return (k > 0) ? confirm("Are you sure you want to delete?") : false
    else
        return (k > 0) ? true : false
}

function ChkAll(objChkBox) {
    var isChecked = objChkBox.checked;
    var chkBoxId = objChkBox.id;
    var objForm = document.forms[0];
    if (chkBoxId == 'D')
        searchFor = "ChkDelete";
    else if (chkBoxId == 'R')
        searchFor = "ChkRenew";
    else if (chkBoxId == 'F')
        searchFor = "chkFeature";
    for (i = 0; i < objForm.elements.length; i++) {
        elem = objForm.elements[i];
        if (elem.id.indexOf(searchFor) > 0) {
            if (!elem.disabled)
                elem.checked = isChecked;
        }
    }
}

function ShowPopUpWin(sPage) {
    var myURL = sPage;
    var myWinName = "WinDetail";
    var Height = 160;
    var Width = 400;
    var myTop = (window.screen.height / 2) - Height / 2;
    var myLeft = (window.screen.width / 2) - Width / 2;
    var myWinProperperties = "height=" + Height + ",width=" + Width + ",top=" + myTop + ",left=" + myLeft + ",toolbar=no,status=no,menubar=no,resizeable=no,scrollbars=no";
    popupWin = window.open(myURL, myWinName, myWinProperperties);
    popupWin.focus();
}

		function ValidateBuy()
		{
		var Buy;
		Buy=eval(document.AddSingleListing.ddlBuy).value;
		
		if (Buy==2)
		{
	
			document.AddSingleListing.txtPrice.disabled=true;
			document.AddSingleListing.ddlAge.disabled=true;
			document.AddSingleListing.ddlCurrency.disabled=true;
			
		}		
		else
		{
			document.AddSingleListing.txtPrice.disabled=false;
			document.AddSingleListing.ddlAge.disabled=false;
			document.AddSingleListing.ddlCurrency.disabled=false;
		}
		
		initListGroup('chainedmenu',eval(document.AddSingleListing.ddlMainCategory),eval(document.AddSingleListing.ddlSubCategory),eval(document.AddSingleListing.ddlSubSubCategory))
	
		}
		
		
		function ValBuy()
		{
		
		var Buy;
		Buy=eval(document.AddSingleListing.ddlBuy).value
		
		var ddlBuy = document.getElementById("ddlBuy");
		var ddlMainCategory = document.getElementById("ddlMainCategory");
		var ddlSubCategory = document.getElementById("ddlSubCategory");
		var sAttachment = document.AddSingleListing.TImage.value;
		var sAttachment2 = document.AddSingleListing.TImage2.value;
		var sAttachment3 = document.AddSingleListing.TImage3.value;
		
		if(ddlBuy.options[ddlBuy.options.selectedIndex].value<=0)
		{
			alert("Please Select Buy/Sell Option");
			ddlBuy.focus();
			return false;
		}
		
		if(ddlMainCategory.options[ddlMainCategory.options.selectedIndex].value<=0)
		{
			alert("Please Select Main Category.");
			ddlMainCategory.focus();
			return false;
		}
		
		if(ddlSubCategory.options[ddlSubCategory.options.selectedIndex].value<=0)
		{
			alert("Please Select Sub Category.");
			ddlSubCategory.focus();
			return false;
		}
		
		
		
		
		
		if(sAttachment.replace(/ /gi,'').length>0)
		{
			if(sAttachment.indexOf("'")>=0)
			{
				alert("The character (') is not allowed in file name. Please rename the file and try again");	
				document.AddSingleListing.TImage.focus();
				return false;
			}
		} 
		
		if((sAttachment.length==0 && sAttachment2.length>0) || (sAttachment.length==0 && sAttachment3.length>0))
		{
				alert("Please upload photo 1");	
				document.AddSingleListing.TImage.focus();
				return false;
		} 
		
		if(sAttachment2.length==0 && sAttachment3.length>0)
		{
				alert("Please upload photo 2");	
				document.AddSingleListing.TImage2.focus();
				return false;
        }
        
        if(sAttachment2.replace(/ /gi,'').length>0)
		{
			if(sAttachment2.indexOf("'")>=0)
			{
				alert("The character (') is not allowed in file name. Please rename the file and try again");	
				document.AddSingleListing.TImage2.focus();
				return false;
			}
		}
		if(sAttachment3.replace(/ /gi,'').length>0)
		{
			if(sAttachment3.indexOf("'")>=0)
			{
				alert("The character (') is not allowed in file name. Please rename the file and try again");	
				document.AddSingleListing.TImage3.focus();
				return false;
			}
		}
		
		if(Buy!=2)
		{ 
			if(eval(document.AddSingleListing.ddlAge).value=="0")
			{
			alert("Please Select Listing Age");
			eval(document.AddSingleListing.ddlAge).focus()
			return false;
			}
			else if(eval(document.AddSingleListing.txtPrice).value.length!="0")
			{
			//alert("Please Enter Listing Price");
			//eval(document.AddSingleListing.txtPrice).focus()
			//return false;
			
				if(eval(document.AddSingleListing.ddlCurrency).value=="0")
				{
				alert("Please Select Currency");
				eval(document.AddSingleListing.ddlCurrency).focus()
				return false;
				}
			}
		}
		
		
	
		
		}
