function ValidateTradeRegistration1() {
    var TradeRegForm
    var strErrors = ""

    TradeRegForm = document.getElementById('TradeRegistration');

    if (TradeRegForm.AssociatedTradesSelected.value.length == 0) {
        strErrors = strErrors + "Trades must be selected.\n"
    }
    if (TradeRegForm.AssociatedTypes.value.length == 0) {
        strErrors = strErrors + "Sub Trades must be selected.\n"
    }
   

    if (TradeRegForm.postcode.value.length == 0) {
        strErrors = strErrors + "Postcode must be filled in.\n"
    }
    else
    {
	    if (checkPostCode(TradeRegForm.postcode.value) != false)
	    {
	    	TradeRegForm.postcode.value = checkPostCode(TradeRegForm.postcode.value);
	  	}	
	  	else
	  	{
	  		strErrors = strErrors + "Postcode invalid.\n"
	  	}
    }	
    

    if (strErrors.length > 0) {
        alert("The form below hasn't been filled in quite right: \n\n" + strErrors)
    } else {
    TradeRegForm.submit()
    }

}

function SetPaymentOptionToggle() {
    if (document.getElementById("PaymentMethod").value == "credits") {
        //SetPaymentOption(2)
        // Show the payg options
        document.getElementById("CreditSelection").style.display = "none";
        document.getElementById("creditmsg").style.display = "none";
        document.getElementById("paygmsg").style.display = "none";
        document.getElementById("PaymentMethod").value = "payg";

    }
    else {
        // Show the credits options
        document.getElementById("CreditSelection").style.display = "block";
        document.getElementById("creditmsg").style.display = "none";
        document.getElementById("paygmsg").style.display = "none";
        document.getElementById("PaymentMethod").value = "credits";
    }
}

function SetPaymentOption(PaymentSelection) {
    document.getElementById("TradesmanRegContainer").className = "reg3";
    document.getElementById("TradesmanRegCols").className = "cols3 clearfix";
    if (PaymentSelection == 1) {
        document.getElementById("PAYG").style.display = "none";
        document.getElementById("Credits").style.display = "";
        document.getElementById("CreditsLink").className = "active";
        //document.getElementById("PAYGLink").className = "";

        document.getElementById("TradesmanRight").style.display = "none";
        document.getElementById("CreditsRight").style.display = "";
        document.getElementById("PAYGRight").style.display = "none";
    } else {
        document.getElementById("PAYG").style.display = "";
        document.getElementById("Credits").style.display = "none";
        document.getElementById("CreditsLink").className = "";
        //document.getElementById("PAYGLink").className = "active";

        document.getElementById("TradesmanRight").style.display = "none";
        document.getElementById("CreditsRight").style.display = "none";
        document.getElementById("PAYGRight").style.display = "";
    }
}

function SwitchJobTab(TabId) {
    document.getElementById("MyJobsNewJob").style.display = "none";
    document.getElementById("MyJobsCurrentJob").style.display = "none";
    document.getElementById("MyJobsFeedback").style.display = "none";
    document.getElementById(TabId).style.display = "";

    document.getElementById("MyJobsNewJobRight").style.display = "none";
    document.getElementById("MyJobsCurrentJobRight").style.display = "none";
    document.getElementById("MyJobsFeedbackRight").style.display = "none";
    document.getElementById(TabId + "Right").style.display = "";

    document.getElementById("MyJobsNewJobLink").className = "";
    document.getElementById("MyJobsCurrentJobLink").className = "";
    document.getElementById("MyJobsFeedbackLink").className = "";
    document.getElementById(TabId + "Link").className = "active";
}


function SwitchLeadTab(TabId) {
	if (null != document.getElementById("MyLeadsPuchasedLeads")) { document.getElementById("MyLeadsPuchasedLeads").style.display = "none"; }
	if (null != document.getElementById("MyLeadsAwaitingDecision")) { document.getElementById("MyLeadsAwaitingDecision").style.display = "none"; }
	if (null != document.getElementById("MyLeadsFeedback")) { document.getElementById("MyLeadsFeedback").style.display = "none"; }
	if (null != document.getElementById(TabId)) { document.getElementById(TabId).style.display = ""; }

    if (null != document.getElementById("MyLeadsPuchasedLeadsRight")) { document.getElementById("MyLeadsPuchasedLeadsRight").style.display = "none"; }
    if (null != document.getElementById("MyLeadsAwaitingDecisionRight")) { document.getElementById("MyLeadsAwaitingDecisionRight").style.display = "none"; }
    if (null != document.getElementById("MyLeadsFeedbackRight")) { document.getElementById("MyLeadsFeedbackRight").style.display = "none"; }
    if (null != document.getElementById(TabId + "Right")) { document.getElementById(TabId + "Right").style.display = ""; }

    if (null != document.getElementById("MyLeadsPuchasedLeadsLink")) { document.getElementById("MyLeadsPuchasedLeadsLink").className = ""; }
    if (null != document.getElementById("MyLeadsAwaitingDecisionLink")) { document.getElementById("MyLeadsAwaitingDecisionLink").className = ""; }
    if (null != document.getElementById("MyLeadsFeedbackLink")) { document.getElementById("MyLeadsFeedbackLink").className = ""; }
    if (null != document.getElementById((TabId + "Link"))) { document.getElementById(TabId + "Link").className = "active"; }	
}
function SwitchAccountTab(TabId) {
    document.getElementById("AccountDetails").style.display = "none";
    document.getElementById("RecentTransactions").style.display = "none";
    document.getElementById("BuyCredits").style.display = "none";
    document.getElementById("ReferAFriend").style.display = "none";
   // document.getElementById("PriorTestimonials").style.display = "none";  
    document.getElementById(TabId).style.display = "";

    document.getElementById("AccountDetailsLink").className = "";
    document.getElementById("RecentTransactionsLink").className = "";
    document.getElementById("BuyCreditsLink").className = "";
    document.getElementById("ReferAFriendLink").className = "";
  //  document.getElementById("PriorTestimonialsLink").className = "";
    document.getElementById(TabId + "Link").className = "active";
}

function ViewJobDetail(JobId) {
    document.getElementById("JobDetail" + JobId).style.display = "";
    document.getElementById("JobDetailLinkShow" + JobId).style.display = "none";
    document.getElementById("JobDetailLinkHide" + JobId).style.display = "";
    document.getElementById("JobDetailLinkHide" + JobId + "2").style.display = "";
    document.getElementById("JobDetailLinkShow" + JobId + "2").style.display = "none";
    document.getElementById("JobDetailLinkHide" + JobId + "3").style.display = "";
    document.getElementById("JobDetailLinkShow" + JobId + "3").style.display = "none";
}

function HideJobDetail(JobId) {
    document.getElementById("JobDetail" + JobId).style.display = "none";
    document.getElementById("JobDetailLinkShow" + JobId).style.display = "";
    document.getElementById("JobDetailLinkShow" + JobId + "2").style.display = "";
    document.getElementById("JobDetailLinkShow" + JobId + "3").style.display = "";
    document.getElementById("JobDetailLinkHide" + JobId).style.display = "none";
    document.getElementById("JobDetailLinkHide" + JobId + "2").style.display = "none";
    document.getElementById("JobDetailLinkHide" + JobId + "3").style.display = "none";
    
}

function ViewJobFeedbackDetail(JobId) {
    document.getElementById("JobFeedbackDetail" + JobId).style.display = "";
    document.getElementById("JobFeedShow" + JobId).style.display = "none";
    document.getElementById("JobFeedHide" + JobId).style.display = "";
    document.getElementById("JobFeedShow" + JobId + "2").style.display = "none";
    document.getElementById("JobFeedHide" + JobId + "2").style.display = "";
    document.getElementById("JobFeedShow" + JobId + "3").style.display = "none";
    document.getElementById("JobFeedHide" + JobId + "3").style.display = "";
}

function HideJobFeedbackDetail(JobId) {
    document.getElementById("JobFeedbackDetail" + JobId).style.display = "none";
    document.getElementById("JobFeedShow" + JobId).style.display = "";
    document.getElementById("JobFeedHide" + JobId).style.display = "none";
    document.getElementById("JobFeedShow" + JobId + "2").style.display = "";
    document.getElementById("JobFeedHide" + JobId + "2").style.display = "none";
    document.getElementById("JobFeedShow" + JobId + "3").style.display = "";
    document.getElementById("JobFeedHide" + JobId + "3").style.display = "none";
}

function DisplayDeregisterOther(){
	 	document.getElementById("Select1" + JobId).style.display = "none";
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function validateHomeJobPost() {
    var NewJobForm
    var strErrors = ""

    NewJobForm = document.getElementById('HomeNewJob');


    if (NewJobForm.Trade.selectedIndex == 0) {
        strErrors = strErrors + "Trade must be filled in.\n"
    }
    if (NewJobForm.Type.selectedIndex == 0) {
        strErrors = strErrors + "Type must be filled in.\n"
    }
    if (NewJobForm.summary.value.length == 0) {
        strErrors = strErrors + "Job Summary must be filled in.\n"
    }
    if (NewJobForm.PriceRangeId.selectedIndex == 0) {
        strErrors = strErrors + "Estimated Cost must be filled in.\n"
    }
    
    if (NewJobForm.postcode.value.length == 0) {
        strErrors = strErrors + "Postcode must be filled in.\n"
    }
    else
    {
	    if (checkPostCode(NewJobForm.postcode.value) != false)
	    {
	    	NewJobForm.postcode.value = checkPostCode(NewJobForm.postcode.value);
	  	}	
	  	else
	  	{
	  		strErrors = strErrors + "Postcode invalid.\n"
	  	}
    }	
    
    if (NewJobForm.RequestedStartDate.selectedIndex == 0) {
        strErrors = strErrors + "Start Date must be filled in.\n"
    }
    if (NewJobForm.ExistingCustomer.value != "1") {
        if (NewJobForm.ExistingCustomer[0].checked == false && NewJobForm.ExistingCustomer[1].checked == false) {
            strErrors = strErrors + "New or Existing customer must be selected.\n"
        }
    }

    if (strErrors.length > 0) {
        document.getElementById("HomeNewJobFormError").style.display = "";
        alert("The form has not been filled in quite right: \n\n" + strErrors)
    } else {
        document.getElementById("HomeNewJobFormError").style.display = "none";
        eraseCookie('custtradetype');
        eraseCookie('custtrade');
        createCookie('custtradetype',NewJobForm.Type.options[NewJobForm.Type.options.selectedIndex].value,1);
        createCookie('custtrade',NewJobForm.Trade.options[NewJobForm.Trade.options.selectedIndex].value,1);
        NewJobForm.submit()
    }

}

function limitText(limitField, limitCount, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } else {
        limitCount.value = limitNum - limitField.value.length;
    }
}


function ValidateMyJobsNewJobForm() {
    var NewJobForm
    var strErrors = ""

    NewJobForm = document.getElementById('MyJobsNewJobForm');


    if (NewJobForm.Trade.selectedIndex == 0) {
        strErrors = strErrors + "Trade must be filled in.\n"
    }
    if ("" == NewJobForm.Type.value) {
        strErrors = strErrors + "Type must be filled in.\n"
    }
    if (NewJobForm.summary.value.length == 0) {
        strErrors = strErrors + "Job Summary must be filled in.\n"
    }
    if (NewJobForm.PriceRangeId.selectedIndex == 0) {
        strErrors = strErrors + "Estimated Cost must be filled in.\n"
    }
    
    if (NewJobForm.postcode.value.length == 0) {
        strErrors = strErrors + "Postcode must be filled in.\n"
    }
    else
    {
	    if (checkPostCode(NewJobForm.postcode.value) != false)
	    {
	    	NewJobForm.postcode.value = checkPostCode(NewJobForm.postcode.value);
	  	}	
	  	else
	  	{
	  		strErrors = strErrors + "Postcode invalid.\n"
	  	}
    }	
    
    
    if (NewJobForm.RequestedStartDate.selectedIndex == 0) {
        strErrors = strErrors + "Start Date must be filled in.\n"
    }
    
    
    
    if (strErrors.length > 0) {
        alert("The form has not been filled in quite right: \n\n" + strErrors)
    } else {
        NewJobForm.submit()
    }
}


function JobSelectTradesmen(JobId) {
    var SelectTradesmanForm;
    var NonSelected;
    var strErrors = "";
    var TradeID;
    var intCount;

    TradeID = document.getElementById('TradesmanId');

    NonSelected = false;
    SelectTradesmanForm = document.getElementById('Job' + JobId + 'SelectTradesmen');

    if (SelectTradesmanForm.TradesmanId.length != null) {
        intCount = SelectTradesmanForm.TradesmanId.length;
    }
    else {
        if (SelectTradesmanForm.TradesmanId.checked == true) {
            NonSelected = true;
        }
    }

    for (var i = 0; i < intCount; i++) {
        if (SelectTradesmanForm.TradesmanId[i].checked) {
            NonSelected = true;
        }
    }


    if (NonSelected == false) {
        strErrors = strErrors + "Tradesman must be chosen.\n"
    }

    if (strErrors.length > 0) {
        alert("The form has not been filled in quite right: \n\n" + strErrors)
    } else {
        
        
        var ReasonPopup = document.getElementById('InBrowserReasonPopup' + JobId);
        ReasonPopup.style.display = "";
        document.getElementById("OverlayBackground" + JobId).style.display = "";
        //SelectTradesmanForm.submit()
    }
}


function JobSelectTradesmen2(JobId) {
    var SelectTradesmanForm
    var NonSelected
    var strErrors = ""


    NonSelected = false;
    SelectTradesmanForm = document.getElementById('Job' + JobId + 'SelectTradesmen2');

    if (SelectTradesmanForm.TradesmanId.length != null) {
        intCount = SelectTradesmanForm.TradesmanId.length;
    }
    else {
        if (SelectTradesmanForm.TradesmanId.checked == true) {
            NonSelected = true;
        }
    }

    for (var i = 0; i < SelectTradesmanForm.TradesmanId.length; i++) {
        if (SelectTradesmanForm.TradesmanId[i].checked) {
            NonSelected = true;
        }
    }


    if (NonSelected == false) {
        strErrors = strErrors + "Tradesman must be chosen.\n"
    }

    if (strErrors.length > 0) {
        alert("The form has not been filled in quite right: \n\n" + strErrors)
    } else {
        var ReasonPopup = document.getElementById('InBrowserReasonPopup2-' + JobId);
        document.getElementById("OverlayBackground2-" + JobId).style.display = "";
        ReasonPopup.style.display = "";
        // SelectTradesmanForm.submit()
    }
}


function GiveFeedback(JobId) {
    var FeedbackForm
    var strErrors = ""

    FeedbackForm = document.getElementById('JobFeedback' + JobId);

    if (FeedbackForm.FeedbackQuality[0].checked == false && FeedbackForm.FeedbackQuality[1].checked == false && FeedbackForm.FeedbackQuality[2].checked == false && FeedbackForm.FeedbackQuality[3].checked == false && FeedbackForm.FeedbackQuality[4].checked == false) {
        strErrors = strErrors + "Quality must be selected.\n"
    }
    if (FeedbackForm.FeedbackValue[0].checked == false && FeedbackForm.FeedbackValue[1].checked == false && FeedbackForm.FeedbackValue[2].checked == false && FeedbackForm.FeedbackValue[3].checked == false && FeedbackForm.FeedbackValue[4].checked == false) {
        strErrors = strErrors + "Value for money must be selected.\n"
    }
    if (FeedbackForm.FeedbackOverall[0].checked == false && FeedbackForm.FeedbackOverall[1].checked == false && FeedbackForm.FeedbackOverall[2].checked == false && FeedbackForm.FeedbackOverall[3].checked == false && FeedbackForm.FeedbackOverall[4].checked == false) {
        strErrors = strErrors + "Overall must be selected.\n"
    }

    
    
    

    if (FeedbackForm.FeedbackComments.value.length == 0) {
        strErrors = strErrors + "Comments must be given.\n"
    }


    if (strErrors.length > 0) {
        alert("The form has not been filled in quite right: \n\n" + strErrors)
    } else {
        FeedbackForm.submit()
    }
}
function SaveTestimonial(JobId) {
    var FeedbackForm
    var strErrors = ""

    FeedbackForm = document.getElementById('Testimonial' + JobId);


    if (FeedbackForm.ReviewerName.value.length == 0) {
        strErrors = strErrors + "Reviewer name must be given.\n"
    }
    if (FeedbackForm.ReviewerLocation.value.length == 0) {
        strErrors = strErrors + "Reviewer location must be given.\n"
    }

    if (FeedbackForm.FeedbackQuality[0].checked == false && FeedbackForm.FeedbackQuality[1].checked == false && FeedbackForm.FeedbackQuality[2].checked == false && FeedbackForm.FeedbackQuality[3].checked == false && FeedbackForm.FeedbackQuality[4].checked == false) {
        strErrors = strErrors + "Quality must be selected.\n"
    }
    if (FeedbackForm.FeedbackValue[0].checked == false && FeedbackForm.FeedbackValue[1].checked == false && FeedbackForm.FeedbackValue[2].checked == false && FeedbackForm.FeedbackValue[3].checked == false && FeedbackForm.FeedbackValue[4].checked == false) {
        strErrors = strErrors + "Value for money must be selected.\n"
    }
    if (FeedbackForm.FeedbackOverall[0].checked == false && FeedbackForm.FeedbackOverall[1].checked == false && FeedbackForm.FeedbackOverall[2].checked == false && FeedbackForm.FeedbackOverall[3].checked == false && FeedbackForm.FeedbackOverall[4].checked == false) {
        strErrors = strErrors + "Overall must be selected.\n"
    }




    if (FeedbackForm.FeedbackComments.value.length == 0) {
        strErrors = strErrors + "Comments must be given.\n"
    }


    if (strErrors.length > 0) {
        alert("The form has not been filled in quite right: \n\n" + strErrors)
    } else {
        FeedbackForm.submit()
    }
}



function SaveTestimonial2(JobId) {
    var FeedbackForm
    var strErrors = ""

    FeedbackForm = document.getElementById('Testimonial' + JobId);


    if (FeedbackForm.ReviewerName.value.length == 0) {
        strErrors = strErrors + "Reviewer name must be given.\n"
    }
    if (FeedbackForm.ReviewerLocation.value.length == 0) {
        strErrors = strErrors + "Reviewer location must be given.\n"
    }





    if (FeedbackForm.FeedbackComments.value.length == 0) {
        strErrors = strErrors + "Comments must be given.\n"
    }


    if (strErrors.length > 0) {
        alert("The form has not been filled in quite right: \n\n" + strErrors)
    } else {
        FeedbackForm.submit()
    }
}

function DisplayInBrowserPopup(URL) {
    var contents = document.createElement('iframe');
    contents.scrolling = 'no';
    contents.frameBorder = '0';
    contents.style.width = '584px';
    contents.style.height = '400px';
    contents.src = URL;


    var InBrowserPopupInner
    InBrowserPopupInner = document.getElementById("InBrowserPopupInner");
    if (InBrowserPopupInner.hasChildNodes()) {
        while (InBrowserPopupInner.childNodes.length >= 1) {
            InBrowserPopupInner.removeChild(InBrowserPopupInner.firstChild);
        }
    }
    InBrowserPopupInner.appendChild(contents);


    var Popup
    Popup = document.getElementById("InBrowserPopup");

    if (window.pageYOffset != undefined) {
        Popup.style.top = (window.pageYOffset + 100) + 'px'; 
    } else {
        Popup.style.top = document.documentElement.scrollTop + 100;
    }
    Popup.style.display = "";
}
function SelectFeedbacks() {
//    alert(document.getElementById("AssociatedTradesSelected").value);
    document.getElementById("OverlayBackground").style.display = "";
    var Popup
    Popup = document.getElementById("InBrowserFeedbackPopup");

    //if (window.pageYOffset != undefined) {
    //    Popup.style.top = (window.pageYOffset + 100) + 'px';
    //} else {
    //    Popup.style.top = document.documentElement.scrollTop + 100;
    //}
    Popup.style.display = "";
}
function CloseFeedbacks() {
	  var Popup
    Popup = document.getElementById("InBrowserFeedbackPopup");
    Popup.style.display = "none";
    document.getElementById("OverlayBackground").style.display = "none";
}
function CloseReasons(JobId) {
	  var Popup
	  Popup = document.getElementById("InBrowserReasonPopup" + JobId);
    Popup.style.display = "none";
    document.getElementById("OverlayBackground" + JobId).style.display = "none";
}

function CloseReasons2(JobId) {
    var Popup
    Popup = document.getElementById("InBrowserReasonPopup2-" + JobId);
    Popup.style.display = "none";
    document.getElementById("OverlayBackground2-" + JobId).style.display = "none";
}

function ProcessDeregReasons() {
    var other;
    var other2;
    var reasonselected;

    other = document.getElementById("other");
    other2 = document.getElementById("other2");
    reasonselected = document.getElementById("reason");

    if (reasonselected.options[reasonselected.selectedIndex].text == 'Other')
    {
        other.style.display = '';
        other2.style.display = '';
    }
    else
    {
        other.style.display = 'none';
        other2.style.display = 'none';
    }
}

function ProcessReasons(JobId) {
	  var other;
	  var reasonselected;
	  
    other = document.getElementById("other-" + JobId);
    other2 = document.getElementById("other2-" + JobId);
    reasonselected = document.getElementById("reason" + JobId);
		
		
		if (reasonselected.options[reasonselected.selectedIndex].value == 'Other')
		{
			other.style.display = '';
			other2.style.display = '';
		}
		else
		{
			other.style.display = 'none';
			other2.style.display = 'none';
		}
}

function ProcessReasons2(JobId) {
    var other;
    var reasonselected;

    other = document.getElementById("other2-1-" + JobId);
    other2 = document.getElementById("other2-2-" + JobId);
    reasonselected = document.getElementById("reason2-" + JobId);


    if (reasonselected.options[reasonselected.selectedIndex].value == 'Other') {
        other.style.display = '';
        other2.style.display = '';
    }
    else {
        other.style.display = 'none';
        other2.style.display = 'none';
    }
}

function SelectTrades() {
//    alert(document.getElementById("AssociatedTradesSelected").value);

    document.getElementById("OverlayBackground").style.display = "";
    
    var Popup
    Popup = document.getElementById("InBrowserPopup");

    //if (window.pageYOffset != undefined) {
    //    Popup.style.top = (window.pageYOffset + 100) + 'px';
    //} else {
    //    Popup.style.top = document.documentElement.scrollTop + 100;
    //}
    Popup.style.display = "";
}

function ActivateAccount() {
    //    alert(document.getElementById("AssociatedTradesSelected").value);

    document.getElementById("OverlayBackground").style.display = "block";

    var Popup
    Popup = document.getElementById("InBrowserPopup3");

    //if (window.pageYOffset != undefined) {
    //    Popup.style.top = (window.pageYOffset + 100) + 'px';
    //} else {
    //    Popup.style.top = document.documentElement.scrollTop + 100;
    //}
    Popup.style.display = "";
}

function SelectTypes() {
    

    strIDs =""
    for (x = 0; x < document.frmTradeSelection.length; x++) {
        if (document.frmTradeSelection[x].checked) {
            strIDs = strIDs + document.frmTradeSelection[x].value + ','            
        }
    }
    if (strIDs.length > 0) {
        var Popup
        Popup = document.getElementById("InBrowserPopup2");

      //  if (window.pageYOffset != undefined) {
     //       Popup.style.top = (window.pageYOffset + 100) + 'px';
    //    } else {
   //         Popup.style.top = document.documentElement.scrollTop + 100;
  //      }
        Popup.style.display = "";
        document.getElementById("OverlayBackground").style.display = "";
    }

 //   alert(document.getElementById("AssociatedTradesSelected").value);
}



function ClosePopup() {
    var Popup
    Popup = document.getElementById("InBrowserPopup");
    Popup.style.display = "none";
}

function ClosePopup3() {
    var Popup
    Popup = document.getElementById("InBrowserPopup3");
    Popup.style.display = "none";
    document.getElementById("OverlayBackground").style.display = "none";
}


function move_box(an, box) {
    var cleft = 0;
    var ctop = 0;
    var obj = an;
    while (obj.offsetParent) {
        cleft += obj.offsetLeft;
        ctop += obj.offsetTop;
        obj = obj.offsetParent;
    }
    box.style.left = cleft + 'px';
    ctop += an.offsetHeight + 8;
    if (document.body.currentStyle &&
    document.body.currentStyle['marginTop']) {
        ctop += parseInt(
      document.body.currentStyle['marginTop']);
    }
    box.style.top = ctop + 'px';
}

function show_hide_box(an, width, height, borderStyle) {
    var href = an.href;
    var boxdiv = document.getElementById(href);

    if (boxdiv != null) {
        if (boxdiv.style.display == 'none') {
            move_box(an, boxdiv);
            boxdiv.style.display = 'block';
        } else
            boxdiv.style.display = 'none';
        return false;
    }

    boxdiv = document.createElement('div');
    boxdiv.setAttribute('id', href);
    boxdiv.style.display = 'block';
    boxdiv.style.position = 'absolute';
    boxdiv.style.width = width + 'px';
    boxdiv.style.height = height + 'px';
    boxdiv.style.border = borderStyle;
    boxdiv.style.backgroundColor = '#fff';

    var contents = document.createElement('iframe');
    contents.scrolling = 'no';
    contents.frameBorder = '0';
    contents.style.width = width + 'px';
    contents.style.height = height + 'px';
    contents.src = href;

    boxdiv.appendChild(contents);
    document.body.appendChild(boxdiv);
    move_box(an, boxdiv);

    return false;
}

function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
}

function UpdatedJobPostSubTrades(TradeId) {
    var objSelect = document.getElementById("NewJobPostType");
    objSelect.length = 0;
    var option = document.createElement("option");

    option.innerHTML = "Select one";
    option.value = "";
    objSelect.appendChild(option);
    for (var i = 0; i < TradeTypes.length; i++) {
        var div
        if (TradeTypes[i][0] == TradeId) {
           
            var option = document.createElement("option");
            option.innerHTML = TradeTypes[i][2];
            option.value = TradeTypes[i][1];
            objSelect.appendChild(option);
            if (readCookie('custtradetype') == TradeTypes[i][1]) {
					    	option.selected = true;
					    }
        }
    }
}

function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum-1);
    }     
}

function displaycharcount() {
	 var charsleft = document.getElementById("charleft"); 
   var txtSummary = document.getElementById("summary"); 
                                	
    charsleft.innerHTML = 80 - txtSummary.value.length;	
}

function SetTradesmenTypes() {
    var SubTradeLinkSet = false;
    strIDs = ""
    document.getElementById("SelectSubTradesLink").innerHTML = "Select sub trades";
    var found = -1
    //for (x = 0; x < document.frmTradeTypeSelection.AssociatedTypes.length; x++) {
    //    if (document.frmTradeTypeSelection.AssociatedTypes[x].checked) {
    //        strIDs = strIDs + document.frmTradeTypeSelection.AssociatedTypes[x].value + ',';
    //    }
    //}
    for (x = 0; x < document.frmTradeTypeSelection.length; x++) {
        if (document.frmTradeTypeSelection[x].checked) {
            strIDs = strIDs + document.frmTradeTypeSelection[x].value + ',';

            for (var i = 0; i < TradeTypes.length; i++) {
                if (TradeTypes[i][1] == document.frmTradeTypeSelection[x].value) {
                    if (SubTradeLinkSet == false) {
                        document.getElementById("SelectSubTradesLink").innerHTML = TradeTypes[i][2];
                        SubTradeLinkSet = true;
                    } else if (Right(document.getElementById("SelectSubTradesLink").innerHTML, 3) != '...') {                   
                        document.getElementById("SelectSubTradesLink").innerHTML = document.getElementById("SelectSubTradesLink").innerHTML + '...'
                    }
                }
            }
        }
    }
    if (strIDs.length > 0) {
        strIDs = strIDs.substring(0, strIDs.length - 1)
    }
    
    document.getElementById("AssociatedTypes").value = strIDs



    var Popup
    Popup = document.getElementById("InBrowserPopup2");
    Popup.style.display = "none";

    document.getElementById("OverlayBackground").style.display = "none";
 //   alert(document.getElementById("AssociatedTradesSelected").value);
}
function TradesmenTypesBack() {

    var Popup
    Popup = document.getElementById("InBrowserPopup");
    Popup.style.display = "";
    Popup = document.getElementById("InBrowserPopup2");
    Popup.style.display = "none";
}

function SetWhereHeard(where) {
    if (where == "Xpert Tradesman") {
        document.getElementById("WhereHeardXpert").style.display = "";
    } else {
    document.getElementById("WhereHeardXpert").style.display = "none";
    }
}
function showNotRegBlock() {
    document.getElementById("NotRegisteredBlock").style.display = '';
    document.getElementById("LatestFeedbackHeaderBlock").style.display = 'None';
}

function HideNotRegBlock() {
    document.getElementById("NotRegisteredBlock").style.display = 'none';
    document.getElementById("LatestFeedbackHeaderBlock").style.display = '';
}

function chkcontrol5(j) {    
    var total = 0;
    var SelectedTypes = [];
    for (var i = 0; i < document.frmTradeTypeSelection.length; i++) {
        if (document.frmTradeTypeSelection[i].checked) {
            for (var x = 0; x < TradeTypes.length; x++) {
                if (TradeTypes[x][1] == document.frmTradeTypeSelection[i].value) {


                    if (isNaN(SelectedTypes[TradeTypes[x][0]])) {
                        SelectedTypes[TradeTypes[x][0]] = 0;
                    }
                    SelectedTypes[TradeTypes[x][0]] = SelectedTypes[TradeTypes[x][0]] + 1;
                    //  alert(SelectedTypes[TradeTypes[x][0]]);

                    //if (SelectedTypes[TradeTypes[x][0]] > 5) {
                    //    alert("Please Select only five per trade")
                    //    j.checked = false;
                    //    return false;
                    //}
                }
            }
        }
    }
}

function Right(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else {
        var iLen = String(str).length;
        return String(str).substring(iLen, iLen - n);
    }
}
